| | |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using UnityEngine; |
| | | |
| | | using System; |
| | | |
| | | |
| | | public class TeamManager : GameSystemManager<TeamManager> |
| | | { |
| | | protected Dictionary<TeamType, TeamBase> teamDict = new Dictionary<TeamType, TeamBase>(); |
| | | protected Dictionary<int, TeamBase> teamDict = new Dictionary<int, TeamBase>(); |
| | | |
| | | public override void Init() |
| | | { |
| | | base.Init(); |
| | | public Action<int> OnTeamChange = null; |
| | | |
| | | public override void Init() |
| | | { |
| | | base.Init(); |
| | | |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += OnBeforePlayerDataInitialize; |
| | | } |
| | | |
| | | public override void Release() |
| | | { |
| | | base.Release(); |
| | | public override void Release() |
| | | { |
| | | base.Release(); |
| | | DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent -= OnBeforePlayerDataInitialize; |
| | | } |
| | | |
| | | public TeamBase GetTeam(TeamType teamType) |
| | | 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(teamType, out team)) |
| | | if (!teamDict.TryGetValue(presetID, out team)) |
| | | { |
| | | team = new TeamBase(); |
| | | team.AddTeamHeros(HeroManager.Instance.GetPowerfulHeroList()); |
| | | teamDict.Add(teamType, team); |
| | | team = new TeamBase(presetID); |
| | | // team.CreateDefault(HeroManager.Instance.GetPowerfulHeroList()); |
| | | teamDict.Add(presetID, team); |
| | | } |
| | | |
| | | return team; |
| | | } |
| | | |
| | | //通过战斗类型获取阵容 |
| | | public TeamBase GetTeam(BattlePreSetType battlePassType) |
| | | { |
| | | int presetID = GetTeamID(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.GetFuncPresetIDByBattleType((int)BattlePreSetType.Story, (int)FuncPresetType.Team); |
| | | } |
| | | |
| | | // 获取指定的方案ID |
| | | public int GetTeamID(BattlePreSetType battleType) |
| | | { |
| | | return FuncPresetManager.Instance.GetFuncPresetIDByBattleType((int)battleType, (int)FuncPresetType.Team); |
| | | } |
| | | } |