| | |
| | | |
| | | } |
| | | |
| | | #region 战斗结果详情 |
| | | public BattleDetailMsg msg = new BattleDetailMsg(); |
| | | public string BattleDetailBattleName = string.Empty; |
| | | public string BattleDetailMyName = string.Empty; |
| | | public string BattleDetailEnemyName = string.Empty; |
| | | public bool isMyStartBattleDetail = false; // 是否是我方发起的战斗 |
| | | |
| | | // isMyStart 是否是我方发起的战斗 |
| | | public void OpenBattleDetailWin(string battleName, bool isMyStart = true) |
| | | { |
| | | if (UIManager.Instance.IsOpened<BattleDetailWin>()) |
| | | return; |
| | | |
| | | JsonData battleSettlement = GetBattleSettlement(battleName); |
| | | if (battleSettlement == null) |
| | | return; |
| | | |
| | | msg = ParserBattleDetail(battleSettlement); |
| | | if (msg == null) |
| | | return; |
| | | |
| | | BattleDetailBattleName = battleName; |
| | | this.isMyStartBattleDetail = isMyStart; |
| | | UIManager.Instance.OpenWindow<BattleDetailWin>(); |
| | | } |
| | | |
| | | //战斗结果详情界面获取 我方发起的战斗的中敌方名字 |
| | | public string GetBattleDetailEnemyNameByMyStart(string battleName) |
| | | { |
| | | string detailName = string.Empty; |
| | | BattleField battleField = BattleManager.Instance.GetActiveBattleFieldByName(battleName); |
| | | if (battleField == null) |
| | | return detailName; |
| | | |
| | | switch (battleName) |
| | | { |
| | | // 敌方名字是Boss名字 |
| | | case BattleConst.StoryBossBattleField: |
| | | case BattleConst.BoneBattleField: |
| | | case BattleConst.TianziBillboradBattleField: |
| | | BattleObject bossBattleObject = battleField.FindBoss(); |
| | | if (bossBattleObject == null || bossBattleObject.teamHero == null) |
| | | return detailName; |
| | | detailName = bossBattleObject.teamHero.name; |
| | | break; |
| | | // 敌方名字是对方玩家名字 |
| | | case BattleConst.ArenaBattleField: |
| | | if (!ArenaManager.Instance.TryGetPlayerInfo(ArenaManager.Instance.atkPlayerId, out ArenaMatchInfo info) || info == null) |
| | | return detailName; |
| | | detailName = info.PlayerName; |
| | | break; |
| | | } |
| | | return detailName; |
| | | } |
| | | |
| | | public BattleDetailMsg ParserBattleDetail(JsonData jsonMsg) |
| | | { |
| | | if (jsonMsg == null) |
| | | return null; |
| | | try |
| | | { |
| | | string jsonStr = jsonMsg.ToJson(); |
| | | BattleDetailMsg result = JsonMapper.ToObject<BattleDetailMsg>(jsonStr); |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.Log("解析战斗数据异常: " + ex.Message); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public List<BattleDetailHeroInfo> GetHeroInfo(BattleDetailMsg msg, bool isMyStart, string battleName, bool isWin) |
| | | { |
| | | if (msg == null || msg.statInfo.IsNullOrEmpty()) |
| | | return null; |
| | | |
| | | int winFaction = msg.winFaction; // 获胜阵营 |
| | | Dictionary<string, Dictionary<string, BattleDetailHeroInfo>> lineupInfo = new Dictionary<string, Dictionary<string, BattleDetailHeroInfo>>(); |
| | | string statInfoKey = string.Empty; |
| | | |
| | | if (isMyStart) |
| | | { |
| | | // 天子战场玩家不会输 |
| | | if (battleName == BattleConst.TianziBillboradBattleField) |
| | | { |
| | | statInfoKey = isWin ? msg.statInfo.Keys.FirstOrDefault(key => key != winFaction.ToString()) : winFaction.ToString(); |
| | | } |
| | | else |
| | | { |
| | | statInfoKey = isWin ? winFaction.ToString() : msg.statInfo.Keys.FirstOrDefault(key => key != winFaction.ToString()); |
| | | } |
| | | } |
| | | |
| | | if (!msg.statInfo.TryGetValue(statInfoKey, out lineupInfo) || lineupInfo.IsNullOrEmpty()) |
| | | return null; |
| | | var lineupInfoKeyList = lineupInfo.Keys.ToList(); |
| | | if (lineupInfoKeyList.IsNullOrEmpty()) |
| | | return null; |
| | | |
| | | // 目前只取第一个阵容的信息 |
| | | string key = lineupInfoKeyList[0]; |
| | | if (!lineupInfo.TryGetValue(key, out var heroInfoDict) || heroInfoDict.IsNullOrEmpty()) |
| | | return null; |
| | | |
| | | var heroInfoKeyList = heroInfoDict.Keys.ToList(); |
| | | heroInfoKeyList = heroInfoKeyList |
| | | .OrderBy(key => int.Parse(key)) // 将字符串键解析为整数后进行排序 |
| | | .ToList(); // 将排序后的结果转回 List<string> |
| | | |
| | | List<BattleDetailHeroInfo> res = new List<BattleDetailHeroInfo>(); |
| | | foreach (var heroInfoKey in heroInfoKeyList) |
| | | { |
| | | if (!heroInfoDict.TryGetValue(heroInfoKey, out var heroInfo)) |
| | | continue; |
| | | res.Add(heroInfo); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | |
| | | public class BattleDetailMsg |
| | | { |
| | | public List<BattleDetailRewardItem> itemInfo; |
| | | |
| | | public int winFaction; |
| | | |
| | | // 对应 "statInfo" |
| | | // 结构:<阵营编号, <阵容编号, <站位编号, 武将数据>>> |
| | | // 注意:JSON中的键 "1", "2" 是字符串,所以字典 Key 用 string |
| | | public Dictionary<string, Dictionary<string, Dictionary<string, BattleDetailHeroInfo>>> statInfo; |
| | | } |
| | | public class BattleDetailHeroInfo |
| | | { |
| | | public int ObjID; // 实例ID |
| | | public int HeroID; // 玩家阵容武将ID |
| | | public int NPCID; // NPCID |
| | | public int LV; // 武将等级 |
| | | public int Star; // 武将星级 |
| | | public int Skin; // 武将皮肤ID |
| | | public ulong DefHurt; // 总承伤 |
| | | public ulong CureHP; // 总治疗 |
| | | public ulong AtkHurt; // 总输出 |
| | | public int Dead; // 是否阵亡 |
| | | } |
| | | |
| | | public class BattleDetailRewardItem |
| | | { |
| | | public int ItemID; |
| | | public int Count; |
| | | } |