using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using System;
|
|
|
public class TeamManager : GameSystemManager<TeamManager>
|
{
|
protected Dictionary<int, TeamBase> teamDict = new Dictionary<int, TeamBase>();
|
|
public Action<int> OnTeamChange = null;
|
|
public override void Init()
|
{
|
base.Init();
|
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize;
|
}
|
|
public override void Release()
|
{
|
base.Release();
|
DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize;
|
}
|
|
protected void OnBeforePlayerDataInitialize()
|
{
|
teamDict.Clear();
|
}
|
|
public void OnHeroChangeEvent(HB124_tagSCHeroPresetInfo vNetData)
|
{
|
var heroPack = PackManager.Instance.GetSinglePack(PackType.Hero);
|
HashSet<int> teamTypeSet = new HashSet<int>();
|
for (int i = 0; i < vNetData.PresetCnt; i++)
|
{
|
int teamType = vNetData.PresetList[i].PresetID;
|
teamTypeSet.Add(teamType);
|
var team = GetTeam(teamType);
|
for (int j = 0; j < vNetData.PresetList[i].HeroCnt; j++)
|
{
|
int index = vNetData.PresetList[i].HeroItemIndexList[j];
|
HeroInfo hero;
|
if (index == 0)
|
{
|
hero = null;
|
}
|
else
|
{
|
var item = heroPack.GetItemByIndex(vNetData.PresetList[i].HeroItemIndexList[j] - 1);
|
if (item == null)
|
{
|
hero = null;
|
Debug.LogError("没有对应的武将数据!");
|
}
|
hero = HeroManager.Instance.GetHero(item.guid);
|
|
}
|
team.RefreshServerData(j, hero);
|
}
|
}
|
|
foreach (var tt in teamTypeSet)
|
{
|
OnTeamChange?.Invoke(tt);
|
}
|
}
|
|
|
public bool HasTeam(int teamType)
|
{
|
return teamDict.ContainsKey(teamType);
|
}
|
|
//通过阵容方案ID获取阵容 从1开始
|
public TeamBase GetTeam(int presetID)
|
{
|
TeamBase team = null;
|
|
if (!teamDict.TryGetValue(presetID, out team))
|
{
|
team = new TeamBase(presetID);
|
// team.CreateDefault(HeroManager.Instance.GetPowerfulHeroList());
|
teamDict.Add(presetID, team);
|
}
|
|
return team;
|
}
|
|
//通过战斗类型获取阵容
|
public TeamBase GetTeam(BattlePreSetType battlePassType)
|
{
|
int presetID = GetTeamID((int)battlePassType);
|
TeamBase team = null;
|
|
if (!teamDict.TryGetValue(presetID, out team))
|
{
|
team = new TeamBase(presetID);
|
// team.CreateDefault(HeroManager.Instance.GetPowerfulHeroList());
|
teamDict.Add(presetID, team);
|
}
|
|
return team;
|
}
|
|
// 获取主阵容方案ID
|
public int GetMainTeamID()
|
{
|
return FuncPresetManager.Instance.GetFuncPresetID((int)BattlePreSetType.Story, (int)FuncPresetType.Team);
|
}
|
|
// 获取指定的方案ID
|
public int GetTeamID(int battleType)
|
{
|
return FuncPresetManager.Instance.GetFuncPresetID(battleType, (int)FuncPresetType.Team);
|
}
|
}
|