using cfg.CharacterCfg;
using Framework;
using Google.Protobuf.Collections;
using NLDPB;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Gameplay.LegionBattle
{
///
/// 军团战队伍数据
///
public sealed class LegionTeamData
{
///
/// 编队数据字典
///
private Dictionary dicLegionRoleData;
///
/// 编队职业数量
///
private Dictionary dicJobCount;
///
/// 队伍角色列表,最多3个队伍,每个队伍n个角色
///
public List[] RoleDataLists { get; private set; }
///
/// 队伍名
///
public string[] TeamNames { get; private set; }
public LegionTeamData()
{
dicLegionRoleData = new Dictionary();
dicJobCount = new();
TeamNames = new string[TableManager.Instance.Tables.GlobalConfig.MaxLegionTeamCount];
RoleDataLists = new List[TableManager.Instance.Tables.GlobalConfig.MaxLegionTeamCount];
for (int i = 0; i < TableManager.Instance.Tables.GlobalConfig.MaxLegionTeamCount; ++i)
{
RoleDataLists[i] = new List();
}
}
///
/// 初始化数据
///
///
///
public void InitData(RepeatedField listTeam, RepeatedField listCharacter)
{
for (int i = 0; i < listTeam.Count; ++i)
{
MSG_LB_Team teamData = listTeam[i];
if (TeamNames.Length > i)
TeamNames[i] = teamData.Name;
LegionRoleData data = new(teamData.Commander);
dicLegionRoleData[teamData.Commander] = data;
RoleDataLists[i].Add(data);
foreach (uint id in teamData.Units)
{
if (0u == id)
continue;
data = new LegionRoleData(id);
dicLegionRoleData[id] = data;
RoleDataLists[i].Add(data);
}
}
for (int i = 0; i < listCharacter.Count; ++i)
{
if (!dicLegionRoleData.TryGetValue(listCharacter[i].Id, out LegionRoleData legionRoleData))
continue;
legionRoleData.CopyData(listCharacter[i]);
}
foreach (LegionRoleData legionRoleData in dicLegionRoleData.Values)
{
if (dicJobCount.TryGetValue(legionRoleData.Job, out int count))
dicJobCount[legionRoleData.Job] = ++count;
else
dicJobCount[legionRoleData.Job] = 1;
}
}
///
/// 获取职业数量
///
///
///
public int GetJobCount(Ejob ejob)
{
if (dicJobCount.TryGetValue(ejob, out int count))
return count;
return 0;
}
}
}