少年修仙传客户端代码仓库
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
using System.Collections;
 
namespace Snxxz.UI
{
    public class EquipDevourWin : Window
    {
        [SerializeField] ScrollerController gridCtrl;
        [SerializeField] Button devourBtn;
        [SerializeField] Button equipColorSelectBtn;
        [SerializeField] Button equipLvSelectBtn;
        [SerializeField] Text equipColorText;
        [SerializeField] Text equipLvText;
        [SerializeField] GameObject colorlistObj;
        [SerializeField] GameObject lvlistObj;
        [SerializeField] Button starSelectBtn;
        [SerializeField] GameObject selectStarIcon;
        [SerializeField] ClickScreenOtherSpace colorSpaceClick;
        [SerializeField] ClickScreenOtherSpace lvSpaceClick;
 
        [SerializeField] UIEffect equipDevourEffect;
        [Header("颜色选择列表")]
        [SerializeField] List<EquipColorSelect> colorSelectlist = new List<EquipColorSelect>();
        [Header("阶级选择列表")]
        [SerializeField]
        List<EquipLvSelect> lvSelectlist = new List<EquipLvSelect>();
 
        [Header("分解装备属性")]
        [SerializeField] Text decomLvText;
        [SerializeField] Text decomPreviewLvText;
        [SerializeField] List<GameObject> decomAttrlist = new List<GameObject>();
        [SerializeField] List<Text> decomAttrNamelist = new List<Text>();
        [SerializeField] List<Text> decomAttrValuelist = new List<Text>();
        [SerializeField] List<Text> decomAttrPreviewlist = new List<Text>();
        [SerializeField] IntensifySmoothSlider expSlider;
        [SerializeField] Text expNumText;
        [SerializeField] UIEffect decomEffect;
        [SerializeField] Button getMatBtn;
        [SerializeField] Image getMatBgImg;
        [SerializeField] Image getMatIcon;
        [SerializeField] Text getMatProgressText;
 
        [SerializeField] int singleLineNum = 5;
        [SerializeField] int sumGridNum = 100;
 
        PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
        ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
        PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
 
        List<ItemModel> devourModellist;
        bool isOpen = true;
        int devourCnt = 0;
        int getMatCycle = 0;
        protected override void BindController()
        {
            colorlistObj.SetActive(true);
            lvlistObj.SetActive(true);
            gridCtrl.OnRefreshCell += RefreshGridCell;
        }
 
        protected override void AddListeners()
        {
            equipColorSelectBtn.AddListener(ClickColorSelectBtn);
            equipLvSelectBtn.AddListener(ClickLvSelectBtn);
            starSelectBtn.AddListener(ClickStarSelectBtn);
            devourBtn.AddListener(ClickEquipDecomBtn);
            colorSpaceClick.AddListener(ClickColorSelectBtn);
            lvSpaceClick.AddListener(ClickLvSelectBtn);
        }
 
        protected override void OnPreOpen()
        {
            getMatCycle = int.Parse(FuncConfigConfig.Get("EquipDecomposeAward").Numerical1);
            devourCnt = 0;
            isOpen = true;
            playerPack.selectDevourlist.Clear();
            devourModellist = playerPack.GetDevourModellist();
            InitUI();
 
        }
 
        protected override void OnAfterOpen()
        {
            this.transform.SetAsLastSibling();
            colorlistObj.SetActive(false);
            lvlistObj.SetActive(false);
            RefreshColor(playerPack.colorType);
            RefreshLv(playerPack.lvType);
            StartCoroutine(SetJumpIndex(0));
 
            playerPack.RefreshColorSelectAct += RefreshColor;
            playerPack.RefreshLvSelectAct += RefreshLv;
            playerPack.RefreshStarSelectAct += RefreshStar;
            playerPack.ItemCntAddAct += RefreshAddItem;
            playerPack.ItemCntReduceAct += RefreshReduceItem;
            playerPack.RefreshPackAct += RefreshPack;
            playerPack.RefreshDecomAttrAct += RefreshDecomAttr;
            equipDevourEffect.OnComplete += OnCompleteEvent;
            playerPack.RefreshEquipDecomNumAct += RefreshDecomPreviewAttr;
        }
 
