少年修仙传客户端代码仓库
hch
2025-07-02 600733c8f592cb9e65f2b7a3e110ac1d686e6bfe
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, June 11, 2019
//--------------------------------------------------------
 
using LitJson;
using vnxbqy.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
 
 
 
public class FaQiLVUPWin : ILWindow
{
    Button preViewLeft;
    Button preViewRight;
    Text faqiName;
    Text faqiRank;
    Text fightPower;
    RawImage faqi3D;
    List<Text> attrNames = new List<Text>();
    List<Text> nums = new List<Text>();
    List<Text> addNums = new List<Text>();
    IntensifySmoothSlider expSlider;
    Text expNum;
    ItemCell itemCell;
    Text itemName;
    Text useCnt;
    ToggleButton autoBuy;
    Button train;
    Button autoTrain;
    Button stopTrain;
    Transform activeState;
 
 
    PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
    StoreModel storeModel { get { return ModelCenter.Instance.GetModelEx<StoreModel>(); } }
    int selectFaqiLV = 1;
 
    #region Built-in
    protected override void BindController()
    {
        preViewLeft = proxy.GetWidgtEx<Button>("leftarrow");
        preViewRight = proxy.GetWidgtEx<Button>("rightarrow");
        faqiName = proxy.GetWidgtEx<Text>("name");
        faqiRank = proxy.GetWidgtEx<Text>("rank");
        fightPower = proxy.GetWidgtEx<Text>("fightPower");
        faqi3D = proxy.GetWidgtEx<RawImage>("FaqiRawImg");
        for (int i = 0; i < 5; i++)
        {
            attrNames.Add(proxy.GetWidgtEx<Text>("attrname" + i));
            nums.Add(proxy.GetWidgtEx<Text>("num" + i));
            addNums.Add(proxy.GetWidgtEx<Text>("addnum" + i));
        }
        expSlider = proxy.GetWidgtEx<IntensifySmoothSlider>("ExpSlider");
        expNum = proxy.GetWidgtEx<Text>("ExpNum");
        itemCell = proxy.GetWidgtEx<ItemCell>("ItemCell1");
        itemName = proxy.GetWidgtEx<Text>("itemName");
        useCnt = proxy.GetWidgtEx<Text>("useCnt");
        autoBuy = proxy.GetWidgtEx<ToggleButton>("Toggle_Inevitable");
        train = proxy.GetWidgtEx<Button>("TrainBtn_1");
        autoTrain = proxy.GetWidgtEx<Button>("AutoTrainBtn");
        stopTrain = proxy.GetWidgtEx<Button>("StopTrainBtn");
        activeState = proxy.GetWidgtEx<Transform>("activeState");
    }
 
    protected override void AddListeners()
    {
 
        preViewLeft.SetListener(()=> {
            if (selectFaqiLV <= 1) return;
            selectFaqiLV--;
            DisplayPreview();
        });
        preViewRight.SetListener(() => {
            if (selectFaqiLV >= ILFaQiLVUpConfig.GetKeys().Count) return;
            selectFaqiLV++;
            DisplayPreview();
        });
 
        autoTrain.SetListener(AutoTrain);
        stopTrain.SetListener(StopAuto);
        autoBuy.SetListener(()=> {
            autoBuy.isOn = !autoBuy.isOn;
            StopAuto();
        });
 
        train.SetListener(TrainOne);
    }
 
    protected override void OnPreOpen()
    {
        FaQiLVUPModel.Instance.onFaqiUpdateEvent += OnFaqiUpdateEvent;
        FaQiLVUPModel.Instance.onFaqiLVChangeEvent += OnFaqiLVChangeEvent;
        packModel.refreshItemCountEvent += RefreshItemCount;
        selectFaqiLV = FaQiLVUPModel.Instance.faqiLV;
        Display();
    }
    protected override void OnPreClose()
    {
        FaQiLVUPModel.Instance.onFaqiUpdateEvent -= OnFaqiUpdateEvent;
        FaQiLVUPModel.Instance.onFaqiLVChangeEvent -= OnFaqiLVChangeEvent;
        packModel.refreshItemCountEvent -= RefreshItemCount;
    }
 
