少年修仙传客户端代码仓库
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
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
namespace vnxbqy.UI
{
    
    public class RedEnvelopeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        Dictionary<int, string> redpackSfxDict = new Dictionary<int, string>();
 
        RedPacketModel redPackdata { get { return ModelCenter.Instance.GetModel<RedPacketModel>(); } }
        OSRedEnvelopeModel envelopeModel { get { return ModelCenter.Instance.GetModel<OSRedEnvelopeModel>(); } }
        FestivalRedpackModel festivalRedpackModel { get { return ModelCenter.Instance.GetModel<FestivalRedpackModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
            SysNotifyMgr.Instance.sysNotifyEvent += OnSystemNotifyEvent;
        }
 
        public override void UnInit()
        {
 
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            serverInited = false;
            m_RedEnvelopeDict.Clear();
            redpacks.Clear();
        }
 
        bool serverInited = false;
 
        Dictionary<int, RedEnvelope> m_RedEnvelopeDict = new Dictionary<int, RedEnvelope>();
        Dictionary<int, List<int>> redpacks = new Dictionary<int, List<int>>();
 
        public event Action EnvelopeUpdateEvent;
        public event Action<int> EnvelopeGetEvent;
 
        public void UpdateRedEnvelope(HA404_tagGCFamilyRedPacketInfo _pak)
        {
            for (int i = 0; i < _pak.Count; i++)
            {
                var info = _pak.RedPacketInfo[i];
                RedEnvelope _envelope = new RedEnvelope()
                {
                    id = (int)info.RedPacketID,
                    player = (int)info.PlayerID,
                    playerName = info.Name,
                    time = info.Time,
                    job = info.PlayeJob,
                    moneyType = info.MoneyType,
                    moneyNum = (int)info.MoneyNum,
                    type = info.GetWay,
                    packCount = info.PacketCnt,
                    state = info.State,
                    Wish = UIHelper.ServerStringTrim(info.Wish),
                    face = (int)info.Face,
                    facePic = (int)info.FacePic,
                };
 
                List<int> list;
                if (!redpacks.TryGetValue(info.GetWay, out list))
                {
                    list = new List<int>();
                    redpacks.Add(info.GetWay, list);
                }
                if (!list.Contains((int)info.RedPacketID))
                {
                    list.Add((int)info.RedPacketID);
                }
 
                m_RedEnvelopeDict[(int)info.RedPacketID] = _envelope;
                if (EnvelopeGetEvent != null)
                {
                    EnvelopeGetEvent(_envelope.id);
                }
            }
            if (EnvelopeUpdateEvent != null)
            {
                EnvelopeUpdateEvent();
            }
        }
 
 
        public void UpdateRedEnvelope(HA405_tagGCFamilyRedPacketGrabInfo vNetData)
        {
            RedEnvelope envelope;
            if (TryGetEnvelope((int)vNetData.RedPacketID, out envelope))
            {
                if (envelope.packCount == vNetData.Count
                    && envelope.state != 3)
                {
                    UpdateRedEnvelope(envelope, 3);
                }
            }
            bool self = false;
            for (int i = 0; i < vNetData.Count; i++)
            {
                if (UIHelper.ServerStringTrim(vNetData.GrabInfo[i].Name).Equals(
                    UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName)))
                {
                    self = true;
                    break;
                }
            }
            if (vNetData.RedPacketID == cacheEnvelopeId)
            {
                if (!envelope.Equals(default(RedEnvelope)))
                {
                    if (envelope.type == FestivalRedpackModel.FESTIVALSYSTEMREDPACK1
                        || envelope.type == FestivalRedpackModel.FESTIVALSYSTEMREDPACK2)
                    {
                        if (!WindowCenter.Instance.IsOpen<RedpackSystemDetailsWin>())
                        {
                            envelopeSfx = vNetData.RedPacketID == envelopeSfx && self ? envelopeSfx : 0;
                            ModelCenter.Instance.GetModel<RedPacketModel>().redpackDetailId = (int)vNetData.RedPacketID;
                            WindowCenter.Instance.Open<RedpackSystemDetailsWin>();
                        }
                        cacheEnvelopeId = 0;
                        return;
                    }
                }
                if (!WindowCenter.Instance.IsOpen<RedDetailsTipsWin>())
                {
                    envelopeSfx = vNetData.RedPacketID == envelopeSfx && self ? envelopeSfx : 0;
                    ModelCenter.Instance.GetModel<RedPacketModel>().redpackDetailId = (int)vNetData.RedPacketID;
                    WindowCenter.Instance.Open<RedDetailsTipsWin>();
                }
                cacheEnvelopeId = 0;
            }
        }
 
