yyl
2025-08-29 dbb4ea01211573e782666e45eb859c96859b2cd6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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>();
 
    public Action<TeamType> 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_tagSCLineupInfo vNetData)
    {
        var heroPack = PackManager.Instance.GetSinglePack(PackType.Hero);
        HashSet<TeamType> teamTypeSet = new HashSet<TeamType>();
        for (int i = 0; i < vNetData.LineupCnt; i++)
        {
            TeamType teamType = (TeamType)vNetData.LineupList[i].LineupID;
            teamTypeSet.Add(teamType);
            var team = GetTeam(teamType);
            for (int j = 0; j < vNetData.LineupList[i].HeroCnt; j++)
            {
                int index = vNetData.LineupList[i].HeroItemIndexList[j];
                HeroInfo hero;
                if (index == 0)
                {
                    hero = null;
                }
                else
                {
                    var item = heroPack.GetItemByIndex(vNetData.LineupList[i].HeroItemIndexList[j] - 1);
                    if (item == null)
                    {
                        hero = null;
                        Debug.LogError("没有对应的武将数据!");
                    }
                    hero = HeroManager.Instance.GetHero(item.guid);
 
                }
                team.RefreshServerData(vNetData.LineupList[i].ShapeType, j, hero);
            }
        }
 
        foreach (var tt in teamTypeSet)
        {
            OnTeamChange?.Invoke(tt);
        }
    }
 
 
    public bool HasTeam(TeamType teamType)
    {
        return teamDict.ContainsKey(teamType);
    }
 
    public TeamBase GetTeam(TeamType teamType)
    {
        TeamBase team = null;
 
        if (!teamDict.TryGetValue(teamType, out team))
        {
            team = new TeamBase(teamType);
            // team.CreateDefault(HeroManager.Instance.GetPowerfulHeroList());
            teamDict.Add(teamType, team);
        }
 
        return team;
    }
}