using System.Collections.Generic;
|
using Cysharp.Threading.Tasks;
|
using LitJson;
|
using UnityEngine;
|
|
// 【战斗结算】
|
// 当收到 // B4 20 回合制战斗状态 #tagMCTurnFightState State 为 4-结算,时,代表本场战斗已结束并结算
|
// char Msg[Len]; //size = Len Msg信息为
|
// {"winFaction":获胜阵营, "statInfo":统计信息, “itemInfo“:[奖励物品信息列表]}
|
// 获胜阵营: 一般为1或者2,当玩家发起的战斗时,如果获胜阵营不等于1代表玩家失败了
|
// 统计信息: 格式 {"阵营编号":{"阵容编号":{"站位编号":{该武将统计信息字典}, ...}, ...}, ...}
|
// 阵营编号: 一般时1或2, 对应 B424 同步下去的阵营
|
// 阵容编号: 隶属于某个阵营的阵容编号,一般是从1开始,一个阵营在多V多的情况下可以有多个阵容
|
// 站位编号: 某个阵容中武将战斗实例的站位编号,一般从1开始,代表站位1
|
// 武将统计信息字典: 格式: {"ObjID":实例ID, "HeroID":玩家阵容武将ID, "NPCID":npc表ID, "AtkHurt":总输出, "DefHurt":总承伤, "CureHP":总治疗}
|
|
// 处理战斗结束逻辑
|
// IsBattleFinish = true;
|
// 结算逻辑
|
|
// {
|
// "itemInfo": [],
|
// "winFaction": 1,//获胜阵营: 一般为1或者2,当玩家发起的战斗时,如果获胜阵营不等于1代表玩家失败了
|
// "statInfo": {
|
// "1": {
|
// "1": {
|
// "5": {
|
// "NPCID": 0,
|
// "DefHurt": 633,
|
// "CureHP": 0,
|
// "AtkHurt": 169247,
|
// "ObjID": 1,
|
// "HeroID": 510006
|
// }
|
// }
|
// },
|
// "2": {
|
// "1": {
|
// "2": {
|
// "NPCID": 10101001,
|
// "DefHurt": 169246,
|
// "CureHP": 143096,
|
// "AtkHurt": 999952,
|
// "ObjID": 2,
|
// "HeroID": 0
|
// },
|
// "4": {
|
// "NPCID": 10101001,
|
// "DefHurt": 0,
|
// "CureHP": 0,
|
// "AtkHurt": 0,
|
// "ObjID": 3,
|
// "HeroID": 0
|
// },
|
// "6": {
|
// "NPCID": 10101001,
|
// "DefHurt": 1,
|
// "CureHP": 0,
|
// "AtkHurt": 0,
|
// "ObjID": 4,
|
// "HeroID": 0
|
// }
|
// }
|
// }
|
// }
|
// }
|
|
//"Msg":{"itemInfo":[{"ItemID":5,"Count":2},{"ItemID":3,"Count":40}],"winFaction":1,"statInfo":{"1":{"1":{"1":{"NPCID":0,"DefHurt":727,"CureHP":0,"AtkHurt":1891,"ObjID":1,"HeroID":530004},"3":{"NPCID":0,"DefHurt":483,"CureHP":1511,"AtkHurt":782,"ObjID":6,"HeroID":520001},"2":{"NPCID":0,"DefHurt":953,"CureHP":0,"AtkHurt":1712,"ObjID":5,"HeroID":510003}}},"2":{"1":{"1":{"NPCID":10101091,"DefHurt":638,"CureHP":0,"AtkHurt":140,"ObjID":2,"HeroID":610001},"3":{"NPCID":10101092,"DefHurt":625,"CureHP":0,"AtkHurt":126,"ObjID":3,"HeroID":610001},"5":{"NPCID":10101093,"DefHurt":3122,"CureHP":0,"AtkHurt":1897,"ObjID":4,"HeroID":510003}}}}}
|
|
//战场结算界面,存在多个的情况
|
public class ArenaBattleVictoryWin : UIBase
|
{
|
[SerializeField] AvatarCell myAvatarCell;
|
[SerializeField] AvatarCell enemyAvatarCell;
|
[SerializeField] TextEx txtMyName;
|
[SerializeField] TextEx txtEnemyName;
|
[SerializeField] TextEx txtMyScore;
|
[SerializeField] TextEx txtEnemyScore;
|
|
[SerializeField] ScrollerController scroller;
|
JsonData jsonData;
|
string guid;
|
protected override void OnPreOpen()
|
{
|
scroller.OnRefreshCell += OnRefreshCell;
|
guid = BattleSettlementManager.Instance.notifyGuid;
|
jsonData = BattleSettlementManager.Instance.GetBattleSettlement(guid);
|
if (jsonData == null)
|
{
|
DelayCloseWindow().Forget();
|
return;
|
}
|
Display();
|
CreateScroller();
|
}
|
|
|
protected override void OnPreClose()
|
{
|
scroller.OnRefreshCell -= OnRefreshCell;
|
BattleSettlementManager.Instance.WinShowOver(guid);
|
}
|
// B4 20 回合制战斗状态 #tagMCTurnFightState 通用的结算状态 State 4-结算奖励
|
// Msg 中额外信息
|
// "tagPlayerID":对战的目标ID,
|
// "atkAddScore":发起方增加的积分,可能为0,
|
// "defDecScore":被击方减少的积分,可能为0,
|
// itemInfo:奖励物品列表,可能为空
|
void Display()
|
{
|
if (!jsonData.ContainsKey("tagPlayerID") || !jsonData.ContainsKey("atkAddScore") || !jsonData.ContainsKey("defDecScore"))
|
return;
|
uint tagPlayerID = (uint)jsonData["tagPlayerID"];
|
int atkAddScore = (int)jsonData["atkAddScore"];
|
int defDecScore = (int)jsonData["defDecScore"];
|
if (!ArenaManager.Instance.TryGetPlayerInfo(tagPlayerID, out ArenaMatchInfo info))
|
return;
|
uint enemyFace = info.Face;
|
uint enemyFacePic = info.FacePic;
|
|
myAvatarCell.InitUI(AvatarHelper.GetAvatarModel((int)PlayerDatas.Instance.baseData.PlayerID,
|
PlayerDatas.Instance.baseData.face,
|
PlayerDatas.Instance.baseData.facePic));
|
enemyAvatarCell.InitUI(AvatarHelper.GetAvatarModel((int)tagPlayerID, (int)enemyFace, (int)enemyFacePic));
|
txtMyName.text = PlayerDatas.Instance.baseData.PlayerName;
|
txtEnemyName.text = UIHelper.ServerStringTrim(info.PlayerName);
|
txtMyScore.text = Language.Get("Arena17", atkAddScore);
|
txtEnemyScore.text = Language.Get("Arena21", defDecScore);
|
}
|
|
List<Item> showItems = new List<Item>();
|
void CreateScroller()
|
{
|
|
showItems.Clear();
|
scroller.Refresh();
|
|
if (!jsonData.ContainsKey("itemInfo"))
|
{
|
return;
|
}
|
|
var resultStr = jsonData["itemInfo"];
|
for (int i = 0; i < resultStr.Count; i++)
|
{
|
showItems.Add(new Item((int)resultStr[i]["ItemID"], (long)resultStr[i]["Count"]));
|
}
|
|
showItems.Sort(SortItem);
|
for (int i = 0; i < showItems.Count; i++)
|
{
|
scroller.AddCell(ScrollerDataType.Header, i);
|
}
|
scroller.Restart();
|
}
|
|
int SortItem(Item itemA, Item itemB)
|
{
|
var itemConfigA = ItemConfig.Get(itemA.id);
|
var itemConfigB = ItemConfig.Get(itemB.id);
|
return itemConfigB.ItemColor - itemConfigA.ItemColor;
|
}
|
|
void OnRefreshCell(ScrollerDataType type, CellView cell)
|
{
|
var _cell = cell as SettlementAwardCell;
|
var item = showItems[cell.index];
|
_cell?.Display(item.id, item.countEx);
|
}
|
}
|