少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    public class HazyRegionIncidentPanel : MonoBehaviour
    {
        [SerializeField] HazyRegionCyclicScroll m_CyclicScroll;
        [SerializeField] Transform m_ContainerPoint;
        [SerializeField] Slider m_Slider;
        [SerializeField] Text m_Point;
        [SerializeField] Button m_Back;
        [SerializeField] Button m_Goto;
        [SerializeField] Text m_GotoLabel;
 
        List<int> incidents = new List<int>();
 
        HazyRegionModel model { get { return ModelCenter.Instance.GetModel<HazyRegionModel>(); } }
        DungeonModel dungeonModel { get { return ModelCenter.Instance.GetModel<DungeonModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        FindPreciousModel findPreciousModel { get { return ModelCenter.Instance.GetModel<FindPreciousModel>(); } }
        DailyQuestModel dailyQuestModel { get { return ModelCenter.Instance.GetModel<DailyQuestModel>(); } }
 
        DateTime requestTime = DateTime.Now;
        int requestCount = 0;
        float timer = 0f;
        Dictionary<int, List<byte>> requestLines = new Dictionary<int, List<byte>>();
 
        private void Awake()
        {
            m_Back.AddListener(OnBack);
            m_Goto.AddListener(Goto);
        }
 
        public void Display()
        {
            DisplayPoint();
            DisplayIncidents();
            DisplayBackButton();
            DisplayGotoState();
 
            requestCount = 0;
            model.incidentDirty = false;
            SendRequestPlayerCount();
 
            m_ContainerPoint.gameObject.SetActive(false);
 
            DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
            DailyQuestActionTimer.Instance.RefreshDailyQuestState += RefreshDailyQuestState;
 
            m_CyclicScroll.animationComplete -= AnimationComplete;
            m_CyclicScroll.animationComplete += AnimationComplete;
        }
 
        void DisplayIncidents()
        {
            incidents.Clear();
            incidents.AddRange(model.GetAllIncidents());
            incidents.Sort(Compare);
 
            if (incidents.Count > 0)
            {
                var _ids = new List<int>(incidents);
                _ids.Sort((x, y) =>
                {
                    HazyRegionModel.Incident lhs_incident;
                    HazyRegionModel.Incident rhs_incident;
                    if (model.TryGetIncident(x, out lhs_incident)
                    && model.TryGetIncident(y, out rhs_incident))
                    {
                        var lhs_index = model.incidentSelectSort.IndexOf(lhs_incident.state);
                        var rhs_index = model.incidentSelectSort.IndexOf(rhs_incident.state);
                        if (lhs_index != rhs_index)
                        {
                            return lhs_index.CompareTo(rhs_index);
                        }
                        lhs_index = incidents.IndexOf(x);
                        rhs_index = incidents.IndexOf(y);
                        if (lhs_index != rhs_index)
                        {
                            return lhs_index.CompareTo(rhs_index);
                        }
                    }
                    return 0;
                });
 
                model.selectIncident = _ids[0];
            }
 
            m_CyclicScroll.Init(incidents);
 
            if (!model.requireIncidentAnimation && model.selectIncident != incidents[0])
            {
                m_CyclicScroll.MoveToCenter(incidents.IndexOf(model.selectIncident));
            }
 
            if (model.requireIncidentAnimation)
            {
                m_CyclicScroll.DisplayAnimation();
                model.requireIncidentAnimation = false;
            }
        }
 
        void DisplayPoint()
        {
            var point = Mathf.Min(model.point, model.limitPoint);
            m_Point.text = StringUtility.Contact(point, "/", model.limitPoint);
            m_Slider.value = Mathf.Clamp01((float)point / model.limitPoint);
        }
 
        void DisplayBackButton()
        {
            m_Back.gameObject.SetActive(false);
        }
 
        int Compare(int lhs, int rhs)
        {
            var lhs_config = HazyRegionConfig.Get(lhs);
            var rhs_config = HazyRegionConfig.Get(rhs);
            var lhs_index = model.incidentTypesSort.IndexOf((HazyRegionIncidentType)lhs_config.incidentType);
            var rhs_index = model.incidentTypesSort.IndexOf((HazyRegionIncidentType)rhs_config.incidentType);
            if (lhs_index != rhs_index)
            {
                return lhs_index.CompareTo(rhs_index);
            }
            if (lhs_config.incidentType == rhs_config.incidentType)
            {
                if ((HazyRegionIncidentType)lhs_config.incidentType == HazyRegionIncidentType.DemonKing)
                {
                    if (lhs_config.lineId != rhs_config.lineId)
                    {
                        return -lhs_config.lineId.CompareTo(rhs_config.lineId);
                    }
                }
            }
            return 0;
        }
 
        private void OnBack()
        {
            if (model.IsIncidentDungeon())
            {
 
                return;
            }
 
            var state = 0;
 
            bool allComplete = true;
            int minpoint = int.MaxValue;
 
            foreach (var id in incidents)
            {
                HazyRegionModel.Incident incident;
                if (model.TryGetIncident(id, out incident))
                {
                    if (incident.state == HazyRegionModel.IncidentState.Processing)
                    {
                        state = 2;
                        allComplete = false;
                        break;
                    }
                    if(incident.state != HazyRegionModel.IncidentState.Complete)
                    {
                        allComplete = false;
                    }
                    var config = HazyRegionConfig.Get(id);
                    if (minpoint > config.point)
                    {
                        minpoint = config.point;
                    }
                }
            }
 
            if (state == 0 && !allComplete && model.point >= minpoint)
            {
                state = 1;
            }
 
            switch (state)
            {
                case 1:
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_1"), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            model.SendBackHazyRegion();
                        }
                    });
                    break;
                case 2:
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("HazyRegionBackRemind_2"), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            model.SendBackHazyRegion();
                        }
                    });
                    break;
                default:
                    model.SendBackHazyRegion();
                    break;
            }
        }
 
        private void DisplayGotoState()
        {
            var questState = dailyQuestModel.GetQuestState((int)DailyQuestType.HazyRegion);
            m_Goto.SetColorful(m_GotoLabel, questState != DailyQuestModel.DailyQuestState.OutTime);
        }
 
        private void Goto()
        {
            var error = 0;
            if (!model.TryGotoIncident(model.selectIncident, true, out error))
            {
                model.DisplayErrorRemind(error);
            }
            else
            {
                var config = HazyRegionConfig.Get(model.selectIncident);
                if (config.incidentType == (int)HazyRegionIncidentType.FairyGrass)
                {
                    HazyRegionModel.Incident incident;
                    if (model.TryGetIncident(model.selectIncident, out incident))
                    {
                        if (incident.state == HazyRegionModel.IncidentState.UnStart)
                        {
                            var item = dungeonModel.GetTicketCost(config.dungeonId, config.lineId);
                            if (item.id != 0)
                            {
                                var itemConfig = ItemConfig.Get(item.id);
                                ConfirmCancel.ShowItemConfirm(Language.Get("HazyRegionFairyGrassTicket",
                                            item.count, itemConfig.ItemName), item.id,
                                            item.count, () =>
                                            {
                                                var count = packModel.GetItemCountByID(PackType.Item, item.id);
                                                if (count >= item.count)
                                                {
                                                    model.SendGotoIncident(model.selectIncident);
                                                }
                                                else
                                                {
                                                    ItemTipUtility.Show(item.id);
                                                }
                                            });
                                return;
                            }
                        }
                    }
                }
                model.SendGotoIncident(model.selectIncident);
            }
        }
 
        private void LateUpdate()
        {
            timer += Time.deltaTime;
            if (timer >= 0.5f)
            {
                if (model.incidentDirty)
                {
                    model.incidentDirty = false;
                    requestCount = 0;
                    requestTime = DateTime.Now;
                    SendRequestPlayerCount();
                    return;
                }
                timer = 0f;
                if ((DateTime.Now - requestTime).TotalSeconds > 5
                    && requestCount < 10)
                {
                    SendRequestPlayerCount();
                }
            }
        }
 
        void SendRequestPlayerCount()
        {
            requestLines.Clear();
            for (int i = 0; i < incidents.Count; i++)
            {
                var config = HazyRegionConfig.Get(incidents[i]);
                if (config.incidentType != (int)HazyRegionIncidentType.DemonKing
                    || config.dungeonType == 0)
                {
                    continue;
                }
                if (findPreciousModel.IsBossAlive(config.npcId))
                {
                    if (!requestLines.ContainsKey(config.dungeonId))
                    {
                        requestLines.Add(config.dungeonId, new List<byte>());
                    }
                    if (!requestLines[config.dungeonId].Contains((byte)config.lineId))
                    {
                        requestLines[config.dungeonId].Add((byte)config.lineId);
                    }
                }
            }
 
            if (requestLines.Count > 0)
            {
                foreach (var mapId in requestLines.Keys)
                {
                    var pak = new CA004_tagCGGetFBLinePlayerCnt();
                    pak.MapID = (uint)mapId;
                    pak.LineCount = (byte)requestLines[mapId].Count;
                    pak.LineIDList = requestLines[mapId].ToArray();
                    GameNetSystem.Instance.SendInfo(pak);
                }
                requestCount++;
                requestTime = DateTime.Now;
            }
        }
 
        private void RefreshDailyQuestState()
        {
            DisplayGotoState();
        }
 
        private void AnimationComplete()
        {
            //if (!NewBieCenter.Instance.IsGuideCompleted(58))
            //{
            //    NewBieCenter.Instance.StartNewBieGuide(58);
            //}
        }
 
        public void Dispose()
        {
            m_CyclicScroll.Dispose();
            DailyQuestActionTimer.Instance.RefreshDailyQuestState -= RefreshDailyQuestState;
            m_CyclicScroll.animationComplete -= AnimationComplete;
        }
 
#if UNITY_EDITOR
        void OnGUI()
        {
            if (GUILayout.Button("Back"))
            {
                OnBack();
            }
        }
#endif
    }
}