少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using System;
using System.Collections.Generic;
using UnityEngine;
 
namespace vnxbqy.UI
{
    //ÏÉÃË»ÕÕ ½âËøÍ¾¾¶ÀàÐÍ
    public enum FairyEmblemUnlockMethodType
    {
        Custom,     // 0 - ¶¨ÖÆ
        LV,         // 1 - µÈ¼¶×Ô¶¯½âËø
        Active,     // 2 - »î¶¯»ñµÃ
    }
 
    public class FairyEmblemModel : Model, IBeforePlayerDataInitialize
    {
        public readonly int MaxItemRowCount = 6;    // Ò»ÐÐչʾx¸ö»ÕÕÂ
        public readonly int FamilyActionsType = 15;     // ¼Ò×åÐÐΪÀàÐÍ15
        public readonly int FuncId = 237;
        public int defaultFamilyEmblemId;           // Ä¬ÈÏ»ÕÕÂID
 
        public bool isSendA408Pack = false;
 
        private int m_NowChooseEmblemId;
        public int nowChooseEmblemId
        {
            get { return m_NowChooseEmblemId; }
            set
            {
                m_NowChooseEmblemId = value;
                ChooseEmblemIdChangeEvent?.Invoke();
            }
        }
 
        //<EmblemId,FamilyAction>
        Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction> familyActions = new Dictionary<int, HA403_tagGCFamilyActionInfo.tagGCFamilyAction>();
 
        public event Action ChooseEmblemIdChangeEvent;      //Çл»±êǩҳ
        public event Action<int, int> UpdateFamilyActionEvent;
 
        Redpoint entranceRedPoint = new Redpoint(10702, MainRedDot.FairyEmbleManageRepoint); //ÏÉÃ˹ÜÀíÃæ°åÈë¿Úºìµã
 
        public override void Init()
        {
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo;
            defaultFamilyEmblemId = int.Parse(FuncConfigConfig.Get("FairyEmblem").Numerical1);
        }
 
        public override void UnInit()
        {
            PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo;
        }
 
        private void OnRefreshFairyInfo()
        {
            UpdateRedPoint();
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            familyActions.Clear();
        }
 
        public void UpdateRedPoint()
        {
            entranceRedPoint.state = RedPointState.None;
            // ½öÃËÖ÷ÄÜ¿´µ½
            if (!IsCaptain())
                return;
            // ÏÉÃË2¼¶³öÏÖ
            if (PlayerDatas.Instance.fairyData == null || PlayerDatas.Instance.fairyData.fairy.FamilyLV != 2)
                return;
            // Ö»³öÏÖÒ»´Î
            if (GetRedPointShow())
                return;
            entranceRedPoint.state = RedPointState.Simple;
        }
 
        string localStr = "FairyEmblemEntranceRedPoint_";
 
        public bool GetRedPointShow()
        {
            return LocalSave.GetBool(localStr + PlayerDatas.Instance.PlayerId);
        }
 
        public void SetRedPointShow()
        {
            LocalSave.SetBool(localStr + PlayerDatas.Instance.PlayerId, true);
        }
 
        public bool TryGetNowEmblemID(out int nowID)
        {
            nowID = 0;
            int emblemID = (int)PlayerDatas.Instance.fairyData.fairy.Extra6;
            if (FamilyEmblemConfig.Has(emblemID) && IsUnLock(emblemID))
            {
                nowID = (int)emblemID;
                return true;
            }
 
            if (FamilyEmblemConfig.Has(defaultFamilyEmblemId))
            {
                nowID = defaultFamilyEmblemId;
                return true;
            }
 
            nowID = 0;
            return false;
 
        }
 
