少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-20 a87120c155c48fa45b20a97c1a58bdbeb77318b7
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, October 23, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
 
    public class RolePointWin : Window
    {
        [SerializeField] Button m_Close;
        [SerializeField] Button m_Suggest;
        [SerializeField] Button m_Confirm;
        [SerializeField] Text m_Point;
        [SerializeField] RectTransform m_ContainerRight;
        [SerializeField] List<PropertyValue> m_PropertyValues;
        [SerializeField] List<AddPointBehaviour> m_AddPoints;
        [SerializeField] NumKeyBoard m_NumkeyBoard;
 
        RolePointModel model { get { return ModelCenter.Instance.GetModel<RolePointModel>(); } }
 
        bool isSpeedUp = false;
        int presentAddPoint = 0;
        int surplusPoint = 0;
        Dictionary<int, int> allocatPoints = new Dictionary<int, int>();
 
        static WaitForSeconds waitSpeedUp = new WaitForSeconds(0.5f);
        static WaitForSeconds waitSpeedFaster = new WaitForSeconds(0.05f);
        static WaitForSeconds waitSpeedSlow = new WaitForSeconds(0.2f);
 
        const int WAITCNT = 1;
 
 
        protected override void BindController()
        {
 
        }
 
        protected override void AddListeners()
        {
            m_Close.onClick.AddListener(CloseClick);
            m_Confirm.onClick.AddListener(Confirm);
            m_Suggest.onClick.AddListener(Suggest);
            m_NumkeyBoard.onValueChange.AddListener(OnPointValChange);
            m_NumkeyBoard.onConfirm.AddListener((bool isOk) =>
            {
                if (isOk)
                {
                    m_NumkeyBoard.gameObject.SetActive(false);
                }
            });
            for (int i = 0; i < m_AddPoints.Count; i++)
            {
                m_AddPoints[i].onPreview = OnPreview;
                m_AddPoints[i].onSub = OnSub;
                m_AddPoints[i].onAdd = OnAdd;
            }
        }
 
        protected override void OnPreOpen()
        {
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent += OnPlayerInfoRefresh;
            m_NumkeyBoard.gameObject.SetActive(false);
            Dictionary<int, string> dict = null;
            if (model.TryGetPointFormula(PlayerDatas.Instance.baseData.Job, out dict))
            {
                int i = 0;
                foreach (var _type in dict.Keys)
                {
                    m_PropertyValues[i].property = _type;
                    i++;
                }
            }
            OnRefreshProprety();
            isSpeedUp = false;
        }
 
        protected override void OnAfterOpen()
        {
            HandleAchievement();
        }
 
        protected override void OnPreClose()
        {
            PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= OnPlayerInfoRefresh;
            isSpeedUp = false;
            StopAllCoroutines();
        }
 
        protected override void OnAfterClose()
        {
            if (!WindowJumpMgr.Instance.IsJumpState
                && !WindowCenter.Instance.IsOpen<RolePanel>()
                && !WindowCenter.Instance.IsOpen<MainInterfaceWin>())
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
        }
 
        void OnRefreshProprety()
        {
            if (model.propertys != null)
            {
                for (int i = 0; i < model.propertys.Length; i++)
                {
                    var proprety = model.propertys[i];
                    var behaviour = m_AddPoints.Find((x) =>
                    {
                        return x.property == proprety;
                    });
                    var config = PlayerPropertyConfig.Get(proprety);
                    behaviour.propertyName.text = config.Name;
                    behaviour.propertyValue.text = UIHelper.GetPropertyMapPlayerData((AttrEnum)proprety).ToString();
                    allocatPoints[proprety] = 0;
                    behaviour.propertyPreview.text = allocatPoints[proprety].ToString();
                }
            }
 
            surplusPoint = (int)PlayerDatas.Instance.baseData.FreePoint;
            m_Point.text = surplusPoint.ToString();
 
            OnRefreshAdd();
        }
 
        private void OnRefreshAdd()
        {
            Equation.Instance.Clear();
            foreach (var key in allocatPoints.Keys)
            {
                var config = PlayerPropertyConfig.Get(key);
                Equation.Instance.AddKeyValue(config.Parameter, allocatPoints[key]);
            }
            Dictionary<int, string> dict = null;
            if (model.TryGetPointFormula(PlayerDatas.Instance.baseData.Job, out dict))
            {
                foreach (var property in dict.Keys)
                {
                    float value = Equation.Instance.Eval<float>(dict[property]);
                    GetProperty(property).RefreshAdd(value);
                }
            }
        }
 
        private PropertyValue GetProperty(int property)
        {
            return m_PropertyValues.Find((x) =>
            {
                return x.property == property;
            });
        }
 
        private void HandleAchievement()
        {
            if (AchievementGoto.achievementType == AchievementGoto.RolePoint)
            {
                var _effect = AchievementGuideEffectPool.Require(1);
                _effect.transform.SetParentEx(m_Suggest.transform, Vector3.zero, Vector3.zero, Vector3.one);
                AchievementGoto.achievementType = 0;
            }
        }
 
        private void Confirm()
        {
            foreach (int key in allocatPoints.Keys)
            {
                if (allocatPoints[key] > 0)
                {
                    model.SendAddPoint(key, allocatPoints[key]);
                }
            }
        }
 
        private void Suggest()
        {
            int points = (int)PlayerDatas.Instance.baseData.FreePoint;
            int totalpoints = points;
            int pt = 0;
 
            Dictionary<int, float> suggestDict = null;
            model.TryGetPointSuggest(PlayerDatas.Instance.baseData.Job, out suggestDict);
            Dictionary<int, int> initDict = null;
            model.TryGetPointInit(PlayerDatas.Instance.baseData.Job, out initDict);
 
            if (suggestDict == null || initDict == null)
            {
                return;
            }
 
            foreach (var property in suggestDict.Keys)
            {
                totalpoints += ((int)UIHelper.GetPropertyMapPlayerData((AttrEnum)property) - initDict[property]);
            }
 
            allocatPoints.Clear();
            foreach (var property in initDict.Keys)
            {
                allocatPoints.Add(property, 0);
                var behaviour = m_AddPoints.Find((x) =>
                {
                    return x.property == property;
                });
                behaviour.propertyPreview.text = allocatPoints[property].ToString();
            }
 
            foreach (var property in suggestDict.Keys)
            {
                int expectpt = Mathf.RoundToInt(suggestDict[property] * totalpoints);
                int presentpt = expectpt - ((int)UIHelper.GetPropertyMapPlayerData((AttrEnum)property) - initDict[property]);
                if (presentpt > 0)
                {
                    if (pt + presentpt > points)
                    {
                        presentpt = points - pt;
                    }
                    pt += presentpt;
                    allocatPoints[property] = presentpt;
                }
                var behaviour = m_AddPoints.Find((x) =>
                {
                    return x.property == property;
                });
                behaviour.propertyPreview.text = allocatPoints[property].ToString();
            }
 
            surplusPoint = points - pt;
            m_Point.text = surplusPoint.ToString();
            OnRefreshAdd();
        }
 
        private void OnPlayerInfoRefresh(PlayerDataRefresh refreshType)
        {
            switch (refreshType)
            {
                case PlayerDataRefresh.FreePoint:
                    {
                        OnRefreshProprety();
                    }
                    break;
                case PlayerDataRefresh.STR:
                case PlayerDataRefresh.PNE:
                case PlayerDataRefresh.PHY:
                case PlayerDataRefresh.CON:
                    {
                        OnRefreshProprety();
                    }
                    break;
                case PlayerDataRefresh.MAXATK:
                case PlayerDataRefresh.MINATK:
                case PlayerDataRefresh.MaxHP:
                case PlayerDataRefresh.DEF:
                case PlayerDataRefresh.HIT:
                case PlayerDataRefresh.AtkInterval:
                case PlayerDataRefresh.BattleValEx1:
                    {
                        foreach (var property in m_PropertyValues)
                        {
                            property.RefreshValue();
                        }
                    }
                    break;
            }
        }
 
        private void OnPointValChange()
        {
            var key = presentAddPoint;
            surplusPoint += allocatPoints[key];
            int num = int.Parse(m_NumkeyBoard.Value);
            if (surplusPoint - num < 0)
            {
                num = surplusPoint;
            }
            allocatPoints[key] = num;
            surplusPoint -= num;
            OnUpdatePoint(key);
            m_NumkeyBoard.Value = num.ToString();
        }
 
        private void OnUpdatePoint(int key)
        {
            var behaviour = m_AddPoints.Find((x) =>
            {
                return x.property == key;
            });
            behaviour.propertyPreview.text = allocatPoints[key].ToString();
            m_Point.text = surplusPoint.ToString();
            OnRefreshAdd();
        }
 
        private void OnAdd(int property, bool down)
        {
            if (!down)
            {
                isSpeedUp = false;
                StopAllCoroutines();
                return;
            }
            isSpeedUp = true;
            if (allocatPoints.ContainsKey(property))
            {
                if (surplusPoint < 1)
                {
                    return;
                }
                allocatPoints[property]++;
                surplusPoint--;
                OnUpdatePoint(property);
            }
            StartCoroutine(Co_OnSpeedUp(true, property));
        }
 
        private void OnSub(int property, bool down)
        {
            if (!down)
            {
                isSpeedUp = false;
                StopAllCoroutines();
                return;
            }
            isSpeedUp = true;
            if (allocatPoints.ContainsKey(property))
            {
                if (allocatPoints[property] < 1)
                {
                    return;
                }
                allocatPoints[property]--;
                surplusPoint++;
                OnUpdatePoint(property);
            }
            StartCoroutine(Co_OnSpeedUp(false, property));
        }
 
        IEnumerator Co_OnSpeedUp(bool up, int property)
        {
            yield return waitSpeedUp;
            int upCnt = 0;
            while (isSpeedUp)
            {
                if (allocatPoints.ContainsKey(property))
                {
                    if (up)
                    {
                        if (surplusPoint < 1)
                        {
                            yield break;
                        }
                        allocatPoints[property]++;
                        surplusPoint--;
                        OnUpdatePoint(property);
                    }
                    else
                    {
                        if (allocatPoints[property] < 1)
                        {
                            yield break;
                        }
                        allocatPoints[property]--;
                        surplusPoint++;
                        OnUpdatePoint(property);
                    }
                }
                if (upCnt < WAITCNT)
                {
                    yield return waitSpeedSlow;
                }
                else
                {
                    yield return waitSpeedFaster;
                }
                upCnt++;
            }
        }
 
        private void OnPreview(int property)
        {
            presentAddPoint = property;
            m_NumkeyBoard.gameObject.SetActive(true);
            m_NumkeyBoard.max = (uint)surplusPoint + (uint)allocatPoints[property];
            m_NumkeyBoard.min = 0;
            var behaviour = m_AddPoints.Find((x) =>
            {
                return x.property == property;
            });
            RectTransform parent = behaviour.pointBottom;
            var worldpos = parent.TransformPoint(new Vector3(0, -parent.rect.height / 2, 0));
            var localpos = m_ContainerRight.InverseTransformPoint(worldpos);
            m_NumkeyBoard.transform.localPosition = localpos;
        }
 
        [Serializable]
        public class PropertyValue
        {
            private int m_Property;
            public int property
            {
                get
                {
                    return m_Property;
                }
                set
                {
                    m_Property = value;
                    Refresh();
                }
            }
 
            [SerializeField] Text m_PropertyName;
            [SerializeField] Text m_PropertyValue;
            [SerializeField] Text m_PropertyAdd;
 
            public void Refresh()
            {
                var config = PlayerPropertyConfig.Get(property);
                if (config != null)
                {
                    m_PropertyName.text = config.Name;
                    RefreshValue();
                    RefreshAdd(0);
                }
            }
 
            public void RefreshValue()
            {
                var config = PlayerPropertyConfig.Get(property);
                if ((AttrEnum)property == AttrEnum.ATK)
                {
                    m_PropertyValue.text = StringUtility.Contact(UIHelper.ReplaceLargeNum((ulong)PlayerDatas.Instance.extersion.MINATK),
                        "-", UIHelper.ReplaceLargeNum((ulong)PlayerDatas.Instance.extersion.MAXATK));
                }
                else
                {
                    m_PropertyValue.text = UIHelper.ReplaceLargeNum((ulong)UIHelper.GetPropertyMapPlayerData((AttrEnum)property));
                }
            }
 
            public void RefreshAdd(float _value)
            {
                m_PropertyAdd.gameObject.SetActive(_value != 0);
                if (_value > 0)
                {
                    m_PropertyAdd.text = StringUtility.Contact("+", _value);
                }
            }
        }
    }
}