少年修仙传客户端代码仓库
client_Wu Xijin
2019-03-05 efa5f8d07fc3321f6ac5f5d97fb422db28d0886f
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
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
 
//红包信息
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  class FamilyRedPacktGrabinfo//家族抢红包的信息
{
 
    public string Name;//玩家名字
    public int PlayerJob;//玩家职业
    public int MoneyNum;//金钱数量
 
 
}
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 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 int UseLimit = 0;//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;
    }
 
    public override void UnInit()
    {
      
    }
 
    public void OnBeforePlayerDataInitialize()
    {
        UseLimit = 0;
        RedEnvelopeID = 0;
        IsRedBagGetBool = false;
        RedBagId = 0;
    }
 
    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);
                }
            }
        }
    }
    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;
                    _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;
                    _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;
                    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]);
                        RedBagPoppingOpen();
                    }
                        
                }
            }
        }
 
        IsRedBagGet();
        RedPacketRedDot();
    }
 
    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>();//打开领取界面
            }
        }
 
 
    }
 
 
    public void IsRedBagGet()
    {
        IsRedBagGetBool = false;
        foreach (var value in _DicRedBag.Values)
        {
            if (!IsDisplayInFamily(value.GetWay))
            {
                continue;
            }
            if (value.State == 1)
            {
                IsRedBagGetBool = true;
            }
        }
        if (IsRedBagGetBool)
        {
            if (OnRedBagGetEvent != null)
            {
                OnRedBagGetEvent();
            }
        }
    }
 
 
    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;
                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)
    {
        if (getWay == 5)
        {
            return false;
        }
        if (getWay == FestivalRedpackModel.FESTIVALSYSTEMREDPACK1
            || getWay == FestivalRedpackModel.FESTIVALSYSTEMREDPACK2
            || getWay == FestivalRedpackModel.FESTIVALTASKREDPACKTYPE)
        {
            return false;
        }
        return true;
    }
 
}