少年修仙传客户端代码仓库
hch
2025-04-03 c154ac0832fe4379a00d3e1cda700e7d2a7383c7
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, September 07, 2017
//--------------------------------------------------------
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using Spine;
using System.Collections.Generic;
 
 
 
//用于人物头像面板
namespace vnxbqy.UI
{
 
    public class MainTreePanel : MonoBehaviour
    {
        [SerializeField] RawImage playerModel;
        [SerializeField] ButtonEx cutTreeBtn;
        [SerializeField] PositionTween treeSpine;
        [SerializeField] ButtonEx cutAutoBtn;
        [SerializeField] UIEffect cutEffect;
        [SerializeField] ButtonEx adventureBtn;
        [SerializeField] Text cutMoneyCnt;
        [SerializeField] EquipOnFloor equipOnFloor;
        [SerializeField] Image taskAwardImg;
        [SerializeField] Text taskAwardCnt;
        [SerializeField] Text taskName;
        [SerializeField] Text taskValue;
        [SerializeField] UIEffect taskFinishEffect;
        [SerializeField] ButtonEx taskButton;
        [SerializeField] Text treeLVTxt;
        [SerializeField] ButtonEx treeBtn;
        [SerializeField] ButtonEx familyBtn; //仙盟
        [SerializeField] ButtonEx homeBtn; //洞府
        [SerializeField] ButtonEx challengeBtn;//挑战
        [SerializeField] ButtonEx petBtn;
        [SerializeField] ButtonEx lqBtn;//灵器
        [SerializeField] ButtonEx fyBtn;//符印
        [SerializeField] ButtonEx gubaoBtn; //古宝(藏宝阁)
        [SerializeField] ButtonEx horseBtn; //坐骑
        [SerializeField] ButtonEx realmUpgrade;
        [SerializeField] List<Text> baseAttrList;
        [SerializeField] Text money1;
        [SerializeField] Button money1Btn;
        [SerializeField] Text money2;
        [SerializeField] Text playerNameText;
        [SerializeField] ImageEx AutoImg;
        [SerializeField] RotationTween AutoTween;
        [SerializeField] UIEffect AutoUIEffect;
 
        CutTreeModel cutTreeModel { get { return ModelCenter.Instance.GetModel<CutTreeModel>(); } }
        AutoCutTreeModel autoCutTreeModel { get { return ModelCenter.Instance.GetModel<AutoCutTreeModel>(); } }
        PackModel packModel { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
 
 
        int hasIdle2 = 0;  //0:未检测 1:有 -1:没有 是否有待机动作2
        int lastNPCID = 0;
 
        float lastClickTime = 0; //上次任意点击时间 用于引导
 
        protected void Awake()
        {
            cutTreeBtn.AddListener(OnCutTreeBtnClick);
            cutAutoBtn.AddListener(OpenCutAutoWin);
            adventureBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open<TurnFightFBWin>();
            });
 