    #endregion
 
    private void RefreshItemCount(PackType type, int index, int id)
    {
        if (id == FaQiLVUPModel.Instance.faqiLVUPItemID)
        {
            ShowItemUseCnt();
        }
 
    }
 
    void Display()
    {
        ShowFaqiOperateInfo();
        DisplayPreview();
 
        ItemCellModel cellModel = new ItemCellModel(FaQiLVUPModel.Instance.faqiLVUPItemID, false, 1);
        itemCell.Init(cellModel);
        itemCell.countText.SetActiveIL(true);
        itemCell.countText.text = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID).ToString();
        var itemConfig = ItemConfig.Get(FaQiLVUPModel.Instance.faqiLVUPItemID);
        itemName.text = UIHelper.AppendColor(itemConfig.ItemColor, itemConfig.ItemName);
        itemCell.button.SetListener(() =>
        {
            ItemTipUtility.Show(FaQiLVUPModel.Instance.faqiLVUPItemID);
        });
    }
 
 
    void DisplayPreview()
    {
        ILFaQiLVUpConfig selectFaqiConfig = ILFaQiLVUpConfig.Get(selectFaqiLV);
        faqiName.text = selectFaqiConfig.Name;
        faqiRank.text = Language.Get("FuncRankName", selectFaqiLV);
        string pathName;
        if (AssetSource.uiFromEditor)
        {
            pathName = selectFaqiConfig.PathName + "/";
        }
        else
        {
            pathName = selectFaqiConfig.PathName.ToLower();
        }
 
        if (!faqi3D.gameObject.activeSelf)
        {
            faqi3D.SetActiveIL(true);
        }
        UI3DTreasureExhibition.Instance.ShowFaQiModel(pathName, selectFaqiConfig.Model, faqi3D, selectFaqiConfig.EffectID);
        activeState.SetActiveIL(selectFaqiLV > FaQiLVUPModel.Instance.faqiLV);
    }
 
    void ShowFaqiOperateInfo()
    {
        ShowAttrText();
        DisplayExpSlider();
        ShowItemUseCnt();
        ShowButton();
    }
    private void ShowAttrText()
    {
        var nextAttr = FaQiLVUPModel.Instance.GetNextTrainAttr();
        ClearAttrText();
        int showIndex = 0;
        for (int i = 0; i < FaQiLVUPModel.Instance.attrSort.Count; i++)
        {
            var attrID = FaQiLVUPModel.Instance.attrSort[i];
            var attrValue = FaQiLVUPModel.Instance.faqiLVUPAttr.ContainsKey(attrID) ? FaQiLVUPModel.Instance.faqiLVUPAttr[attrID] : 0;
            attrNames[showIndex].text = PlayerPropertyConfig.Get(attrID).ShowName;
            nums[showIndex].text = PlayerPropertyConfig.GetValueDescription(attrID, attrValue);
            if (nextAttr.ContainsKey(attrID))
            {
                addNums[i].SetActiveIL(true);
                addNums[showIndex].text = "+" + PlayerPropertyConfig.GetValueDescription(attrID, nextAttr[attrID]);
            }
            
            showIndex++;
        }
 
        fightPower.text = UIHelper.ReplaceLargeArtNum(UIHelper.GetFightPower(FaQiLVUPModel.Instance.faqiLVUPAttr));
    }
 
    private void ClearAttrText()
    {
        for (int i = 0; i < attrNames.Count; i++)
        {
            attrNames[i].text = string.Empty;
            nums[i].text = string.Empty;
            addNums[i].text = string.Empty;
            addNums[i].SetActiveIL(false);
 
        }
 
    }
    void OnFaqiUpdateEvent()
    {
        isHorseUpdate = true;
        ShowFaqiOperateInfo();
        waitServer = false;
    }
 
    void OnFaqiLVChangeEvent()
    {
        selectFaqiLV = FaQiLVUPModel.Instance.faqiLV;
        DisplayPreview();
        StopAuto();
        WindowCenter.Instance.OpenIL<FaQiLVUPSuccessWin>();
    }
 
    private void ShowItemUseCnt()
    {
        int number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
        int useCount = FaQiLVUPModel.Instance.GetTrainCount();
        useCnt.text = UIHelper.AppendColor(useCount > number ? TextColType.Red : TextColType.Green, "x" + useCount);
        itemCell.countText.text = number.ToString();
    }
 
    private void ShowButton()
    {
        if (autoCnt > 0)
            return;
        train.SetActiveIL(true);
        autoTrain.SetActiveIL(true);
        stopTrain.SetActiveIL(false);
 
        if (FaQiLVUPModel.Instance.GetTrainCount() == 0)
        {
            train.SetActiveIL(false);
            autoTrain.SetActiveIL(false);
            stopTrain.SetActiveIL(false);
 
        }
    }
 
    private void ShowButtonState(bool autoOn)
    {
        if (FaQiLVUPModel.Instance.GetTrainCount() == 0)
        {
            train.SetActiveIL(false);
            autoTrain.SetActiveIL(false);
            stopTrain.SetActiveIL(false);
        }
        else
        {
            autoTrain.SetActiveIL(!autoOn);
            stopTrain.SetActiveIL(autoOn);
        }
        autoCnt = 0;
    }
 
    private int GetNextLVNeedCnt()
    {
        var config = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV);
        int useCnt = FaQiLVUPModel.Instance.GetTrainCount();
        int useAllCnt = Mathf.CeilToInt((config.NeedEatCount - FaQiLVUPModel.Instance.eatItemCount) / (float)useCnt) * useCnt;
 
        var nextConfig = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV + 1);
        if (nextConfig.NeedEatCount == 0)
        {
            // 下一阶满级,只扣剩余所需不超过单次的材料数量
            useAllCnt = config.NeedEatCount - FaQiLVUPModel.Instance.eatItemCount;
        }
 
        return useAllCnt;
    }
 
 
    private void AutoTrain()
    {
        autoCnt = 0;
        int number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
        int useCnt = FaQiLVUPModel.Instance.GetTrainCount();
 
        if (useCnt == 0)
        {
            ScrollTip.ShowTip(Language.Get("Z1029"));
            return;
        }
        int maxNeedCnt = GetNextLVNeedCnt();
        //材料足够升阶或不勾选自动购买的情况
        if (number >= maxNeedCnt || !autoBuy.isOn)
        {
            if (useCnt > number)
            {
                ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
                return;
            }
            ShowButtonState(true);
            SnxxzGame.Instance.StartCoroutine(OnAutoTrain());
            return;
        }
        
        //花仙玉购买限购商品
        var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
        int needBuyCnt = maxNeedCnt - number;
        int useMoney = config.MoneyNumber * needBuyCnt;
        if ((int)UIHelper.GetMoneyCnt(1) < useCnt * config.MoneyNumber && number < useCnt)
        {
            //只处理最小购买单位
            SysNotifyMgr.Instance.ShowTip("LackMoney", 1);
            WindowCenter.Instance.Open<RechargeTipWin>();
            return;
        }
 
        ConfirmCancel.ShowPopConfirm(
                Language.Get("Mail101"),
                Language.Get("FaQiWin_4", FaQiLVUPModel.Instance.faqiLV + 1, needBuyCnt),
 
                (bool _ok) =>
                {
                    if (_ok)
                    {
                        ShowButtonState(true);
                        SnxxzGame.Instance.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 = FaQiLVUPModel.Instance.GetTrainCount();
            useMultiCnt = Mathf.Min(100, Mathf.Max(autoCnt - 3, 1)) * useSingleCnt;
            LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(13, FaQiLVUPModel.Instance.faqiLVUPItemID, useMultiCnt, 1, 0);
            if (useMultiCnt > GetNextLVNeedCnt())
            {
                useMultiCnt = GetNextLVNeedCnt();
            }
            var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
            int needBuyCnt = 0;
            //优先消耗完身上物品再扣钱
            number = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
            if (useMultiCnt > number)
            {
                if (useSingleCnt > number)
                {
                    if (autoBuy.isOn)
                    {
                        // 多次购买 或者补足一次
                        needBuyCnt = number == 0 ? useMultiCnt : useSingleCnt - number;
                        int remainNum = 10000000; //没有限购
                        //storeModel.TryGetIsSellOut(config, out remainNum);
                        if (remainNum == 0 || useSingleCnt > remainNum)
                        {
                            //限购买完 或不够1次的情况
                            SysNotifyMgr.Instance.ShowTip("ShopBuyLimit");
                            yield break;
                        }
                        if (needBuyCnt > remainNum)
                        {
                            //多倍购买不够改成1倍购买
                            needBuyCnt = useSingleCnt;
                            useMultiCnt = useSingleCnt;
                            autoCnt = 1;
                        }
                    }
                    else
                    {
                        ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
                        ShowButtonState(false);
                        yield break;
                    }
                }
 
                if (needBuyCnt < useSingleCnt)
                {
                    useMultiCnt = useSingleCnt;
                    autoCnt = 1;
                }
            }
 
            if (needBuyCnt > 0)
            {
 
                if ((int)UIHelper.GetMoneyCnt(1) < needBuyCnt * config.MoneyNumber)
                {
                    SysNotifyMgr.Instance.ShowTip("LackMoney", 1);
                    WindowCenter.Instance.Open<RechargeTipWin>();
                    ShowButtonState(false);
                    yield break;
                }
            }
            FaQiLVUPModel.Instance.UpgradeFaqi(useMultiCnt, autoBuy.isOn);
 
            waitServer = true;
            yield return new WaitForSeconds(0.5f);
        }
    }
 
    private void StopAuto()
    {
        autoCnt = 0;
        waitServer = false;
        SnxxzGame.Instance.StopAllCoroutines();
        ShowButtonState(false);
    }
 
 
    void TrainOne()
    {
        var singleCnt = FaQiLVUPModel.Instance.GetTrainCount();
        if (singleCnt == 0)
        {
            ScrollTip.ShowTip(Language.Get("Z1029"));
            return;
        }
 
        var hasCnt = packModel.GetItemCountByID(PackType.Item, FaQiLVUPModel.Instance.faqiLVUPItemID);
 
        if (!autoBuy.isOn && singleCnt > hasCnt)
        {
            ScrollTip.ShowTip(UIHelper.AppendColor(TextColType.Red, Language.Get("Material101")));
            return;
        }
        LimitedTimeLuxuryGiftModel.Instance.IsItemIdShow(13, FaQiLVUPModel.Instance.faqiLVUPItemID, singleCnt,1, 0);
        //var config = StoreConfig.Get(FaQiLVUPModel.Instance.faqiLVUPStoreID);
        int remainNum = 10000000; //没有限购
        //storeModel.TryGetIsSellOut(config, out remainNum);
 
        if (singleCnt > (hasCnt + remainNum))
        {
            //限购买完 或不够1次的情况
            SysNotifyMgr.Instance.ShowTip("ShopBuyLimit");
            return;
        }
        
        FaQiLVUPModel.Instance.UpgradeFaqi(singleCnt, autoBuy.isOn);
    }
 
    bool isHorseUpdate = false; // 用于进度条更新
    private void DisplayExpSlider()
    {
        var config = ILFaQiLVUpConfig.Get(FaQiLVUPModel.Instance.faqiLV);
 
        if (config.NeedEatCount == 0)
        {
            expNum.text = Language.Get("Z1029");
            expSlider.stage = FaQiLVUPModel.Instance.faqiLV;
            expSlider.value = 1f;
            expSlider.delay = 0f;
            expSlider.ResetStage();
        }
        else
        {
            int exp = FaQiLVUPModel.Instance.eatItemCount * FaQiLVUPModel.onceItemExp;
            int expMax = config.NeedEatCount * FaQiLVUPModel.onceItemExp;
            expNum.text = exp + "/" + expMax;
            expSlider.delay = isHorseUpdate ? 0.1f : 0f;
            expSlider.stage = FaQiLVUPModel.Instance.faqiLV;
            expSlider.value = (float)Math.Round((float)exp / expMax, 2, MidpointRounding.AwayFromZero);
            isHorseUpdate = false;
        }
    }
}