少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using LitJson;
using System.Collections;
 
namespace vnxbqy.UI
{
    public class EquipDevourWin : Window
    {
        [SerializeField] ScrollerController gridCtrl;
        [SerializeField] Button devourBtn;
        [SerializeField] Button equipColorSelectBtn;
        [SerializeField] Text equipColorText;
        [SerializeField] GameObject colorlistObj;
        [SerializeField] ClickScreenOtherSpace colorSpaceClick;
 
        [SerializeField] UIEffect equipDevourEffect;
        [Header("颜色选择列表")]
        [SerializeField] List<EquipColorSelect> colorSelectlist = new List<EquipColorSelect>();
 
        [Header("分解装备属性")]
        [SerializeField] Text decomLvText;
        [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] ButtonEx gotoShenfj;
        [SerializeField] ItemCell devItemCell;
        [SerializeField] ItemCell devItemCell2;
 
        [SerializeField] int singleLineNum = 5;
        [SerializeField] int sumGridNum = 100;
 
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
        List<ItemModel> devourModellist;
        bool isOpen = true;
        int getMatCycle = 0;
        int devItemID;//分解装备获得的材料ID
        int devItemID2;//红装分解装备获得的材料ID
        string devourFormula;   //分解公式
        string devourFormula2;   //红装分解公式
        int preViewDevItemCnt; //分解获得的材料数量
        int preViewDevItemCnt2; //红装分解获得的材料数量
        protected override void BindController()
        {
            colorlistObj.SetActive(true);
            gridCtrl.OnRefreshCell += RefreshGridCell;
        }
 
        protected override void AddListeners()
        {
            equipColorSelectBtn.AddListener(ClickColorSelectBtn);
            devourBtn.AddListener(ClickEquipDecomBtn);
            colorSpaceClick.AddListener(ClickColorSelectBtn);
            gotoShenfj.AddListener(() =>
            {
                WindowCenter.Instance.Open("EquipShenDecomposeWin");
            });
        }
 
        protected override void OnPreOpen()
        {
            if (getMatCycle == 0)
            { 
                var config = FuncConfigConfig.Get("EquipDecomposeAward");
                getMatCycle = int.Parse(config.Numerical1);
                devItemID = int.Parse(config.Numerical4);
                devourFormula = config.Numerical5;
 
                //{"5":[3017,"1+itemClass"]}
                var json = JsonMapper.ToObject(FuncConfigConfig.Get("EquipDecomposeAward2").Numerical1);
                devItemID2 = int.Parse(json["5"][0].ToString());
                devourFormula2 = json["5"][1].ToString();
            }
            isOpen = true;
            playerPack.selectDevourlist.Clear();
            devourModellist = playerPack.GetDevourModellist();
            
        }
 
        protected override void OnAfterOpen()
        {
            InitUI();
            this.transform.SetAsLastSibling();
 
            OnRefreshColor(playerPack.colorType);
            StartCoroutine(SetJumpIndex(0));
 
            playerPack.RefreshColorSelectAct += OnRefreshColor;
            playerPack.itemCntAddEvent += RefreshAddItem;
            playerPack.itemCntReduceEvent += RefreshReduceItem;
            playerPack.refrechPackEvent += OnRefreshPack;
            playerPack.RefreshDecomAttrAct += RefreshDecomAttr;
            equipDevourEffect.OnComplete += OnCompleteEvent;
            playerPack.RefreshEquipDecomNumAct += RefreshDecomPreviewAttr;
            GlobalTimeEvent.Instance.secondEvent += CheckRefreshScroller;
        }
 
        protected override void OnPreClose()
        {
            equipDevourEffect.OnComplete -= OnCompleteEvent;
            playerPack.RefreshColorSelectAct -= OnRefreshColor;
            playerPack.itemCntAddEvent -= RefreshAddItem;
            playerPack.itemCntReduceEvent -= RefreshReduceItem;
            playerPack.refrechPackEvent -= OnRefreshPack;
            playerPack.RefreshDecomAttrAct -= RefreshDecomAttr;
            playerPack.RefreshEquipDecomNumAct -= RefreshDecomPreviewAttr;
            GlobalTimeEvent.Instance.secondEvent -= CheckRefreshScroller;
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        protected override void OnActived()
        {
            base.OnActived();
            colorlistObj.SetActive(false);
        }
 
        private void InitUI()
        {
            sumGridNum = Math.Max(100, (int)(devourModellist.Count * 1.5));
            playerPack.GetSelectDevourList();
            CreateCell();
            isOpen = false;
            RefreshDecomposeAttr();
            RefreshDecomPreviewAttr();
            ItemConfig getMatConfig = ItemConfig.Get(2125);
            if (getMatConfig != null)
            {
                getMatBgImg.SetItemBackGround(getMatConfig.ItemColor);
                getMatIcon.SetSprite(getMatConfig.IconKey);
                getMatBtn.RemoveAllListeners();
                getMatBtn.AddListener(() =>
                {
                    ItemTipUtility.Show(getMatConfig.ID);
                });
            }
            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.GetItemByIndex(type, index);
            playerPack.RefreshGetNewItem(itemModel);
            //gridCtrl.m_Scorller.RefreshActiveCellViews();
            m_RefreshScroller = true;
        }
 
        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.GetItemByIndex(type, index);
            if (itemModel == null)
            {
                for (int i = 0; i < playerPack.selectDevourlist.Count; i++)
                {
                    if (playerPack.selectDevourlist[i].gridIndex == index)
                    {
                        playerPack.selectDevourlist.RemoveAt(i);
                        break;
                    }
                }
            }
 
            //gridCtrl.m_Scorller.RefreshActiveCellViews();
            m_RefreshScroller = true;
        }
 
