少年修仙传客户端代码仓库
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
using vnxbqy.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using LitJson;
 
//红包信息
public class FamilyRedPacket//红包信息
{
    public int RedPacketID;//红包唯一ID
    public int PlayerID;//玩家ID
    public string Name;//玩家名字
    public int Time;//时间
    public int PlayeJob;//玩家职业
    public int MoneyType;//金钱类型//1是V6红包
    public int MoneyNum;//金钱数量
    public int GetWay;        //获得途径
    public int PacketCnt;        //可抢个数
    public int State;        //0未发,1未领取,2已领取,3全部领完
    public string Wish;        //祝福语
    public byte IsAnonymous;    //是否匿名
    public int Face;        //基本脸型
    public int FacePic;        //头像框
 
}
 
 public  class FamilyRedPacktGrabinfo//家族抢红包的信息
{
 
    public string Name;//玩家名字
    public int PlayerJob;//玩家职业
    public int MoneyNum;//金钱数量
    public int Face;        //基本脸型
    public int FacePic;        //头像框
 
 
}
public class RedPacketModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
{
 
    public Dictionary<int, FamilyRedPacket> _DicRedBag = new Dictionary<int, FamilyRedPacket>();//接收红包信息
    public  Dictionary<int, FamilyRedPacktGrabinfo> _DicRedGrabinfo = new Dictionary<int, FamilyRedPacktGrabinfo>();//获取抢红包的信息字典
    public Dictionary<int, List<int>> redBagTypes = new Dictionary<int, List<int>>(); //红包类型的大分类,1仙盟 2全服 3节日
    public delegate void RedEnvelopeToAdd(FamilyRedPacket _familyRedPacket);
    public static event RedEnvelopeToAdd Event_RedEnvelopeToAdd;//红包的添加
    public delegate void RedEnvelopeToRefresh(FamilyRedPacket _familyRedPacket);
    public static event RedEnvelopeToRefresh Event_RedEnvelopeToRefresh;//红包的刷新
 
    public delegate void DetailsRedEnvelopeRefresh();
    public static event DetailsRedEnvelopeRefresh Event_DetailsRedEnvelopeRefresh;//红包详情的信息刷新
 
    public event Action ServerGrabCntEvent;  // 可抢个数刷新
    public event Action RedbagRefresh;  //红包刷新
    public event Action RedpackDelEvent; //红包删除
    public int UseLimit = 0;//V6红包使用额度
    public int ServerGrabCnt = 0;// 全服红包已抢次数
    public bool _v6RedBool = false; //是否v6红包
 
    public int RedBagId = 0;//获取当前选中红包的ID
 
    public int redpackDetailId = 0;
 
    public bool IsRedBagGetBool = false;
    public static event Action OnRedBagGetEvent;//是否有可领取的红包
 
    private const int Redpoint_key1 = 1070202;
    public  Redpoint redPointStre1 = new Redpoint(10702, Redpoint_key1);
 
    public int RedEnvelopeID = 0;//发红包的ID(用于默认弹出开)
 
    private int GrabRedBagId = 0;
    public override void Init()
    {
        PlayerDatas.Instance.fairyData.OnRefreshFairyMine += OnRefreshFairyMine;
        ParseConfig();
    }
 
    public override void UnInit()
    {
      
    }
 
    void ParseConfig()
    {
        redBagTypes.Clear();
        var config = JsonMapper.ToObject(FuncConfigConfig.Get("RedPacketClassify").Numerical1);
        foreach (var key in config.Keys)
        {
            redBagTypes[int.Parse(key)] = new List<int> (JsonMapper.ToObject<int[]>(config[key].ToJson()));
        }
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        UseLimit = 0;
        RedEnvelopeID = 0;
        IsRedBagGetBool = false;
        RedBagId = 0;
        _DicRedBag.Clear();
        _DicRedGrabinfo.Clear();
    }
 
    public void OnPlayerLoginOk()
    {
       
    }
 
    private void OnRefreshFairyMine()//退出仙盟
    {
        if (_DicRedBag.Count > 0 && !PlayerDatas.Instance.fairyData.HasFairy)
        {
            var list = _DicRedBag.Values.ToList();
            for (int i = 0; i < list.Count; i++)
            {
                if (IsDisplayInFamily(list[i].GetWay))
                {
                    _DicRedBag.Remove(list[i].RedPacketID);
                }
            }
            IsRedBagGet();
            RedbagRefresh?.Invoke();
        }
    }
 