            taskButton.AddListener(OnTaskClick);
            treeBtn.AddListener(() => { 
                WindowCenter.Instance.Open<FairyTreeUpgradeWin>();
            });
            homeBtn.AddListener(() => 
            {
                cutTreeModel.selectFuncArrNum = 0;
                WindowCenter.Instance.Open<FunctionEnterWin>();
            });
            challengeBtn.AddListener(() =>
            {
                cutTreeModel.selectFuncArrNum = 1;
                WindowCenter.Instance.Open<FunctionEnterWin>();
            });
            familyBtn.AddListener(() =>
            {
                ModelCenter.Instance.GetModel<FairyModel>().GotoFairyWin();
            });
            petBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open<PetWin>(false, 0);
            });
            lqBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open("SpiritEquipWin");
            });
            fyBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open<RunePanel>();
            });
            gubaoBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open("TreasurePavilionWin");
            });
            horseBtn.AddListener(() =>
            {
                WindowCenter.Instance.Open<MountMainWin>(false, 0);
            });
            realmUpgrade.AddListener(() =>
            {
                WindowCenter.Instance.Open<RealmWin>();
            });
 
            money1Btn.AddListener(() =>
            {
                WindowCenter.Instance.Open<VipRechargeWin>(false, 1);
            });
        }
 
        private void OnEnable()
        {
            lastClickTime = Time.realtimeSinceStartup;
            if (!autoCutTreeModel.isAutoCutTree)
                cutTreeModel.lastModelAnimateTime = Time.realtimeSinceStartup - 10;
 
        }
 
        public void Init()
        {
            lastClickTime = Time.realtimeSinceStartup;
            if (!autoCutTreeModel.isAutoCutTree)
                cutTreeModel.lastModelAnimateTime = Time.realtimeSinceStartup - 10;
            Display();
            equipOnFloor.Init();
            PlayerDatas.Instance.playerDataRefreshEvent += UpdatePlayerData;//数据的刷新(h0418)
            //GlobalTimeEvent.Instance.secondEvent += Instance_secondEvent;
            cutTreeModel.OnCutTreeResult += CutTreeModel_OnCutTreeResult;
            cutTreeModel.OnCutTreeTaskEvent += OnCutTreeTaskEvent;
            cutTreeModel.OnSelectMainType += OnSelectMainType;
            cutTreeModel.UpdateTreeLVEvent += UpdateTreeLVEvent;
            autoCutTreeModel.AutoCutTreeStartEvent += OnAutoCutTreeStart;
            autoCutTreeModel.AutoCutTreeStopEvent += OnAutoCutTreeStop;
        }
 
 
 
        public void UnInit()
        {
            equipOnFloor.UnInit();
            PlayerDatas.Instance.playerDataRefreshEvent -= UpdatePlayerData;//数据的刷新(h0418)
            //GlobalTimeEvent.Instance.secondEvent -= Instance_secondEvent;
            cutTreeModel.OnCutTreeResult -= CutTreeModel_OnCutTreeResult;
            cutTreeModel.OnCutTreeTaskEvent -= OnCutTreeTaskEvent;
            cutTreeModel.OnSelectMainType -= OnSelectMainType;
            cutTreeModel.UpdateTreeLVEvent -= UpdateTreeLVEvent;
            autoCutTreeModel.AutoCutTreeStartEvent -= OnAutoCutTreeStart;
            autoCutTreeModel.AutoCutTreeStopEvent -= OnAutoCutTreeStop;
        }
 
        void OnAutoCutTreeStart()
        {
            AutoImg.SetSprite("AutoCutTree02");
            AutoTween.Play();
            AutoUIEffect.Play();
        }
 
        void OnAutoCutTreeStop()
        {
            AutoImg.SetSprite("AutoCutTree01");
            AutoTween.Stop();
            AutoUIEffect.Stop();
        }
 
        void UpdatePlayerData(PlayerDataType type)//数据的刷新
        {
            if (type == PlayerDataType.default26 || type == PlayerDataType.Gold || type == PlayerDataType.default33)
                RefreshMoney();
            else if (type == PlayerDataType.MAXATK || type == PlayerDataType.DEF || type == PlayerDataType.MaxHP || type == PlayerDataType.BattleValEx1)
            {
                DisplayBaseAttr();
            }
        }
 
        void DisplayBaseAttr()
        {
            var showList = PlayerPropertyConfig.GetShowDict()[1];
            for (int i = 0; i < baseAttrList.Count; i++)
            {
                if (i < showList.Count)
                {
                    baseAttrList[i].text = PlayerPropertyConfig.GetFullDescriptionEx(showList[i], (long)UIHelper.GetPropertyValue((PropertyType)showList[i]));
                }
                else
                {
                    baseAttrList[i].text = "";
                }
            }
            
        }
 
        private void LateUpdate()
        {
            //!!! 还需要注意其他界面打开的情况下,不触发引导
            //新手几秒内未任何点击触发引导
            if (cutTreeModel.m_CutTreeTaskID > 1 && PlayerDatas.Instance.baseData.LV < cutTreeModel.autoGuideList[0] && Time.realtimeSinceStartup - lastClickTime > cutTreeModel.autoGuideList[0])
            {
                if (NewBieCenter.Instance.inGuiding)
                {
                    lastClickTime = Time.realtimeSinceStartup;
                    return;
                }
                var config = TaskConfig.Get(cutTreeModel.m_CutTreeTaskID);
                //触发引导
                if (cutTreeModel.taskClickGuide.ContainsKey(config.TaskType) && !NewBieCenter.Instance.inGuiding
                    && !WindowCenter.Instance.ExistAnyFullScreenOrMaskWin() 
                    && !WindowCenter.Instance.IsOpen<EquipExchangeWin>())
                {
                    NewBieCenter.Instance.ResetGuide(cutTreeModel.taskClickGuide[config.TaskType]);
                    NewBieCenter.Instance.StartNewBieGuideEx(cutTreeModel.taskClickGuide[config.TaskType]);
                }
 
                lastClickTime = Time.realtimeSinceStartup;
 
            }
            if (PlayerDatas.Instance.baseData.LV < 10 && Input.GetMouseButtonDown(0))
            {
                lastClickTime = Time.realtimeSinceStartup;
            }
 
            //未砍树情况下,人物进入待机2
            if (hasIdle2 > 0 && cutTreeModel.IsRestTime())
            { 
                var npcModel = UI3DModelExhibition.InstanceTree.NpcModelPet;
                var animator = npcModel.GetComponentInChildren<Animator>();
                AnimatorStateInfo _stateInfo = animator.GetCurrentAnimatorStateInfo(0);
                if (_stateInfo.shortNameHash != GAStaticDefine.State_Dance)
                {
                    animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Dance);
                    UI3DModelExhibition.InstanceTree.ChangeModelEulerAngles(new Vector3(0, PlayerModelMarkConfig.Get(PlayerDatas.Instance.baseData.modelMark).angelIdle2, 0));
                    //animator.Play(GAStaticDefine.State_Dance);
                }
 
            }
        }
 
 
        void RefreshMoney()
        {
            cutMoneyCnt.text = UIHelper.GetMoneyCnt(41).ToString();
            var money1Vaule = UIHelper.GetMoneyCnt(1);
            if (money1Vaule > 100000)
            {
                money1.text = UIHelper.ReplaceLargeNum(money1Vaule);
            }
            else
            {
                money1.text = money1Vaule.ToString();
            }
            var money2Value = UIHelper.GetMoneyCnt(42);
            if (money2Value > 100000)
            {
                money2.text = UIHelper.ReplaceLargeNum(money2Value);
            }
            else
            {
                money2.text = money2Value.ToString();
            }
        }
 
        public void Display()
        {
            playerModel.SetActive(true);
            var npcId = PlayerModelMarkConfig.Get(PlayerDatas.Instance.baseData.modelMark).npcid;
            if (lastNPCID != npcId)
            {
                lastNPCID = npcId;
                hasIdle2 = 0;
            }
            var config = NPCConfig.Get(npcId);
            if (cutTreeModel.isCreateNewUIModel)
            {   
                UI3DModelExhibition.InstanceTree.ShowNPC(npcId, config.UIModeLOffset, new Vector3(0, 0, 0), playerModel);
                cutTreeModel.isCreateNewUIModel = false;
            }
            RefreshMoney();
 
            playerNameText.text = PlayerDatas.Instance.baseData.PlayerName;
 
 
            if (!autoCutTreeModel.isAutoCutTree)
            {
                var npcModel = UI3DModelExhibition.InstanceTree.NpcModelPet;
                if (npcModel != null)
                {
                    var animator = npcModel.GetComponentInChildren<Animator>();
                    if (animator != null)
                    {
                        // 切换模型的判定
                        if (hasIdle2 == 0)
                        { 
                            // 获取Animator Controller中的动画片段列表  
                            AnimationClip[] clips = animator.runtimeAnimatorController.animationClips;
 
                            // 遍历动画片段列表,找到目标动画片段  
                            foreach (AnimationClip clip in clips)
                            {
                                if (clip.name == "Idle2")
                                {
                                    hasIdle2 = 1;
                                    break; // 找到后退出循环  
                                }
                            }
                            if (hasIdle2 != 1)
                                hasIdle2 = -1;
                        }
                        if (hasIdle2 > 0)
                        { 
                            var runtimeController = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, config.MODE);
                            animator.runtimeAnimatorController = runtimeController;
                            animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Dance);
                            UI3DModelExhibition.InstanceTree.ChangeModelEulerAngles(new Vector3(0, PlayerModelMarkConfig.Get(PlayerDatas.Instance.baseData.modelMark).angelIdle2, 0));
                            //animator.Play(GAStaticDefine.State_Dance);
                        }
                    }
 
                }
 
            }
 
 
 
            ShowTaskInfo();
            UpdateTreeLVEvent();
            DisplayBaseAttr();
        }
 
       //背包中有物品点击弹对比框不发包,物品不足不发包;
       //如果是自动状态 ,点击停止自动
       //发包 到 收包 表现动作期间 - 得到2x加速指令(激活月卡默认就是加速状态) 如果收包延迟最快0.5秒发一次包;如果砍的次数过多,速度自动加快不超过x秒
       //表现升级期间 不可点击 不可自动(等待状态)
        void OnCutTreeBtnClick()
        {
            if (autoCutTreeModel.isAutoCutTree)
            {
                autoCutTreeModel.StopAutoCutTree();
                return;
            }
 
            //砍树动作表现过程中,加速表现
            if (cutTreeModel.isPlayCutTreeAnim && Time.realtimeSinceStartup - cutTreeModel.lastModelAnimateTime < 11)
            {
                playSpeed = 2.4f * (1 + Math.Max(maxCutCount - 2, 0) * 0.3f);
                return;
            }
 
            var items = packModel.GetItems(PackType.EquipOnFloor);
            if (items != null && items.Count != 0)
            {
                cutTreeModel.OpenEquipExchangeWin(items[0]);
                return;
            }
 
            if (UIHelper.GetMoneyCnt(41) < 1)
            {
                SysNotifyMgr.Instance.ShowTip("LackMoneyCommon", 41);
                return;
            }
 
            UI3DModelExhibition.InstanceTree.ChangeModelEulerAngles(new Vector3(0, PlayerModelMarkConfig.Get(PlayerDatas.Instance.baseData.modelMark).angel, 0));
 
            cutTreeModel.SendCutTree(1);
        }
 
        void SetTreeStartState()
        {
            treeSpine.SetStartState();
        }
 
        void OpenCutAutoWin()
        {
            if (FuncOpen.Instance.IsFuncOpen(229))
            {
                WindowCenter.Instance.Open<AutoCutTreeWin>();
            }
            else
            {
                FuncOpen.Instance.ProcessorFuncErrorTip(229);
            }
        }
 
        int cutCount = 0;   //还要砍几次 计数用
        int cutNowCount = 0; // 当前还要砍几次 因为延迟显示需要记录当前的cutCount显示用
        int maxCutCount = 0; //本轮的最大砍树次数cutCount的最大值
        float playSpeed = 1f;
        int cutTreeAtkEffectStartIndex;
 
        private void CutTreeModel_OnCutTreeResult()
        {
            //时间顺序:砍树动作-掉落-分解/替换
            var quality = cutTreeModel.GetStartEquipQuality();
            var betterQuality = cutTreeModel.GetBetterEquipQuality(quality);
            maxCutCount = cutCount = betterQuality - quality + 1;
            cutTreeAtkEffectStartIndex = Math.Min(quality, cutTreeModel.cutTreeAtkEffects.Length) - 1;
            playSpeed = 1.2f * cutTreeModel.cutTreeSpeed * (1 + Math.Max(maxCutCount - 2, 0) * 0.3f);
            PlayCutTreeAnimate();
        }
 
        void PlayCutTreeAnimate()
        {
            //treeSpine.delay = 0.15f / playSpeed;
            treeSpine.duration = 1 / playSpeed;
            treeSpine.Play(SetTreeStartState);
            SoundPlayer.Instance.PlayUIAudio(853);
            cutNowCount = cutCount;
            Clock.AlarmAfter(0.25f / playSpeed, () =>
            {
                cutEffect.StopImediatly();
                cutEffect.effect = cutTreeModel.cutTreeAtkEffects[Math.Min(cutTreeAtkEffectStartIndex + maxCutCount - cutNowCount, cutTreeModel.cutTreeAtkEffects.Length - 1)];
                cutEffect.Play(); //被击特效延迟显示;后续补另一个落叶特效
            });
 
            var npcId = PlayerModelMarkConfig.Get(PlayerDatas.Instance.baseData.modelMark).npcid;
            var npcConfig = NPCConfig.Get(npcId);
            var npcModel = UI3DModelExhibition.InstanceTree.NpcModelPet;
            if (npcModel != null)
            {
                var animator = npcModel.GetComponentInChildren<Animator>();
                if (animator != null)
                {
                    animator.SetInteger(GAStaticDefine.Param_Action, GAStaticDefine.Act_Idle);
                    var runtimeController = AnimatorControllerLoader.LoadMobController(AnimatorControllerLoader.controllerSuffix, npcConfig.MODE);
                    animator.runtimeAnimatorController = runtimeController;
                    animator.speed = playSpeed;
                    animator.Play(GAStaticDefine.State_Attack1Hash);
                }
            }
            DebugEx.LogFormat("播放砍树动作 :{0}", cutCount);
            cutCount--;
            if (cutCount > 0)
            { 
                Clock.AlarmAfter(cutTreeModel.cutTreeDuration / cutTreeModel.cutTreeSpeed, PlayCutTreeAnimate);
            }
            else
            {
                Clock.AlarmAfter(1/playSpeed/2, () => { 
                    cutTreeModel.AfterPlayCutTreeAnimEvent?.Invoke();
                });
            }
        }
 
        void ShowTaskInfo()
        {
            if (cutTreeModel.m_CutTreeTaskID == 0) return;
            var config = TaskConfig.Get(cutTreeModel.m_CutTreeTaskID);
            int itemID = config.AwardItemList[0][0];
            int itemCnt = config.AwardItemList[0][1];
            taskAwardImg.SetSprite(ItemConfig.Get(itemID).IconKey);
            taskAwardCnt.text = itemCnt.ToString();
            if (config.TaskType == 4)
            {
                var fbConfig = AdventureConfig.Get(config.TaskConds[1]);
                taskName.text = string.Format(config.TaskDescribe, fbConfig.Name);
            }
            else
            { 
                taskName.text = config.TaskDescribe;
            }
            taskValue.text = string.Format("({0}/{1})", cutTreeModel.m_CutTreeTaskValue, config.NeedValue);
            taskValue.color = UIHelper.GetUIColor(cutTreeModel.m_CutTreeTaskState == 2 ? TextColType.Green : TextColType.Red, true);
            if (cutTreeModel.m_CutTreeTaskState == 2)
            {
                taskFinishEffect.Play();
            }
            else
            {
                taskFinishEffect.StopImediatly();
            }
        }
 
        void OnCutTreeTaskEvent()
        {
            ShowTaskInfo();
        }
 
        void OnSelectMainType()
        {
            Display();
        }
 
        void OnTaskClick()
        {
            if (cutTreeModel.m_CutTreeTaskID == 0) return;
            var config = TaskConfig.Get(cutTreeModel.m_CutTreeTaskID);
            if (cutTreeModel.m_CutTreeTaskState != 2)
            {
                //触发引导
                if (cutTreeModel.taskClickGuide.ContainsKey(config.TaskType) && !NewBieCenter.Instance.inGuiding)
                {
                    NewBieCenter.Instance.ResetGuide(cutTreeModel.taskClickGuide[config.TaskType]);
                    NewBieCenter.Instance.StartNewBieGuideEx(cutTreeModel.taskClickGuide[config.TaskType]);
                }
            }
            else
            {
                CA504_tagCMPlayerGetReward _pak = new CA504_tagCMPlayerGetReward();
                _pak.RewardType = 66;
                _pak.DataEx = (uint)cutTreeModel.m_CutTreeTaskID;
                GameNetSystem.Instance.SendInfo(_pak);
            }
        }
 
        void UpdateTreeLVEvent()
        {
            treeLVTxt.text = (cutTreeModel.GetUIShowTreeLV()).ToString();
        }
 
 
    }
 
}