少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace vnxbqy.UI
{
    public class CycleHallActModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk, IOpenServerActivity
    {
        private int m_NowTabId;
        public int nowTabId
        {
            get { return m_NowTabId; }
            set
            {
                if (m_NowTabId != value)
                    m_NowTabId = value;
                UpdateRedpoint();
                onNowTabIdUpdate?.Invoke();
            }
        }
 
        //ͬ²½²¥·Å°Ú¶¯¶¯»­
        public Action PlayAnimationSync;
 
        private bool isPlayAnimation = false;
        public bool IsPlayAnimation
        {
            get
            {
                return isPlayAnimation;
            }
            set
            {
                isPlayAnimation = value;
                if (isPlayAnimation)
                {
                    PlayAnimationSync?.Invoke();
                }
                isPlayAnimation = false;
            }
        }
        public Dictionary<int, HAA89_tagMCActLunhuidianPlayerInfo> playerInfoDict = new Dictionary<int, HAA89_tagMCActLunhuidianPlayerInfo>();
        public event Action<int> onStateUpdate;
        public event Action onNowTabIdUpdate;
        public Redpoint redPoint = new Redpoint(MainRedDot.CycleHallRepoint);
 
        //<Ë÷Òý£¬ºìµã>
        public Dictionary<int, Redpoint> redPointDict = new Dictionary<int, Redpoint>();
 
        //<ÂÖ»ØÀàÐÍ,½çÃæID>
        public Dictionary<int, int> windowIDDict = new Dictionary<int, int>();
 
        //<ÂÖ»ØÀàÐÍ,¹¦ÄÜID>
        public Dictionary<int, int> funcIdDict = new Dictionary<int, int>();
 
        // <ÂÖ»ØÀàÐÍ,ÉϴεĠCurRound>
        public Dictionary<int, int> lastCurRoundDict = new Dictionary<int, int>();
 
        // <ÂÖ»ØÀàÐÍ,ÉϴεĠCurValue>
        public Dictionary<int, int> lastCurValueDict = new Dictionary<int, int>();
 
        public const int activityType = (int)OpenServerActivityCenter.ActivityType.AT_Activity2;
        public const int activityID = (int)NewDayActivityID.CycleHallAct;
        public static Operation operaType = Operation.default47;
 
        public int actNum = 10; //¶ÔÓ¦½çÃæ
        public event Action UpdatePlayerInfoAction;
 
        public int newRoundType;
        public int newAwardType;
        public int newAwardTypeValue;
        public int newAwardIndex;
        public event Action UpdateNewAwardHave;
        StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
 
        public override void Init()
        {
            OperationTimeHepler.Instance.operationStartEvent += OperationStartEvent;
            OperationTimeHepler.Instance.operationEndEvent += OperationEndEvent;
            OperationTimeHepler.Instance.operationAdvanceEvent += OperationAdvanceEvent;
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            OpenServerActivityCenter.Instance.Register(activityID, this, activityType);
            LoadTable();
        }
 
        private void LoadTable()
        {
            var jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("CycleHall").Numerical1);
            List<string> keyList = jsonData.Keys.ToList();
            for (int i = 0; i < keyList.Count; i++)
            {
                windowIDDict.Add(int.Parse(keyList[i]), int.Parse(jsonData[keyList[i]].ToJson()));
            }
 
            jsonData = JsonMapper.ToObject(FuncConfigConfig.Get("CycleHall").Numerical2);
            keyList = jsonData.Keys.ToList();
            for (int i = 0; i < keyList.Count; i++)
            {
                funcIdDict.Add(int.Parse(keyList[i]), int.Parse(jsonData[keyList[i]].ToJson()));
            }
        }
 
        public OperationCycleHall GetOperationInfo()
        {
            OperationTimeHepler.Instance.TryGetOperation(operaType, out OperationCycleHall cycleHallAct);
            return cycleHallAct;
        }
 
        public List<int> GetTabIDList()
        {
            OperationCycleHall act;
            OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
            if (act == null)
                return new List<int>();
            var list = CycleHallConfig.GetTabList();
            if (list.IsNullOrEmpty())
                return new List<int>();
            List<int> resList = new List<int>();
            for (int i = 0; i < list.Count; i++)
            {
                int id = list[i];
                if (!CycleHallConfig.Has(id))
                    continue;
                CycleHallConfig config = CycleHallConfig.Get(id);
                if (act.TryGetRound(config.RoundType, out var info) && funcIdDict.TryGetValue(config.RoundType, out var funcId) && FuncOpen.Instance.IsFuncOpen(funcId))
                {
                    if (!resList.Contains(id))
                    {
                        resList.Add(id);
                    }
                }
            }
            return resList;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            playerInfoDict.Clear();
            lastCurRoundDict.Clear();
            lastCurValueDict.Clear();
        }
 
        public void OnPlayerLoginOk()
        {
        }
 
        public override void UnInit()
        {
            storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
        }
 
        private void RefreshBuyShopLimitEvent()
        {
            UpdateRedpoint();
        }
 
        public bool IsOpen
        {
            get
            {
                return OperationTimeHepler.Instance.SatisfyOpenCondition(operaType);
            }
        }
 
        public bool priorityOpen
        {
            get
            {
                return redPoint.state == RedPointState.Simple;
            }
        }
 
        public bool IsAdvance
        {
            get
            {
                return OperationTimeHepler.Instance.SatisfyAdvanceCondition(operaType);
            }
        }
 
        private void OperationEndEvent(Operation type, int state)
        {
            if (type == operaType)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
                WindowCenter.Instance.Close<CycleHallWin>();
                UpdateRedpoint();
            }
        }
 
        private void OperationAdvanceEvent(Operation type)
        {
            if (type == operaType)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        private void OperationStartEvent(Operation type, int state)
        {
            if (type == operaType && state == 0)
            {
                if (onStateUpdate != null)
                {
                    onStateUpdate(activityID);
                }
            }
        }
 
        //0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡  2 ÒÑÁìÈ¡
        public int GetAwardState(int roundType, int awardIndex)
        {
            if (playerInfoDict == null || !playerInfoDict.TryGetValue((byte)roundType, out var playerInfo) || playerInfo == null)
                return 0;
            OperationCycleHall act;
            OperationTimeHepler.Instance.TryGetOperation(operaType, out act);
            if (act == null || !act.TryGetRoundInfoByIndex(roundType, awardIndex, out var awardInfo, out int listIndex))
                return 0;
 
            if (playerInfo.CurValue >= awardInfo.NeedValue)
            {
                return (playerInfo.AwardRecord & (1 << awardIndex)) != 0 ? 2 : 1;
            }
            else
            {
                return 0;
            }
        }
 
        //ÁìÈ¡¸ÃroundTypeÀàÐÍËùÓпÉÁìÈ¡µÄ½±Àø
        public void HaveAllMissionAward(int roundType)
        {
            var act = GetOperationInfo();
            if (act == null || !act.TryGetRound(roundType, out var round) || round.AwardList == null)
                return;
            if (playerInfoDict == null || !playerInfoDict.TryGetValue((byte)roundType, out var playerInfo) || playerInfo == null)
                return;
 
            for (int i = 0; i < round.AwardList.Length; i++)
            {
                var award = round.AwardList[i];
                int state = GetAwardState(roundType, award.AwardIndex);//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡  2 ÒÑÁìÈ¡
                if (state == 1)
                {
                    SendGetAward(roundType, (int)award.NeedValue);
                }
            }
        }
 
        public void UpdateRedpoint()
        {
            redPoint.state = RedPointState.None;
            if (redPointDict != null)
            {
                var redPointList = redPointDict.Keys.ToList();
                for (int i = 0; i < redPointList.Count; i++)
                {
                    int redPointId = redPointList[i];
                    redPointDict[redPointId].state = RedPointState.None;
                }
            }
 
            if (!IsOpen) return;
 
            var act = GetOperationInfo();
            if (act == null || act.roundInfoDict == null)
                return;
            var roundTypeList = act.roundInfoDict.Keys.ToList();
            for (int i = 0; i < roundTypeList.Count; i++)
            {
                int roundType = roundTypeList[i];
                if (!act.roundInfoDict.ContainsKey(roundType))
                    continue;
                int id = CycleHallConfig.GetIndex(roundType, 1);
                if (id <= 0)
                    continue;
                if (!redPointDict.ContainsKey(id))
                    redPointDict[id] = new Redpoint(MainRedDot.CycleHallRepoint, MainRedDot.CycleHallRepoint * 1000 + id);
 
                //ÓпÉÁìÈ¡µÄÈÎÎñ½±Àø
                if (!act.TryGetRound(roundType, out var round) || round.AwardList == null)
                    return;
                for (int j = 0; j < round.AwardList.Length; j++)
                {
                    var award = round.AwardList[j];
                    int index = award.AwardIndex;
 
                    int state = GetAwardState(roundType, index);//0 ²»¿ÉÁìÈ¡ 1 ¿ÉÁìÈ¡  2 ÒÑÁìÈ¡
                    if (state == 1)
                        redPointDict[id].state = RedPointState.Simple;
                }
 
                //É̵êÃâ·Ñ
                id = CycleHallConfig.GetIndex(roundType, 2);
                if (id <= 0)
                    continue;
                if (!redPointDict.ContainsKey(id))
                    redPointDict[id] = new Redpoint(MainRedDot.CycleHallRepoint, MainRedDot.CycleHallRepoint * 1000 + id);
 
                List<StoreConfig> _list = null;
                StoreConfig.TryGetStoreConfigs(round.ShopType, out _list);
 
                int storeCnt = _list == null ? 0 : _list.Count;
 
                for (int k = 0; k < storeCnt; k++)
                {
                    if (_list[k].MoneyNumber == 0)
                    {
                        int remainNum;
                        storeModel.TryGetIsSellOut(_list[k], out remainNum);
                        if (remainNum > 0)
                            redPointDict[id].state = RedPointState.Simple;
                    }
                }
            }
        }
 
        public void CheckNewAwardHave(int roundType, int curRound, int curValue)
        {
            if (lastCurRoundDict.ContainsKey(roundType) && lastCurValueDict.ContainsKey(roundType))
            {
                int lastCurRound = lastCurRoundDict[roundType];
                int lastCurValue = lastCurValueDict[roundType];
                if (lastCurRound < curRound)
                {
                    lastCurValueDict[roundType] = 0;
                }
 
                lastCurValue = lastCurValueDict[roundType];
                if (lastCurValue < curValue)
                {
                    var act = GetOperationInfo();
                    if (act != null && act.TryGetRound(roundType, out var round) && round.AwardList != null)
                    {
                        for (int i = 0; i < round.AwardList.Length; i++)
                        {
                            var Award = round.AwardList[i];
                            int state = GetAwardState(roundType, Award.AwardIndex);
                            if (Award.NeedValue > lastCurValue && Award.NeedValue <= curValue && state == 1)
                            {
                                newRoundType = roundType;
                                newAwardType = round.AwardType;
                                newAwardTypeValue = (int)round.AwardTypeValue;
                                newAwardIndex = Award.AwardIndex;
                                if (!DTC0403_tagPlayerLoginLoadOK.neverLoginOk && !WindowCenter.Instance.IsOpen<CycleHallAchievementTipWin>())
                                {
                                    WindowCenter.Instance.Open<CycleHallAchievementTipWin>();
                                }
                                UpdateNewAwardHave?.Invoke();
                            }
                        }
                    }
                }
            }
            lastCurRoundDict[roundType] = curRound;
            lastCurValueDict[roundType] = curValue;
        }
 
        public void UpdatePlayerInfo(HAA89_tagMCActLunhuidianPlayerInfo netPack)
        {
            if (actNum != netPack.ActNum)
                return;
            if (!playerInfoDict.ContainsKey(netPack.RoundType))
                playerInfoDict[netPack.RoundType] = new HAA89_tagMCActLunhuidianPlayerInfo();
            playerInfoDict[netPack.RoundType].RoundType = netPack.RoundType;
            playerInfoDict[netPack.RoundType].CurRound = netPack.CurRound;
            playerInfoDict[netPack.RoundType].CurValue = netPack.CurValue;
            playerInfoDict[netPack.RoundType].AwardRecord = netPack.AwardRecord;
            CheckNewAwardHave(netPack.RoundType, (int)netPack.CurRound, (int)netPack.CurValue);
            UpdatePlayerInfoAction?.Invoke();
            UpdateRedpoint();
        }
 
        public void SendGetAward(int roundType, int needValue)
        {
            CA504_tagCMPlayerGetReward getReward = new CA504_tagCMPlayerGetReward();
            getReward.RewardType = 78;
            getReward.DataEx = (uint)actNum;
            getReward.DataExStr = StringUtility.Contact(roundType, "|", needValue);
            getReward.DataExStrLen = (byte)getReward.DataExStr.Length;
            GameNetSystem.Instance.SendInfo(getReward);
        }
    }
}