    public void UpdateDelRedpack(HAC05_tagGCRedPacketDel _pak)
    {
        for (int i = 0; i < _pak.Cnt; i++)
        {
            var _id = (int)_pak.DelRedPacketID[i];
            if (_DicRedBag.ContainsKey(_id))
            {
 
                _DicRedBag.Remove(_id);
            }
        }
        RedpackDelEvent?.Invoke();
        IsRedBagGet();
        RedbagRefresh?.Invoke();
    }
 
 
    public void RedEnvelopeInfo(HA404_tagGCFamilyRedPacketInfo info)//家族红包总信息
    {
 
 
        if ((int)info.IsAll == 1)
        {
            _DicRedBag.Clear();
            for (int i = 0; i < info.Count; i++)
            {
                if (!_DicRedBag.ContainsKey((int)info.RedPacketInfo[i].RedPacketID))
                {
                    FamilyRedPacket _familyRed = new FamilyRedPacket();
                    _familyRed.RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
                    _familyRed.PlayerID = (int)info.RedPacketInfo[i].PlayerID;
                    _familyRed.Name = info.RedPacketInfo[i].Name;
                    _familyRed.Time = (int)info.RedPacketInfo[i].Time;
                    _familyRed.PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
                    _familyRed.MoneyType = (int)info.RedPacketInfo[i].MoneyType;
                    _familyRed.MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
                    _familyRed.GetWay = (int)info.RedPacketInfo[i].GetWay;
                    _familyRed.PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
                    _familyRed.State = (int)info.RedPacketInfo[i].State;
                    _familyRed.Wish = (string)info.RedPacketInfo[i].Wish;
                    _familyRed.IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
                    _familyRed.Face = (int)info.RedPacketInfo[i].Face;
                    _familyRed.FacePic = (int)info.RedPacketInfo[i].FacePic;
                    _DicRedBag.Add((int)info.RedPacketInfo[i].RedPacketID, _familyRed);
                   
                }
             
            }
 
        }
        else
        {
            for (int i = 0; i < info.Count; i++)
            {
                if (!_DicRedBag.ContainsKey((int)info.RedPacketInfo[i].RedPacketID))
                {
                    FamilyRedPacket _familyRed = new FamilyRedPacket();
                    _familyRed.RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
                    _familyRed.PlayerID = (int)info.RedPacketInfo[i].PlayerID;
                    _familyRed.Name = info.RedPacketInfo[i].Name;
                    _familyRed.Time = (int)info.RedPacketInfo[i].Time;
                    _familyRed.PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
                    _familyRed.MoneyType = (int)info.RedPacketInfo[i].MoneyType;
                    _familyRed.MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
                    _familyRed.GetWay = (int)info.RedPacketInfo[i].GetWay;
                    _familyRed.PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
                    _familyRed.State = (int)info.RedPacketInfo[i].State;
                    _familyRed.Wish = (string)info.RedPacketInfo[i].Wish;
                    _familyRed.IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
                    _familyRed.Face = (int)info.RedPacketInfo[i].Face;
                    _familyRed.FacePic = (int)info.RedPacketInfo[i].FacePic;
                    _DicRedBag.Add((int)info.RedPacketInfo[i].RedPacketID, _familyRed);
 
                    if (Event_RedEnvelopeToAdd != null)
                        Event_RedEnvelopeToAdd(_familyRed);
                }
                else
                {
                    
 
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].RedPacketID = (int)info.RedPacketInfo[i].RedPacketID;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PlayerID = (int)info.RedPacketInfo[i].PlayerID;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Name = info.RedPacketInfo[i].Name;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Time = (int)info.RedPacketInfo[i].Time;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PlayeJob = (int)info.RedPacketInfo[i].PlayeJob;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].MoneyType = (int)info.RedPacketInfo[i].MoneyType;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].MoneyNum = (int)info.RedPacketInfo[i].MoneyNum;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].GetWay = (int)info.RedPacketInfo[i].GetWay;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].PacketCnt = (int)info.RedPacketInfo[i].PacketCnt;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].State = (int)info.RedPacketInfo[i].State;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].IsAnonymous = info.RedPacketInfo[i].IsAnonymous;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Face = (int)info.RedPacketInfo[i].Face;
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].FacePic = (int)info.RedPacketInfo[i].FacePic;
                    if ((int)info.RedPacketInfo[i].RedPacketID == GrabRedBagId)
                    {
                        var Values = _DicRedGrabinfo.Values;
                        foreach (var value in Values)
                        {
                            if (value.Name == PlayerDatas.Instance.baseData.PlayerName)
                            {
                                _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].State = 2;
                            }
                        }
                    }
                    _DicRedBag[(int)info.RedPacketInfo[i].RedPacketID].Wish = (string)info.RedPacketInfo[i].Wish;
                    if (Event_RedEnvelopeToRefresh != null)
                    {
                        Event_RedEnvelopeToRefresh(_DicRedBag[(int)info.RedPacketInfo[i].RedPacketID]);
                    }
                    if (WindowCenter.Instance.IsOpen<RedBagTipsWin>() || WindowCenter.Instance.IsOpen<FullServerRechargeRedpackWin>())
                    { 
                        RedBagPoppingOpen();
                    }
                        
                }
            }
        }
 
        IsRedBagGet();
        RedPacketRedDot();
        RedbagRefresh?.Invoke();
    }
 
    private void RedBagPoppingOpen()
    {
        if (_DicRedBag.ContainsKey(RedEnvelopeID) && WindowCenter.Instance.IsOpen<RedBagTipsWin>())
        {
            var redBag = _DicRedBag[RedEnvelopeID];
            if (IsDisplayInFamily(redBag.GetWay) && redBag.GetWay != 0 && redBag.PlayerID == PlayerDatas.Instance.PlayerId && redBag.State == 1)
            {
                RedBagId = RedEnvelopeID;
                WindowCenter.Instance.Open<RedpackOpenWin>();//打开领取界面
                RedEnvelopeID = 0;
            }
        }
 
        if (_DicRedBag.ContainsKey(RedEnvelopeID) && WindowCenter.Instance.IsOpen<FullServerRechargeRedpackWin>())
        {
            var redBag = _DicRedBag[RedEnvelopeID];
            if (redBag.GetWay == FullServerRechargeRedpackModel.FullServer_Recharge_Redpack && redBag.PlayerID == PlayerDatas.Instance.PlayerId && redBag.State == 1)
            {
                RedBagId = RedEnvelopeID;
                WindowCenter.Instance.Open<RedpackOpenWin>();//打开领取界面
            }
        }
 
    }
 
 
    public void IsRedBagGet()
    {
        var existUnGetRedpack = false;  //切换有无时通知
        //仙盟开启才判断
        if (!FuncOpen.Instance.IsFuncOpen(15))
            return;
        foreach (var value in _DicRedBag.Values)
        {
            if (!IsDisplayInFamily(value.GetWay))
            {
                continue;
            }
            if (value.State == 1)
            {
                existUnGetRedpack = true;
                break;
            }
        }
        if (IsRedBagGetBool != existUnGetRedpack)
        {
            IsRedBagGetBool = existUnGetRedpack;
            OnRedBagGetEvent?.Invoke();
        }
    }
 
 
    private void RedPacketRedDot()
    {
        redPointStre1.state = RedPointState.None;
        bool _bool = false;
        foreach (var value in _DicRedBag.Values)
        {
 
            if (value.PlayerID == PlayerDatas.Instance.baseData.PlayerID && value.State == 0 && IsDisplayInFamily(value.GetWay))
            {
                _bool = true;
            }
            if (value.State == 1 && IsDisplayInFamily(value.GetWay))
            {
                _bool = true;
            }
        }
        if (_bool)
        {
            redPointStre1.state = RedPointState.Simple;
        }
 
    }
 
    public string RedPacketMaxName = null;//最大红包数量的ID
    public void GrabRedEnvelope( HA405_tagGCFamilyRedPacketGrabInfo info)//家族抢红包信息
    {
        GrabRedBagId = (int)info.RedPacketID;
        int _moneyNum = 0;
        _DicRedGrabinfo.Clear();
     
        for (int i = 0; i < info.Count;i++)
        {
            if (!_DicRedGrabinfo.ContainsKey(i))
            {
                FamilyRedPacktGrabinfo _familyRed = new FamilyRedPacktGrabinfo();
           
                _familyRed.Name = info.GrabInfo[i].Name;
                _familyRed.PlayerJob = info.GrabInfo[i].PlayeJob;
                _familyRed.MoneyNum = (int)info.GrabInfo[i].MoneyNum;
                _familyRed.Face = (int)info.GrabInfo[i].Face;
                _familyRed.FacePic = (int)info.GrabInfo[i].FacePic;
                if ((int)info.GrabInfo[i].MoneyNum > _moneyNum)
                {
                    _moneyNum = (int)info.GrabInfo[i].MoneyNum;
                    RedPacketMaxName = info.GrabInfo[i].Name;
 
                }
                _DicRedGrabinfo.Add(i, _familyRed);
 
 
            }
 
 
        }
 
        if (Event_DetailsRedEnvelopeRefresh != null)
            Event_DetailsRedEnvelopeRefresh();
 
 
 
 
    }
 
    public bool IsDisplayInFamily(int getWay)
    {
        foreach (var key in redBagTypes.Keys)
        {
            if (key == 1) continue;
            if (redBagTypes[key].Contains(getWay))
                return false;
        }
        return true;
    }
 
    public bool IsDisplayRechargeTH(FamilyRedPacket redbag)
    {
        if (!redBagTypes[2].Contains(redbag.GetWay))
            return false;
 
        if (redbag.State == 0 && redbag.PlayerID != PlayerDatas.Instance.baseData.PlayerID)
        {
            //过滤别人的可发红包
            return false;
        }
        return true;
    }
 
    public void UpdateServerGrabCntEvent()
    {
        ServerGrabCntEvent?.Invoke();
    }
}