        public void UpdateRedEnvelope(RedEnvelope envelope, int _state)
        {
            m_RedEnvelopeDict[(int)envelope.id] = new RedEnvelope()
            {
                id = envelope.id,
                player = envelope.player,
                playerName = envelope.playerName,
                time = envelope.time,
                job = envelope.job,
                moneyType = envelope.moneyType,
                moneyNum = envelope.moneyNum,
                type = envelope.type,
                packCount = envelope.packCount,
                state = _state,
                Wish = UIHelper.ServerStringTrim(envelope.Wish),
                face = envelope.face,
                facePic = envelope.facePic,
            };
            if (EnvelopeUpdateEvent != null)
            {
                EnvelopeUpdateEvent();
            }
        }
 
        public event Action EnvelopeDelEvent;
 
        public bool TryGetEnvelope(int _id,out RedEnvelope _envelope)
        {
            return m_RedEnvelopeDict.TryGetValue(_id, out _envelope);
        }
 
        public void UpdateRedEnvelope(HAC05_tagGCRedPacketDel _pak)
        {
            for (int i = 0; i < _pak.Cnt; i++)
            {
                var _id = (int)_pak.DelRedPacketID[i];
                if (m_RedEnvelopeDict.ContainsKey(_id))
                {
                    var type = m_RedEnvelopeDict[_id].type;
                    if (redpacks.ContainsKey(type))
                    {
                        var list = redpacks[type];
                        if (list.Contains(_id))
                        {
                            list.Remove(_id);
                        }
                    }
 
                    m_RedEnvelopeDict.Remove(_id);
                }
            }
            if (EnvelopeDelEvent != null)
            {
                EnvelopeDelEvent();
            }
        }
 
        public void SendGetEnvelope(int _id,int getWay)
        {
            RedEnvelope _envelope;
            if(m_RedEnvelopeDict.TryGetValue(_id,out _envelope))
            {
                if (_envelope.state == 1)
                {
                    CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
                    _pak.RedPaketID = (uint)_id;
                    _pak.GetWay = (byte)getWay;
                    GameNetSystem.Instance.SendInfo(_pak);
                }
            }
        }
 
        public bool TryGetLatestEnvelope(out RedEnvelope envelope)
        {
            envelope = default(RedEnvelope);
            bool _has = false;
            foreach (var _envelope in m_RedEnvelopeDict.Values)
            {
                if (_envelope.state == 1)
                {
                    envelope = _envelope;
                    _has = true;
                }
            }
            return _has;
        }
 
        public bool TryGetEnvelopes(int type, out List<int> list)
        {
            return redpacks.TryGetValue(type, out list);
        }
 
        public void GetEnvelopes(int _type, ref List<int> _list)
        {
            _list.Clear();
            foreach (var _id in m_RedEnvelopeDict.Keys)
            {
                if (m_RedEnvelopeDict[_id].type == _type)
                {
                    _list.Add(_id);
                }
            }
        }
 
        public bool CheckEnvelopeLimit(int _id, bool _tip = false)
        {
            if (!m_RedEnvelopeDict.ContainsKey(_id))
            {
                return false;
            }
            RedEnvelope _envelope = m_RedEnvelopeDict[_id];
            var _OSRedModel = ModelCenter.Instance.GetModel<OSRedEnvelopeModel>();
            var _OSRedType = _OSRedModel.OSRedEnvelopeType;
            if (_envelope.type == _OSRedType)
            {
                if (TimeUtility.OpenDay >= _OSRedModel.openDays)
                {
                    if (_tip)
                    {
                        SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
                    }
                    return false;
                }
                if (_OSRedModel.getEnvelopeTimes <= 0)
                {
                    if (_tip)
                    {
                        SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
                    }
                    return false;
                }
            }
            return true;
        }
 
