hch
2025-07-29 81298e554df8d11aeefe7b08aa3d45f1593bf586
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
 
using UnityEngine;
 
//武将相关界面的操作数据管理
public class HeroUIManager : GameSystemManager<HeroUIManager>
{
    //武将列表界面
    public List<string> heroSortList { get; private set; } = new List<string>();  //上阵为主线的列表
 
    public List<string> heroOnTeamSortList { get; private set; } = new List<string>();    //不同上阵的列表排序
 
    public TeamType selectTeamType = TeamType.Story;  //当前选中的是哪个阵容, 布阵相关逻辑使用
 
    public void OnBeforePlayerDataInitialize()
    {
        heroSortList.Clear();
        heroOnTeamSortList.Clear();
    }
 
    public void OnPlayerLoginOk()
    {
    }
 
    public override void Init()
    {
 
    }
 
    public override void Release()
    {
 
    }
 
    public bool waitResortHeroList = false;
 
 
    //刷新时机, 打开武将界面 或者 关闭功能界面
    public void SortHeroList()
    {
        heroSortList = HeroManager.Instance.GetHeroGuidList();
        heroSortList.Sort(CmpHero);
    }
 
 
    int CmpHero(string guidA, string guidB)
    {
        HeroInfo heroA = HeroManager.Instance.GetHero(guidA);
        HeroInfo heroB = HeroManager.Instance.GetHero(guidB);
        if (heroA == null || heroB == null)
        {
            return 0;
        }
 
        // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID
        bool isInTeamA = heroA.IsInTeamByTeamType(TeamType.Story);
        bool isInTeamB = heroB.IsInTeamByTeamType(TeamType.Story);
        if (isInTeamA != isInTeamB)
        {
            return isInTeamA ? -1 : 1;
        }
        if (heroA.heroLevel != heroB.heroLevel)
        {
            return heroA.heroLevel > heroB.heroLevel ? -1 : 1;
        }
        if (heroA.breakLevel != heroB.breakLevel)
        {
            return heroA.breakLevel > heroB.breakLevel ? -1 : 1;
        }
        if (heroA.awakeLevel != heroB.awakeLevel)
        {
            return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1;
        }
        if (heroA.Quality != heroB.Quality)
        {
            return heroA.Quality > heroB.Quality ? -1 : 1;
        }
        if (heroA.heroStar != heroA.heroStar)
        {
            return heroA.heroStar > heroB.heroStar ? -1 : 1;
        }
 
        return heroA.heroId.CompareTo(heroB.heroId);
    }
 
 
    public void SortHeroOnTeamList()
    {
        heroOnTeamSortList = HeroManager.Instance.GetHeroGuidList();
        heroOnTeamSortList.Sort(CmpHeroByTeamType);
    }
 
 
    int CmpHeroByTeamType(string guidA, string guidB)
    {
        HeroInfo heroA = HeroManager.Instance.GetHero(guidA);
        HeroInfo heroB = HeroManager.Instance.GetHero(guidB);
        if (heroA == null || heroB == null)
        {
            return 0;
        }
 
        // 排序规则:上阵>武将等级>突破等级>武将觉醒阶级>武将品质>武将吞噬星级>武将ID
        bool isInTeamA = heroA.IsInTeamByTeamType(selectTeamType);
        bool isInTeamB = heroB.IsInTeamByTeamType(selectTeamType);
        if (isInTeamA != isInTeamB)
        {
            return isInTeamA ? -1 : 1;
        }
        if (heroA.heroLevel != heroB.heroLevel)
        {
            return heroA.heroLevel > heroB.heroLevel ? -1 : 1;
        }
        if (heroA.breakLevel != heroB.breakLevel)
        {
            return heroA.breakLevel > heroB.breakLevel ? -1 : 1;
        }
        if (heroA.awakeLevel != heroB.awakeLevel)
        {
            return heroA.awakeLevel > heroB.awakeLevel ? -1 : 1;
        }
        if (heroA.Quality != heroB.Quality)
        {
            return heroA.Quality > heroB.Quality ? -1 : 1;
        }
        if (heroA.heroStar != heroA.heroStar)
        {
            return heroA.heroStar > heroB.heroStar ? -1 : 1;
        }
 
        return heroA.heroId.CompareTo(heroB.heroId);
    }
 
 
 
    public void QueryUnLockHeroPack()
    {
        //解锁更多的武将背包
    }
 
    //上阵队伍中各个国家的武将数量
    public Dictionary<HeroCountry, int> GetCountryHeroCountByTeamType(TeamType teamType)
    {
        Dictionary<HeroCountry, int> heroCountryCount = new Dictionary<HeroCountry, int>();
 
        var team = TeamManager.Instance.GetTeam(teamType);
        if (team != null)
        {
            for (int i = 0; i < team.serverHeroes.Length; i++)
            {
                var hero = HeroManager.Instance.GetHero(team.serverHeroes[i].guid);
                if (hero != null)
                {
                    if (!heroCountryCount.ContainsKey(hero.heroCountry))
                    {
                        heroCountryCount.Add(hero.heroCountry, 1);
                    }
                    else
                    {
                        heroCountryCount[hero.heroCountry] += 1;
                    }
 
                }
            }
 
        }
 
        return heroCountryCount;
    }
 
    //获得上阵中武将数量最大的国家和数量
    public Int2 GetMaxCountHeroCountry(TeamType teamType)
    {
        var countryCount = GetCountryHeroCountByTeamType(teamType);
        //找到最大的国家和数量
        HeroCountry country = HeroCountry.None;
        int maxValue = 0;
        foreach (var data in countryCount)
        {
            if (data.Value > maxValue)
            {
                country = data.Key;
                maxValue = data.Value;
            }
        }
        return new Int2((int)country, maxValue);
    }
 
    //在不同页签下选AttackType 0 攻击阵容 1 防守阵容
    public int GetSelectTeamTypeByAttackType(int AttackType)
    {
        if (selectTeamType == TeamType.Arena || selectTeamType == TeamType.ArenaDefense)
        {
            return AttackType == 0 ? (int)TeamType.Arena : (int)TeamType.ArenaDefense;
        }
 
        
        return (int)TeamType.Story;
    }
}