        // Õ¹Ê¾Ö¸¶¨»ÕÕ ±íÖÐÕÒ²»µ½»ÕÕ¾ÍÏÔʾĬÈϵÄ
        public void ShowEmblem(int emblemID, ImageEx imgTitle, float scale = 1.0f)
        {
            int nowEmblemID = emblemID;
            if (!FamilyEmblemConfig.Has(nowEmblemID))
            {
                nowEmblemID = defaultFamilyEmblemId;
            }
            FamilyEmblemConfig config = FamilyEmblemConfig.Get(nowEmblemID);
            UIFrame frame = imgTitle.GetComponent<UIFrame>();
            if (UIFrameMgr.Inst.ContainsDynamicImage(config.Image))
            {
                if (frame == null)
                    frame = imgTitle.gameObject.AddComponent<UIFrame>();
 
                List<UnityEngine.Sprite> spriteList = UIFrameMgr.Inst.GetDynamicImage(config.Image);
                if (!spriteList.IsNullOrEmpty())
                {
                    imgTitle.rectTransform.sizeDelta = new Vector2(spriteList[0].rect.width, spriteList[0].rect.height);
                }
 
                imgTitle.raycastTarget = false;
                frame.ResetFrame(config.Image);
                frame.enabled = true;
            }
            else
            {
                if (frame != null)
                    frame.enabled = false;
                imgTitle.SetSprite(config.Image);
                imgTitle.SetNativeSize();
            }
            imgTitle.rectTransform.localScale = new Vector3(scale, scale, scale);
        }
 
        //·¢°ü ²éÑ¯Íæ¼Òµ±Ç°ÏÉÃË»ÕÕÂ
        public void TrySendA408EmblemInfoPack()
        {
            //ÒѾ­·¢¹ý°üÁË
            if (isSendA408Pack)
                return;
            isSendA408Pack = true;
            var pack = new CA408_tagCGQueryFamilyAction();
            pack.ActionType = 15;
            pack.FamilyID = PlayerDatas.Instance.baseData.FamilyId;
            GameNetSystem.Instance.SendInfo(pack);
        }
 
        //·¢°ü ¸ü¸ÄÏÉÃË»ÕÕÂ
        public void SendCA413ChangeFamilyEmblemPack(int emblemId)
        {
            var pack = new CA413_tagCGChangeFamilyEmblem();
            pack.EmblemID = (byte)emblemId;
            GameNetSystem.Instance.SendInfo(pack);
        }
 
        public List<int> GetShowList()
        {
            List<int> showList = new List<int>();
            List<string> keys = FamilyEmblemConfig.GetKeys();
            for (int i = 0; i < keys.Count; i++)
            {
                showList.Add(int.Parse(keys[i]));
            }
            showList.Sort(Cmp);
            return showList;
        }
 
        // ÒѼ¤»î>δ¼¤»î
        private int Cmp(int a, int b)
        {
            bool isUnlock1 = IsUnLock(a);
            bool isUnlock2 = IsUnLock(b);
 
            if (isUnlock1 != isUnlock2)
            {
                return isUnlock2.CompareTo(isUnlock1);
            }
 
            // Èç¹û¼¤»î״̬Ïàͬ£¬±È½ÏÊÇ·ñΪÏÞʱ£ºÏÞʱ (true) > ÓÀ¾Ã (false)
            bool isLimitA = IsLimitTime(a, out var familyAction1);
            bool isLimitB = IsLimitTime(b, out var familyAction2);
 
            if (isLimitA != isLimitB)
            {
                return isLimitB.CompareTo(isLimitA);
            }
 
            // ÏÞʱ״̬Ïàͬ£¬±È½Ï SortNum
            int sortNumA = GetSortNum(a);
            int sortNumB = GetSortNum(b);
            if (sortNumA != sortNumB)
            {
                return sortNumA.CompareTo(sortNumB);
            }
 
            return a.CompareTo(b);
        }
 
        public int GetSortNum(int emblemID)
        {
            if (!FamilyEmblemConfig.Has(emblemID))
                return 0;
            return FamilyEmblemConfig.Get(emblemID).SortNum;
        }
 
        // »ñµÃ»ÕÕÂÀ´Ô´ÀàÐÍ
        public FairyEmblemUnlockMethodType GetFairyEmblemUnlockType(int emblemID)
        {
            FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemID);
            if (config == null)
                return FairyEmblemUnlockMethodType.LV;
            if (config.CustomFamilyID > 0)
                return FairyEmblemUnlockMethodType.Custom;
            return config.UnlockFamilyLV > 0 ? FairyEmblemUnlockMethodType.LV : FairyEmblemUnlockMethodType.Active;
        }
 