        public int cacheEnvelopeId = 0;
        public int envelopeSfx { get; set; }
        public void SendOpenRedpackPackage(int _id,int getWay)
        {
            cacheEnvelopeId = _id;
            CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
            _pak.RedPaketID = (uint)_id;
            _pak.GetWay = (byte)getWay;
            GameNetSystem.Instance.SendInfo(_pak);
        }
 
 
        #region 红包雨特效
        DateTime sfxRedpackTime = DateTime.Now;
 
        private void OnSystemNotifyEvent(string _key, ArrayList list)
        {
            var config = SysInfoConfig.Get(_key);
            if (config != null && string.IsNullOrEmpty(config.richText))
            {
                foreach (var key in redpackSfxDict.Keys)
                {
                    if (_key.Equals(redpackSfxDict[key]))
                    {
                        var effectId = 0;
                        int.TryParse(config.effect, out effectId);
                        PlayRedpackSfx(key, effectId);
                        return;
                    }
                }
            }
            if (_key.Equals("OSRedpackSfx") && list.Count > 0)
            {
                var type = 0;
                int.TryParse(list[0].ToString(), out type);
                if (type != 0)
                {
                    switch (type)
                    {
                        case 5:
                            CheckRedpackSfx(type);
                            break;
                        case FestivalRedpackModel.FESTIVALTASKREDPACKTYPE:
                            CheckFestivalRedpackSfx(type);
                            break;
                    }
                }
            }
        }
 
        public void CheckRedpackSfx(int type)
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.OpenServerRedEnvelope))
            {
                return;
            }
            if (envelopeModel.getEnvelopeTimes <= 0)
            {
                return;
            }
            if (!serverInited)
            {
                return;
            }
            if (!(StageLoad.Instance.currentStage is DungeonStage)
                || WindowCenter.Instance.IsOpen<LoadingWin>())
            {
                return;
            }
            if (DateTime.Now >= sfxRedpackTime)
            {
                var _effect = EffectMgr.Instance.PlayUIEffect(5162, 4500, WindowCenter.Instance.uiRoot.tipsCanvas, false);
                sfxRedpackTime = sfxRedpackTime.AddSeconds(_effect != null ? _effect.duration : 0);
            }
        }
 
        public void PlayRedpackSfx(int type, int effectId)
        {
            if (!serverInited)
            {
                return;
            }
            festivalRedpackModel.JudgePlayRedpackVoice(type);
            if (!(StageLoad.Instance.currentStage is DungeonStage)
                || WindowCenter.Instance.IsOpen<LoadingWin>())
            {
                return;
            }
            if (DateTime.Now >= sfxRedpackTime)
            {
                var _effect = EffectMgr.Instance.PlayUIEffect(effectId, 4500, WindowCenter.Instance.uiRoot.tipsCanvas, false);
                sfxRedpackTime = sfxRedpackTime.AddSeconds(2f);
            }
        }
 
        public void CheckFestivalRedpackSfx(int type)
        {
            if (!festivalRedpackModel.IsOpen)
            {
                return;
            }
            if (festivalRedpackModel.grabRedpackTimes <= 0)
            {
                return;
            }
            if (!serverInited)
            {
                return;
            }
            if (!(StageLoad.Instance.currentStage is DungeonStage)
                || WindowCenter.Instance.IsOpen<LoadingWin>())
            {
                return;
            }
            if (DateTime.Now >= sfxRedpackTime)
            {
                var _effect = EffectMgr.Instance.PlayUIEffect(5162, 4500, WindowCenter.Instance.uiRoot.tipsCanvas, false);
                sfxRedpackTime = sfxRedpackTime.AddSeconds(2f);
            }
        }
        #endregion
 
        void ParseConfig()
        {
            var config = FuncConfigConfig.Get("OpenServerRedPacketRain");
            var json = LitJson.JsonMapper.ToObject(config.Numerical2);
            foreach (var key in json.Keys)
            {
                var type = int.Parse(key);
                redpackSfxDict.Add(type, json[key].ToString());
            }
        }
 
        public struct RedEnvelope
        {
            public int id;
            public int player;
            public string playerName;
            public uint time;
            public int job;
            public int moneyType;
            public int moneyNum;
            public int type;
            public int packCount;
            public int state;        //0未发,1未领取,2已领取,3全部领完
            public string Wish;        //祝福语
            public int face;
            public int facePic;
        }
    }
}