少年修仙传客户端代码仓库
Client_PangDeRong
2018-09-21 d1a2ab5b56bae336a1b5cbc4f307cb67e76c22e6
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
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
namespace Snxxz.UI
{
    public class RedEnvelopeModel : Model, IBeforePlayerDataInitialize, IPlayerLoginOk
    {
        PlayerRedPacketDatas redPackdata { get { return ModelCenter.Instance.GetModel<PlayerRedPacketDatas>(); } }
        OSRedEnvelopeModel envelopeModel { get { return ModelCenter.Instance.GetModel<OSRedEnvelopeModel>(); } }
 
        public override void Init()
        {
            ParseConfig();
            SysNotifyMgr.Instance.OnSystemNotifyEvent += OnSystemNotifyEvent;
        }
 
        public override void UnInit()
        {
 
        }
 
        public void OnPlayerLoginOk()
        {
            serverInited = true;
        }
 
        public void OnBeforePlayerDataInitialize()
        {
            serverInited = false;
            m_RedEnvelopeDict.Clear();
        }
 
        bool serverInited = false;
 
        private Dictionary<int, RedEnvelope> m_RedEnvelopeDict = new Dictionary<int, RedEnvelope>();
 
        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 = info.MoneyNum,
                    type = info.GetWay,
                    packCount = info.PacketCnt,
                    state = info.State,
                    Wish = UIHelper.ServerStringTrim(info.Wish)
                };
                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 (!WindowCenter.Instance.CheckOpen<RedDetailsTipsWin>())
                {
                    envelopeSfx = vNetData.RedPacketID == envelopeSfx && self ? envelopeSfx : 0;
                    ModelCenter.Instance.GetModel<PlayerRedPacketDatas>().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)
            };
            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))
                {
                    m_RedEnvelopeDict.Remove(_id);
                }
            }
            if (EnvelopeDelEvent != null)
            {
                EnvelopeDelEvent();
            }
        }
 
        public void SendGetEnvelope(int _id)
        {
            RedEnvelope _envelope;
            if(m_RedEnvelopeDict.TryGetValue(_id,out _envelope))
            {
                if (_envelope.state == 1)
                {
                    CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
                    _pak.RedPaketID = (uint)_id;
                    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 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 RequestDetail(int _id)
        {
            cacheEnvelopeId = _id;
            CAB12_tagCMGrabFamilyRedPacket _pak = new CAB12_tagCMGrabFamilyRedPacket();
            _pak.RedPaketID = (uint)_id;
            GameNetSystem.Instance.SendInfo(_pak);
        }
 
 
        #region 红包雨特效
        DateTime sfxRedpackTime = DateTime.Now;
 
        private void OnSystemNotifyEvent(string _key)
        {
            if (_key.Equals("OSRedpackSfx"))
            {
                CheckRedpackSfx();
            }
        }
 
        public void CheckRedpackSfx()
        {
            if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.OpenServerRedEnvelope))
            {
                return;
            }
            if (envelopeModel.getEnvelopeTimes <= 0)
            {
                return;
            }
            if (!serverInited)
            {
                return;
            }
            if (!(StageManager.Instance.CurrentStage is DungeonStage)
                || WindowCenter.Instance.CheckOpen<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);
            }
        }
        #endregion
 
        void ParseConfig()
        {
        }
 
        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;        //祝福语
        }
    }
}