        protected override void OnPreClose()
        {
            equipDevourEffect.OnComplete -= OnCompleteEvent;
            playerPack.RefreshColorSelectAct -= RefreshColor;
            playerPack.RefreshLvSelectAct -= RefreshLv;
            playerPack.ItemCntAddAct -= RefreshAddItem;
            playerPack.ItemCntReduceAct -= RefreshReduceItem;
            playerPack.RefreshPackAct -= RefreshPack;
            playerPack.RefreshStarSelectAct -= RefreshStar;
            playerPack.RefreshDecomAttrAct -= RefreshDecomAttr;
            playerPack.RefreshEquipDecomNumAct -= RefreshDecomPreviewAttr;
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void InitUI()
        {
            playerPack.GetSelectDevourList();
            CreateCell();
            isOpen = false;
            RefreshDecomposeAttr();
            RefreshDecomPreviewAttr();
            if(playerPack.starType != PlayerPackModel.EquipStarType.None)
            {
                selectStarIcon.SetActive(true);
            }
            else
            {
                selectStarIcon.SetActive(false);
            }
            ItemConfig getMatConfig = ItemConfig.Get(2125);
            if(getMatConfig != null)
            {
                getMatBgImg.SetItemBackGround(getMatConfig.ItemColor);
                getMatIcon.SetSprite(getMatConfig.IconKey);
                getMatBtn.RemoveAllListeners();
                getMatBtn.AddListener(()=>
                {
                    ItemAttrData attrData = new ItemAttrData(getMatConfig.ID,true);
                    tipsModel.SetItemTipsModel(attrData);
                });
            }
            RefreshGeMatProgress();
        }
 
        IEnumerator SetJumpIndex(int index)
        {
            yield return null;
            gridCtrl.JumpIndex(index);
            gridCtrl.m_Scorller.RefreshActiveCellViews();
        }
 
        private void RefreshGeMatProgress()
        {
            getMatProgressText.text = Language.Get("EquipDevour_Text5",StringUtility.Contact(playerPack.decomposeProgress,"/",getMatCycle));
        }
 
        private void RefreshAddItem(PackType type, int index, int id)
        {
            ItemConfig itemConfig = ItemConfig.Get(id);
            if (type != PackType.Item || (type == PackType.Item && itemConfig.Type != 29 && itemConfig.EquipPlace <= 0)) return;
 
            devourModellist = playerPack.GetDevourModellist();
            ItemModel itemModel = playerPack.GetItemModelByIndex(type,index);
            playerPack.RefreshGetNewItem(itemModel);
            gridCtrl.m_Scorller.RefreshActiveCellViews();
        }
 
        private void RefreshReduceItem(PackType type, int index, int id)
        {
            ItemConfig itemConfig = ItemConfig.Get(id);
            if (type != PackType.Item || (type == PackType.Item && itemConfig.Type != 29 && itemConfig.EquipPlace <= 0)) return;
 
            devourModellist = playerPack.GetDevourModellist();
            ItemModel itemModel = playerPack.GetItemModelByIndex(type,index);
            if(itemModel == null)
            {
                for(int i = 0; i < playerPack.selectDevourlist.Count; i++)
                {
                    if(playerPack.selectDevourlist[i].itemPlace == index)
                    {
                        playerPack.selectDevourlist.RemoveAt(i);
                        break;
                    }
                }
            }
 
            gridCtrl.m_Scorller.RefreshActiveCellViews();
        }
 
 
        private void RefreshPack(PackType type)
        {
            if (type != PackType.Item) return;
            playerPack.selectDevourlist.Clear();
            devourModellist = playerPack.GetDevourModellist();
            playerPack.GetSelectDevourList();
            gridCtrl.m_Scorller.RefreshActiveCellViews();
        }
 
        private void RefreshLv(PlayerPackModel.EquipLvType type)
        {
            for (int i = 0; i < lvSelectlist.Count; i++)
            {
                if (lvSelectlist[i].lvType == type)
                {
                    equipLvText.text = lvSelectlist[i].lvText.text;
                    equipLvText.color = lvSelectlist[i].lvText.color;
                    break;
                }
            }
            if (!isOpen)
            {
                lvlistObj.SetActive(false);
                playerPack.GetSelectDevourList();
                gridCtrl.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        private void RefreshColor(PlayerPackModel.EquipColorType type)
        {
            for (int i = 0; i < colorSelectlist.Count; i++)
            {
                if (colorSelectlist[i].colorType == type)
                {
                    equipColorText.text = colorSelectlist[i].colorText.text;
                    equipColorText.color = colorSelectlist[i].colorText.color;
                    break;
                }
            }
            if (!isOpen)
            {
                colorlistObj.SetActive(false);
                playerPack.GetSelectDevourList();
                gridCtrl.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        private void RefreshStar(PlayerPackModel.EquipStarType type)
        {
            if (!isOpen)
            {
                playerPack.GetSelectDevourList();
                gridCtrl.m_Scorller.RefreshActiveCellViews();
            }
        }
 
        private void CreateCell()
        {
            devourCnt = 0;
            gridCtrl.Refresh();
            int line = sumGridNum / singleLineNum;
            for(int i = 0; i < line; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header,i);
            }
            gridCtrl.Restart();
        }
 
        private void RefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int childLength = cell.transform.childCount;
            for(int i = 0; i < childLength; i++)
            {
                int cellCnt = cell.index * singleLineNum + (i + 1);
                DevourGridCell gridCell = cell.transform.GetChild(i).GetComponent<DevourGridCell>();
                if (devourModellist != null)
                {
                    if (cellCnt <= devourModellist.Count)
                    {
                        ItemModel itemModel = devourModellist[cellCnt - 1];
                        gridCell.SetModel(itemModel);
                    }
                    else
                    {
                        gridCell.SetModel(null);
                    }
                }
                else
                {
                    gridCell.SetModel(null);
                }
            }
        }
 
        private void ClickStarSelectBtn()
        {
            if(playerPack.starType != PlayerPackModel.EquipStarType.None)
            {
                playerPack.SetStarSelect(PlayerPackModel.EquipStarType.None);
                selectStarIcon.SetActive(false);
            }
            else
            {
                playerPack.SetStarSelect(PlayerPackModel.EquipStarType.One);
                selectStarIcon.SetActive(true);
            }
        }
 
        private void ClickLvSelectBtn()
        {
            if (lvlistObj.activeInHierarchy)
            {
                lvlistObj.SetActive(false);
            }
            else
            {
                lvlistObj.SetActive(true);
            }
        }
 
        private void ClickColorSelectBtn()
        {
            if(colorlistObj.activeInHierarchy)
            {
                colorlistObj.SetActive(false);
            }
            else
            {
                colorlistObj.SetActive(true);
            }
        }
 
        #region 分解属性预览
 
        private void RefreshDecomAttr()
        {
            RefreshDecomposeAttr(true);
            devourModellist = playerPack.GetDevourModellist();
            playerPack.GetSelectDevourList();
            gridCtrl.m_Scorller.RefreshActiveCellViews();
            RefreshGeMatProgress();
            RefreshDecomPreviewAttr();
            if (playerPack.getItems != null && playerPack.getItems.Length > 0)
            {
                WindowCenter.Instance.Open<DecomposeGetItemWin>();
            }
        }
        
        public void RefreshDecomposeAttr(bool isRefresh = false)
        {
            //decomPreviewLvText.gameObject.SetActive(false);
            decomLvText.text = playerPack.decomposeLv.ToString();
            EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
            expNumText.text = StringUtility.Contact(playerPack.decomposeExp,"/",deComposeConfig.UpNeedExp);
            if(!isRefresh)
            {
                expSlider.delay = 0;
                expSlider.ResetStage();
            }
            else
            {
                expSlider.delay = 0.1f;
               
            }
            expSlider.stage = playerPack.decomposeLv;
            expSlider.value = (float)Math.Round((double)playerPack.decomposeExp / deComposeConfig.UpNeedExp, 2, MidpointRounding.AwayFromZero);//经验条的初始化和刷新
            Dictionary<int, int> attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
            List<int> attrIdlist = null;
            List<int> attrValuelist = null;
            if(attrDict != null)
            {
                attrIdlist = attrDict.Keys.ToList();
                attrValuelist = attrDict.Values.ToList();
            }
            for(int i = 0; i < decomAttrlist.Count; i++)
            {
                if (attrIdlist != null)
                {
                    if(i < attrIdlist.Count)
                    {
                        decomAttrlist[i].SetActive(true);
                        decomAttrPreviewlist[i].gameObject.SetActive(false);
                        PlayerPropertyConfig propertyConfig = PlayerPropertyConfig.Get(attrIdlist[i]);
                        decomAttrNamelist[i].text = StringUtility.Contact(propertyConfig.Name,":");
                        decomAttrValuelist[i].text = attrValuelist[i].ToString();
 
                    }
                    else
                    {
                        decomAttrlist[i].SetActive(false);
                    }
                }
                else
                {
                    decomAttrlist[i].SetActive(false);
                }
            }
        }
 
        int equipAddExpPreview = 0;
        public void RefreshDecomPreviewAttr()
        {
            equipAddExpPreview = 0;
            EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
            if (playerPack.selectDevourlist.Count > 0)
            {
                int devourCnt = GetRealDevourCnt();
                equipAddExpPreview = GetPreviewExpByDevour();
                int previewLv = GetPreviewDecomposeLv(playerPack.decomposeLv, 0);
                //decomPreviewLvText.gameObject.SetActive(true);
                //decomPreviewLvText.text = StringUtility.Contact("+", previewLv - playerPack.decomposeLv);
                Dictionary<int, int> attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
                Dictionary<int, int> attrPreviewDict = playerPack.GetDecomAttrDictByLv(previewLv);
                if (attrDict != null)
                {
                    int i = 0;
                    foreach (var id in attrDict.Keys)
                    {
                        if (attrPreviewDict != null)
                        {
                            if (attrPreviewDict.ContainsKey(id))
                            {
                                decomAttrPreviewlist[i].gameObject.SetActive(true);
                                int addAttr = attrPreviewDict[id] - attrDict[id];
                                decomAttrPreviewlist[i].text = StringUtility.Contact("+", addAttr);
                            }
                        }
                        i += 1;
                    }
                }
                string previewExp = StringUtility.Contact(playerPack.decomposeExp,"+",equipAddExpPreview);
                expNumText.text = StringUtility.Contact(UIHelper.AppendStringColor(TextColType.Green,previewExp,true),"/"+ deComposeConfig.UpNeedExp);
            }
            else
            {
                RefreshDecomposeAttr();
            }
        }
 
        public int GetPreviewDecomposeLv(int decomLv,int sumNeedExp)
        {
            EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(decomLv);
            if(!playerPack.IsMaxDecomLv(decomLv,out decomLv))
            {
                if (decomLv == playerPack.decomposeLv)
                {
                    sumNeedExp += deComposeConfig.UpNeedExp - playerPack.decomposeExp;
                }
                else
                {
                    sumNeedExp += deComposeConfig.UpNeedExp;
                }
 
                if (equipAddExpPreview > sumNeedExp)
                {
                    decomLv += 1;
                    return GetPreviewDecomposeLv(decomLv, sumNeedExp);
                }
            }
            return decomLv;
        }
        #endregion
 
        private void ClickEquipDecomBtn()
        {
            if (playerPack.selectDevourlist.Count <= 0)
            {
                SysNotifyMgr.Instance.ShowTip("EquipDevour_Text_1");
                return;
            }
            int devourCnt = GetRealDevourCnt();
            int betterEquip = 0;
            int preciousCnt = 0;
            int twoStarCnt = 0;
            bool isContain = playerPack.ContainPreciousItem(realDevourlist, out betterEquip, out preciousCnt);
            bool isTwoStarEquip = playerPack.ContainTwoStarEquip(realDevourlist,out twoStarCnt);
            if (isContain || isTwoStarEquip)
            {
               if(betterEquip > 0 && preciousCnt > 0)
                {
                   ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                   Language.Get("EquipResolve_Text_1", betterEquip, preciousCnt),
                   (bool isOk) =>
                   {
                       if (isOk)
                       {
                           equipDevourEffect.Play();
                           SendEquipdevourQuest();
                       }
                   });
                }
               else if(twoStarCnt > 0 && preciousCnt > 0)
                {
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                      Language.Get("EquipResolve_Text_6", twoStarCnt, preciousCnt),
                      (bool isOk) =>
                      {
                          if (isOk)
                          {
                              equipDevourEffect.Play();
                              SendEquipdevourQuest();
                          }
                      });
                }
               else if(betterEquip > 0)
                {
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                     Language.Get("EquipResolve_Text_5", betterEquip),
                    (bool isOk) =>
                    {
                        if (isOk)
                        {
                            equipDevourEffect.Play();
                            SendEquipdevourQuest();
                        }
                    });
                }
               else if(preciousCnt > 0)
                {
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                       Language.Get("EquipResolve_Text_4",preciousCnt),
                      (bool isOk) =>
                      {
                          if (isOk)
                          {
                              equipDevourEffect.Play();
                              SendEquipdevourQuest();
                          }
                      });
                }
               else if(twoStarCnt > 0)
                {
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                      Language.Get("EquipResolve_Text_7", twoStarCnt),
                     (bool isOk) =>
                     {
                         if (isOk)
                         {
                             equipDevourEffect.Play();
                             SendEquipdevourQuest();
                         }
                     });
                }
               
            }
            else
            {
                equipDevourEffect.Play();
                SendEquipdevourQuest();
            }
          
        }
 
        private void OnCompleteEvent()
        {
            decomEffect.Play();
        }
 
        public int GetPreviewExpByDevour()
        {
            int sumExp = 0;
            for (int i = 0; i < realDevourlist.Count; i++)
            {
                int curExp = 0;
                ItemModel itemModel = realDevourlist[i];
                if (itemModel.config.EquipPlace == 0)
                {
                    curExp = itemModel.count * itemModel.config.EffectValueA1;
                }
                else
                {
                    PetEatEquipConfig tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(itemModel.config.ItemColor, itemModel.config.LV);
                    if (tagPet != null)
                    {
                        curExp = tagPet.Exp;
                    }
                }
                sumExp += curExp;
            }
 
            int vipLv = PlayerDatas.Instance.baseData.VIPLv;
            if (vipLv != 0)
            {
                int ExpUp = ModelCenter.Instance.GetModel<VipModel>().GetVipPrivilegeCnt(VipPrivilegeType.Minion);
                float percent = (float)Math.Round((double)ExpUp / 10000, 2);
                sumExp += Mathf.FloorToInt(sumExp * (float)percent);
            }
            return sumExp;
        }
 
        public void SendEquipdevourQuest()
        {
            if (!modelInterface.isPackResetOk || SettingEffectMgr.Instance.isStartDecompose) return;
 
            playerPack.isAutoDecompose = false;
            SettingEffectMgr.Instance.isStartDecompose = true;
            CA32C_tagCMEquipDecompose _petEat = new CA32C_tagCMEquipDecompose();
            var _petIndex = new ushort[realDevourlist.Count];
            var idlist = new uint[realDevourlist.Count];
            for (int i = 0; i < realDevourlist.Count; i++)
            {
                _petIndex[i] = (ushort)realDevourlist[i].itemPlace;
                idlist[i] = (uint)realDevourlist[i].itemId;
            }
            _petEat.Count = (byte)_petIndex.Length;
            _petEat.IndexList = _petIndex;
            _petEat.ItemIDList = idlist;
            _petEat.IsAuto = 0;
            GameNetSystem.Instance.SendInfo(_petEat);
        }
 
        List<ItemModel> realDevourlist = new List<ItemModel>();
        private int GetRealDevourCnt()
        {
            realDevourlist.Clear();
            int devourCnt = 0;
            for (int i = 0; i < sumGridNum; i++)
            {
                if (i < devourModellist.Count)
                {
                    ItemModel itemModel = devourModellist[i];
                    if(playerPack.selectDevourlist.Contains(itemModel))
                    {
                        devourCnt += itemModel.count;
                        realDevourlist.Add(itemModel);
                    }
                }
            }
            return devourCnt;
        }
    }
}