        // Ö¸¶¨µÄ»ÕÕ½âËøÁËÂð
        public bool IsUnLock(int emblemId)
        {
            FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId);
            FairyEmblemUnlockMethodType type = GetFairyEmblemUnlockType(emblemId);
            HA403_tagGCFamilyActionInfo.tagGCFamilyAction familyAction;
            switch (type)
            {
                case FairyEmblemUnlockMethodType.Custom:
                    //ËùÔÚÏÉÃ˲»ÊÇÖ¸¶¨µÄ¶¨ÖÆÏÉÃˠδ½âËø
                    if (PlayerDatas.Instance.baseData.FamilyId != config.CustomFamilyID)
                        return false;
                    //·â°üÖÐûÓоÍËãδ½âËø
                    if (!TryGetfamilyAction(emblemId, out familyAction))
                        return false;
                    if (familyAction.Value2 > 0 && familyAction.Value2 < TimeUtility.AllSeconds)
                        return false;
                    return true;
 
                case FairyEmblemUnlockMethodType.LV:
                    //ËùÔÚÏÉÃ˵ȼ¶Ð¡ÓÚ»ÕÕÂÒªÇóµÈ¼¶ Î´½âËø
                    if (PlayerDatas.Instance.fairyData.fairy.FamilyLV < config.UnlockFamilyLV)
                        return false;
                    return true;
 
                case FairyEmblemUnlockMethodType.Active:
                    //·â°üÖÐûÓоÍËãδ½âËø
                    if (!TryGetfamilyAction(emblemId, out familyAction))
                        return false;
                    if (familyAction.Value2 > 0 && familyAction.Value2 < TimeUtility.AllSeconds)
                        return false;
                    return true;
 
                default:
                    return false;
            }
        }
 
        public bool IsUsing(int emblemId)
        {
            if (!TryGetNowEmblemID(out int Id))
            {
                return false;
            }
            return emblemId == Id;
        }
 
        public bool IsLimitTime(int emblemId, out HA403_tagGCFamilyActionInfo.tagGCFamilyAction familyAction)
        {
            familyAction = new HA403_tagGCFamilyActionInfo.tagGCFamilyAction();
            FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId);
            FairyEmblemUnlockMethodType type = GetFairyEmblemUnlockType(emblemId);
            switch (type)
            {
                case FairyEmblemUnlockMethodType.LV:
                    return false;
 
                case FairyEmblemUnlockMethodType.Custom:
                case FairyEmblemUnlockMethodType.Active:
                    if (config.ExpireMinutes <= 0)
                        return false;
                    if (!TryGetfamilyAction(emblemId, out familyAction))
                        return false;
                    return true;
 
                default:
                    return false;
            }
        }
 
        public bool IsCaptain()
        {
            return (int)PlayerDatas.Instance.fairyData.mine.FamilyLV == 3;
        }
 
        // ³¢ÊÔ´Ó·â°üÖеõ½Ö¸¶¨µÄ»ÕÕÂʱЧÐÅÏ¢£¨»î¶¯Í¾¾¶»ñÈ¡µÄ»ÕÕÂ,¶¨ÖÆ»ÕÕ£©
        private bool TryGetfamilyAction(int emblemId, out HA403_tagGCFamilyActionInfo.tagGCFamilyAction familyAction)
        {
            familyAction = new HA403_tagGCFamilyActionInfo.tagGCFamilyAction();
            if (!familyActions.TryGetValue(emblemId, out var info) || info == null)
                return false;
            familyAction = info;
            return true;
        }
 
        public bool TryGetEffectID(int emblemId, out int effectID)
        {
            effectID = 0;
            if (!FamilyEmblemConfig.Has(emblemId))
                return false;
            FamilyEmblemConfig config = FamilyEmblemConfig.Get(emblemId);
            if (!EffectConfig.Has(config.EffectID))
                return false;
            effectID = config.EffectID;
            return true;
        }
 
        public void UpdateFamilyAction(HA403_tagGCFamilyActionInfo vNetData)
        {
            if (vNetData.ActionType != FamilyActionsType || PlayerDatas.Instance.baseData == null || (int)vNetData.FamilyID != (int)PlayerDatas.Instance.baseData.FamilyId)
                return;
            for (int i = 0; i < vNetData.FamilyActionList.Length; i++)
            {
                HA403_tagGCFamilyActionInfo.tagGCFamilyAction familyAction = vNetData.FamilyActionList[i];
                familyActions[(int)familyAction.Value1] = familyAction;
            }
            UpdateFamilyActionEvent?.Invoke((int)vNetData.FamilyID, vNetData.ActionType);
        }
    }
}