少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, January 05, 2018
//--------------------------------------------------------
 
using vnxbqy.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
//坐骑面板
namespace vnxbqy.UI
{
 
    public class MountWin : Window
    {
        [SerializeField] Text HorseName;
        [SerializeField] Text HorseRank;
        [SerializeField] Button ChangeLookLib;
        [SerializeField] Text FightPower;
        [SerializeField] RawImage Hosrse3D;
        [SerializeField] Button UseModel;
        [SerializeField] Button CancelHorseClothe; //取消幻化并使用原阶模型
        [SerializeField] Image HorseState; //骑乘中或未激活
        [SerializeField] Text HorseStateText; //骑乘中或未激活
        [SerializeField] Button Left;
        [SerializeField] Button Right;
        [SerializeField] Button MountHunBtn;//坐骑兽魂按钮
 
        [SerializeField] UIEffect m_UieffectLVUp;//坐骑升级特效
        [SerializeField] PositionTween m_PositionTweenLVUp;
 
        [SerializeField] List<Text> AttrNameList;
        [SerializeField] List<Text> AttrValueList;
        [SerializeField] List<Text> AttrAddValueList;
 
 
        [SerializeField] ItemCell UseItem;
        [SerializeField] Text UseItemName;
        [SerializeField] Button m_TrainBtn_1;//坐骑驯养
        [SerializeField] Text m_TrainUseCnt;
        [SerializeField] Button m_AutoTrainBtn;//自动驯养 
        [SerializeField] Button m_StopTrainBtn;//停止驯养 
 
        [SerializeField] ToggleButton m_Inevitable;
 
        [SerializeField] UIEffect effectSlider; //进度条
        [SerializeField] Text Exp;
        [SerializeField] IntensifySmoothSlider ExpSlider;
        [SerializeField] Button UseFoster;
 
        #region Built-in
 
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        MountModel mountModel { get { return ModelCenter.Instance.GetModel<MountModel>(); } }
        RidingAndPetActivationModel ridingAndPetActivationModel { get { return ModelCenter.Instance.GetModel<RidingAndPetActivationModel>(); } }
 
        int m_ShowHorseLV = 1; // 当前显示的马匹阶
 
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            MountHunBtn.AddListener(OnClickMountHunButton);
            UseFoster.SetListener(() => {
                if(FosterModel.Instance.CheckHorseOpen(true))
                {
                    WindowJumpMgr.Instance.WindowJumpToEx("FosterWin");            
                }                
            });
            ChangeLookLib.SetListener(()=> {
                WindowJumpMgr.Instance.ClearJumpData();
                WindowCenter.Instance.Open<MountSkinWin>();
                WindowCenter.Instance.Close<PetWin>();
            });
            Left.SetListener(()=> {
                m_ShowHorseLV = m_ShowHorseLV - 1;
                ShowHorse();
            });
            Right.SetListener(() => {
                if (m_ShowHorseLV - mountModel.HorseLV > 2)
                {
                    ScrollTip.ShowTip(Language.Get("HorseLVUPCanSee"));
                    return;
                }
                m_ShowHorseLV = m_ShowHorseLV + 1;
                ShowHorse();
            });
            UseModel.SetListener(()=> {
                if (m_ShowHorseLV > mountModel.HorseLV)
                {
                    ScrollTip.ShowTip(Language.Get("HorseLVUPCanSee"));
                    return;
                }
                mountModel.AppearanceSwitch((byte)m_ShowHorseLV, 1);
                ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
            });
            CancelHorseClothe.SetListener(() => {
                mountModel.AppearanceSwitch((byte)m_ShowHorseLV, 1);
                ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
            });
 
            m_TrainBtn_1.SetListener(() => {
                if (mountModel.GetTrainCount() == 0)
                {
                    ScrollTip.ShowTip(Language.Get("Z1029"));
                    return;
                }
 
                if (!m_Inevitable.isOn && mountModel.GetTrainCount() > playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId))
                {
                    ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
                    return;
                }
                
                mountModel.MountDanUse(mountModel.GetTrainCount(), m_Inevitable.isOn);
            });
 
            m_AutoTrainBtn.SetListener(AutoTrain);
 
            m_StopTrainBtn.SetListener(()=> {
                StopAuto();
            });
 