        bool m_RefreshScroller = false;
        void CheckRefreshScroller()
        {
            if (m_RefreshScroller)
            {
                gridCtrl.m_Scorller.RefreshActiveCellViews();
                m_RefreshScroller = false;
            }
        }
 
        private void OnRefreshPack(PackType type)
        {
            if (type != PackType.Item) return;
            playerPack.selectDevourlist.Clear();
            devourModellist = playerPack.GetDevourModellist();
            playerPack.GetSelectDevourList();
            //gridCtrl.m_Scorller.RefreshActiveCellViews();
            m_RefreshScroller = true;
            RefreshDecomposeAttr();
            RefreshDecomPreviewAttr();
            RefreshGeMatProgress();
        }
 
        private void OnRefreshColor(PackModel.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();
                RefreshDecomposeAttr();
                RefreshDecomPreviewAttr();
                RefreshGeMatProgress();
            }
        }
 
        private void CreateCell()
        {
            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 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>();
            }
        }
 
        void RefreshDecomposeAttr(bool isRefresh = 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);//经验条的初始化和刷新
            var 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].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;
        void RefreshDecomPreviewAttr()
        {
            equipAddExpPreview = 0;
            EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
            devItemCell.SetActive(false);
            devItemCell2.SetActive(false);
            if (playerPack.selectDevourlist.Count > 0)
            {
                equipAddExpPreview = GetPreviewExpByDevour();
                var previewLv = GetPreviewDecomposeLv(playerPack.decomposeLv, 0);
                var attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
                var 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].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.AppendColor(TextColType.Green, previewExp, true), "/" + deComposeConfig.UpNeedExp);
                if (preViewDevItemCnt != 0)
                {
                    devItemCell.SetActive(true);
                    devItemCell.Init(new ItemCellModel(devItemID, false, (ulong)preViewDevItemCnt));
                    devItemCell.button.AddListener(() => { 
                        ItemTipUtility.Show(devItemID);
                    });
                }
 
                if (preViewDevItemCnt2 != 0)
                {
                    devItemCell2.SetActive(true);
                    devItemCell2.Init(new ItemCellModel(devItemID2, false, (ulong)preViewDevItemCnt2));
                    devItemCell2.button.AddListener(() => {
                        ItemTipUtility.Show(devItemID2);
                    });
                }
            }
            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;
            }
 
            var betterEquipCount = GetBetterEquipCount(playerPack.selectDevourlist);
            if (betterEquipCount > 0)
            {
                ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                   Language.Get("EquipResolve_Text_1", betterEquipCount),
                  (bool ok) =>
                  {
                      if (ok)
                      {
                          equipDevourEffect.Play();
                          playerPack.SendEquipdevourQuest(false);
                      }
                  });
            }
            else
            {
                equipDevourEffect.Play();
                playerPack.SendEquipdevourQuest(false);
            }
 
        }
 
        private void OnCompleteEvent()
        {
            decomEffect.Play();
        }
 
        int GetBetterEquipCount(List<ItemModel> itemModels)
        {
            if (itemModels.IsNullOrEmpty())
            {
                return 0;
            }
 
            var count = 0;
            foreach (var item in itemModels)
            {
                if (item.isAuction || ItemLogicUtility.Instance.IsFightUp(item.itemId, item.score) == 1)
                {
                    count += item.count;
                }
                
            }
            return count;
        }
 
 
        int GetPreviewExpByDevour()
        {
            int sumExp = 0;
            preViewDevItemCnt = 0;
            preViewDevItemCnt2 = 0;
            for (int i = 0; i < playerPack.selectDevourlist.Count; i++)
            {
                int curExp = 0;
                ItemModel itemModel = playerPack.selectDevourlist[i];
                if (itemModel.config.EquipPlace == 0)
                {
                    curExp = itemModel.count * itemModel.config.EffectValueA1;
                }
                else
                {
                    var tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(itemModel.config.ItemColor, itemModel.config.LV);
                    if (tagPet != null)
                    {
                        curExp = tagPet.Exp;
                    }
                    preViewDevItemCnt += GetDogzScoreById(itemModel);
                    preViewDevItemCnt2 += GetRedEquipDevourItemCnt(itemModel);
                }
                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 int GetDogzScoreById(ItemModel itemModel)
        {
            if (itemModel == null)
                return 0;
            if (itemModel.config.ItemColor < 4)
                return 0;
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("itemColor", itemModel.config.ItemColor);
            Equation.Instance.AddKeyValue("isSuite", itemModel.config.SuiteiD == 0 ? 0 : 1);
            Equation.Instance.AddKeyValue("itemClass", itemModel.config.LV);
            return Equation.Instance.Eval<int>(devourFormula);
        }
 
        //红装分解可获得的材料数量
        public int GetRedEquipDevourItemCnt(ItemModel itemModel)
        {
            if (itemModel == null)
                return 0;
            if (itemModel.config.ItemColor < 5)
                return 0;
            Equation.Instance.Clear();
            Equation.Instance.AddKeyValue("itemColor", itemModel.config.ItemColor);
            Equation.Instance.AddKeyValue("isSuite", itemModel.config.SuiteiD == 0 ? 0 : 1);
            Equation.Instance.AddKeyValue("itemClass", itemModel.config.LV);
            return Equation.Instance.Eval<int>(devourFormula2);
        }
    }
}