            m_Inevitable.SetListener(()=> {
                m_Inevitable.isOn = !m_Inevitable.isOn;
                StopAuto();
            });
        }
 
        private void StopAuto()
        {
            autoCnt = 0;
            waitServer = false;
            StopCoroutine("OnAutoTrain");
            ShowButtonState(false);
        }
 
        
        protected override void OnPreOpen()
        {
            m_ShowHorseLV = mountModel.HorseLV;  //默认当前阶
            mountModel.onHorseInfoUpdate += HorseInfoUpdate;
            mountModel.onHorseLVUP += HorseLVUP;
            mountModel.HorseExpItemRefresh += HorseExpItemRefresh;
            MountModel.Event_MountAlteration += ShowHorse;
            ShowHorse();
            DisplayHorseInfo();
 
            ItemCellModel cellModel = new ItemCellModel(mountModel.horseUpItemId, false, 1);
            UseItem.Init(cellModel);
            UseItem.countText.SetActive(true);
            UseItem.countText.text = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId).ToString();
            var itemConfig = ItemConfig.Get(mountModel.horseUpItemId);
            UseItemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
            UseItem.button.SetListener(() =>
            {
                ItemTipUtility.Show(mountModel.horseUpItemId);
            });
            mountModel.MountStoneRed();
        }
 
        protected override void OnActived()
        {
            base.OnActived();
        }
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnPreClose()
        {
            mountModel.onHorseInfoUpdate -= HorseInfoUpdate;
            mountModel.onHorseLVUP -= HorseLVUP;
            MountModel.Event_MountAlteration -= ShowHorse;
            mountModel.HorseExpItemRefresh -= HorseExpItemRefresh;
 
            StopAuto();
            UI3DModelExhibition.Instance.StopShow();
        }
 
        protected override void OnAfterClose()
        {
 
        }
        #endregion
 
        private void RefreshLeftRightBtn()
        {
 
        }
 
        bool isHorseUpdate = false; // 用于进度条更新
        private void HorseInfoUpdate()
        {
            isHorseUpdate = true;
            effectSlider.Play();
            DisplayHorseInfo();
            waitServer = false;
        }
 
        private void DisplayHorseInfo()
        {
            ShowAttrText();
 
            HorseExpItemRefresh();
 
            ShowButton();
 
            DisplayExpSlider();
        }
 
        private void HorseExpItemRefresh()
        {
            ShowItemUseCnt();
            ShowButton();
        }
 
        private void ShowItemUseCnt()
        {
            int number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
            int useCnt = mountModel.GetTrainCount();
            m_TrainUseCnt.text = UIHelper.AppendColor(useCnt > number ? TextColType.Red : TextColType.Green, "x" + mountModel.GetTrainCount());
            UseItem.countText.text = number.ToString();
        }
 
        private void OnClickMountHunButton()
        {
            StopAuto();
            WindowCenter.Instance.Open<MountStoneTipsWin>();
        }
 
        private void ShowButton()
        {
            if (autoCnt > 0)
                return;
            m_TrainBtn_1.SetActive(true);
            m_AutoTrainBtn.SetActive(true);
            m_StopTrainBtn.SetActive(false);
 
            if (mountModel.GetTrainCount() == 0)
            {
                m_TrainBtn_1.SetActive(false);
                m_AutoTrainBtn.SetActive(false);
                m_StopTrainBtn.SetActive(false);
 
            }
        }
 
        // 幻化模型替换当前阶模型,左右按钮改变m_ShowHorseLV
        private void ShowHorse()
        {
            var horseInfo = HorseLVUpConfig.Get(m_ShowHorseLV);
            if (horseInfo == null)
            {
                //防止意外情况,正常不会出现
                m_ShowHorseLV = mountModel.HorseLV;
                horseInfo = HorseLVUpConfig.Get(m_ShowHorseLV);
            }
            int curShowHorseID = horseInfo.HorseID;
            HorseName.text = HorseConfig.Get(horseInfo.HorseID).Name;
            HorseRank.text = Language.Get("FuncRankName", m_ShowHorseLV);
 
            if (!Hosrse3D.gameObject.activeSelf)
            {
                Hosrse3D.SetActive(true);
            }
 
            int model3D = horseInfo.HorseID;
            if (mountModel.HorseIDNow != 0 && mountModel.HorseLV == m_ShowHorseLV && !mountModel.RankHorseIDList.Contains(mountModel.HorseIDNow))
            {
                //当前阶有幻化情况下替换幻化模型
                model3D = mountModel.HorseIDNow;
            }
 
            HorseConfig _model = HorseConfig.Get(model3D);
            UI3DModelExhibition.Instance.ShowHourse(_model.Model, Hosrse3D);
            if (UI3DModelExhibition.Instance.NpcModelHorse != null)
            {
                var animator = UI3DModelExhibition.Instance.NpcModelHorse.GetComponent<Animator>();
                if (animator != null)
                {
                    animator.Play(GAStaticDefine.State_Dance);
 
                }
            }
            Left.SetActive(true);
            Right.SetActive(true);
            if (m_ShowHorseLV == 1)
            {
                Left.SetActive(false);
            }
            if (HorseLVUpConfig.Get(m_ShowHorseLV + 1) == null)
            {
                Right.SetActive(false);
            }
 
            UseModel.SetActive(false);
            CancelHorseClothe.SetActive(false);
            HorseState.SetActive(false);
            if (mountModel.RankHorseIDList.Contains(mountModel.HorseIDNow))
            {
                if (curShowHorseID == mountModel.HorseIDNow)
                {
                    HorseState.SetActive(true);
                    HorseStateText.text = UIHelper.AppendColor(TextColType.NavyBrown, Language.Get("Petwin8"));
                }
                else
                {
                    UseModel.SetActive(true);
                }
            }
            else
            {
                //幻化情况
                if (mountModel.HorseLV == m_ShowHorseLV)
                {
                    CancelHorseClothe.SetActive(true);
                }
                else
                {
                    UseModel.SetActive(true);
                }
            }
 
            if (m_ShowHorseLV > mountModel.HorseLV)
            {
                UseModel.SetActive(false);
                HorseState.SetActive(true);
                HorseStateText.text = UIHelper.AppendColor(TextColType.Red, Language.Get("MountWin113"));
            }
 
        }
 
        private void ShowAttrText()
        {
            ClearAttrText();
            Dictionary<int, int> allAttr = mountModel.GetHorseAllAttr();
            Dictionary<int, int> nextAttr = mountModel.GetNextTrainAttr();
            int showIndex = 0;
            foreach (var attrID in mountModel.HorseAttrSort)
            {
                if (!allAttr.ContainsKey(attrID) && !nextAttr.ContainsKey(attrID))
                {
                    continue;
                }
 
                AttrNameList[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
                AttrValueList[showIndex].text = allAttr.ContainsKey(attrID) ? PlayerPropertyConfig.GetValueDescription(attrID, allAttr[attrID]) : PlayerPropertyConfig.GetValueDescription(attrID, 0);
                AttrAddValueList[showIndex].text =  nextAttr.ContainsKey(attrID) ? "+" + PlayerPropertyConfig.GetValueDescription(attrID, nextAttr[attrID]) : (mountModel.GetTrainCount() == 0 ? string.Empty : "+" + PlayerPropertyConfig.GetValueDescription(attrID, 0));
                showIndex++;
            }
 
            FightPower.text = (UIHelper.GetFightPower(allAttr) + mountModel.GetMountSkinAddFightPower()).ToString() ;
        }
 
        private void ClearAttrText()
        {
            for (int i = 0; i < AttrNameList.Count; i++)
            {
                AttrNameList[i].text = string.Empty;
                AttrValueList[i].text = string.Empty;
                AttrAddValueList[i].text = string.Empty;
 
            }
 
        }
 
        private void HorseLVUP()
        {
            if (!m_UieffectLVUp.IsPlaying)
            {
                m_UieffectLVUp.Play();
                m_PositionTweenLVUp.Play();
            }
            m_ShowHorseLV = mountModel.HorseLV;
            mountModel.AppearanceSwitch((byte)mountModel.HorseLV, 1);
            ScrollTip.ShowTip(Language.Get("Z1062")); //外观切换成功
            ShowHorse();
            StopAuto();
            //WindowCenter.Instance.Open<HorseLvUpWin>();
            ridingAndPetActivationModel.RidingAndPetActivationSet(RidingAndPetActivation.MountRankUp, HorseLVUpConfig.Get(m_ShowHorseLV).HorseID);
 
        }
 
 
        private void DisplayExpSlider()
        {
            var config = HorseLVUpConfig.Get(mountModel.HorseLV);
 
            if (config.NeedEatCount == 0)
            {
                Exp.text = Language.Get("Z1029");
                ExpSlider.stage = mountModel.HorseLV;
                ExpSlider.value = 1f;
                ExpSlider.delay = 0f;
                ExpSlider.ResetStage();
            }
            else
            {
                int exp = mountModel.HorseEatCount * mountModel.HorseDanExp;
                int expMax = config.NeedEatCount * mountModel.HorseDanExp;
                Exp.text = exp + "/" + expMax;
                ExpSlider.delay = isHorseUpdate ? 0.1f : 0f;
                ExpSlider.stage = mountModel.HorseLV;
                ExpSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero);
                isHorseUpdate = false;
            }
        }
 
        private void ShowButtonState(bool autoOn)
        {
            if (mountModel.GetTrainCount() == 0)
            {
                m_TrainBtn_1.SetActive(false);
                m_AutoTrainBtn.SetActive(false);
                m_StopTrainBtn.SetActive(false);
            }
            else
            {
                m_AutoTrainBtn.SetActive(!autoOn);
                m_StopTrainBtn.SetActive(autoOn);
            }
            autoCnt = 0;
        }
 
        
        private void AutoTrain()
        {
            autoCnt = 0;
            int number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
            int useCnt = mountModel.GetTrainCount();
 
            if (useCnt == 0)
            {
                ScrollTip.ShowTip(Language.Get("Z1029"));
                return;
            }
 
            int maxNeedCnt = GetNextLVNeedCnt();
            //材料足够升阶或不勾选自动购买的情况
            if (number >= maxNeedCnt || !m_Inevitable.isOn)
            {
                if (useCnt > number)
                {
                    ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
                    return;
                }
                ShowButtonState(true);
                StartCoroutine("OnAutoTrain");
                return;
            }
            
            //花仙玉购买
            var config = StoreConfig.GetStoreCfg(mountModel.horseUpItemId, 1, 1);
            int needBuyCnt = maxNeedCnt - number;
            int useMoney = config.MoneyNumber * needBuyCnt;
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(52, 1, useMoney, 2, 0);
            if (PlayerDatas.Instance.baseData.diamond < useCnt * config.MoneyNumber && number < useCnt)
            {
                //只处理最小购买单位
                SysNotifyMgr.Instance.ShowTip("GoldErr");
                WindowCenter.Instance.Open<RechargeTipWin>();
                return;
            }
 
            ConfirmCancel.ShowPopConfirm(
                    Language.Get("Mail101"),
                    Language.Get("Z1032", mountModel.HorseLV+1, needBuyCnt),
 
                    (bool _ok) =>
                    {
                        if (_ok)
                        {
                            ShowButtonState(true);
                            StartCoroutine("OnAutoTrain");
                        }
                    }
                    );
        }
 
        bool waitServer = false; //等待服务器回报后才可继续发包
        int autoCnt = 0; //用于发包数量加速
        IEnumerator OnAutoTrain()
        {
            int useSingleCnt = 0;
            int useMultiCnt = 0;
            int number = 0;
            while (true)
            {
                //不超过阶的 仙玉消耗
                //等待服务端回包
                if (waitServer)
                {
                    yield return new WaitForSeconds(0.1f);
                    continue;
                }
                autoCnt++;
                useSingleCnt = mountModel.GetTrainCount();
                useMultiCnt = Math.Min(200, Math.Max(autoCnt - 3, 1)) * useSingleCnt;
                if (useMultiCnt > GetNextLVNeedCnt())
                {
                    useMultiCnt = GetNextLVNeedCnt();
                }
 
                int needBuyCnt = 0;
                //优先消耗完身上物品再扣仙玉
                number = playerPack.GetItemCountByID(PackType.Item, mountModel.horseUpItemId);
                if (useMultiCnt > number)
                {
                    if (useSingleCnt > number)
                    {
                        if (m_Inevitable.isOn)
                        {
                            // 多次购买 或者补足一次
                            needBuyCnt = number == 0 ? useMultiCnt : useSingleCnt - number;
                        }
                        else
                        {
                            ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
                            ShowButtonState(false);
                            yield break;
                        }
                    }
                    if (needBuyCnt < useSingleCnt)
                    {
                        useMultiCnt = useSingleCnt;
                        autoCnt = 1;
                    }
                }
 
                if (needBuyCnt > 0)
                {
                    var config = StoreConfig.GetStoreCfg(mountModel.horseUpItemId, 1, 1);
                    if (PlayerDatas.Instance.baseData.diamond < needBuyCnt * config.MoneyNumber)
                    {
                        SysNotifyMgr.Instance.ShowTip("GoldErr");
                        WindowCenter.Instance.Open<RechargeTipWin>();
                        ShowButtonState(false);
                        yield break;
                    }
                }
                mountModel.MountDanUse(useMultiCnt, m_Inevitable.isOn);
 
                waitServer = true;
                yield return new WaitForSeconds(0.5f);
            }
        }
 
 
        private int GetNextLVNeedCnt()
        {
            var config = HorseLVUpConfig.Get(mountModel.HorseLV);
            int useCnt = mountModel.GetTrainCount();
            int useAllCnt = (int)Math.Ceiling((config.NeedEatCount - mountModel.HorseEatCount) / (float)useCnt) * useCnt;
 
            var nextConfig = HorseLVUpConfig.Get(mountModel.HorseLV + 1);
            if (nextConfig.NeedEatCount == 0)
            {
                // 下一阶满级,只扣剩余所需不超过单次的材料数量
                useAllCnt = config.NeedEatCount - mountModel.HorseEatCount;
            }
 
            return useAllCnt;
        }
 
    }
}