少年修仙传客户端代码仓库
client_Wu Xijin
2018-09-10 34c01f30d2e26aa76a0ee0a5a06664a25ef3fe5a
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
using System.Collections.Generic;
using Snxxz.UI;
using TableConfig;
using UnityEngine;
using UnityEngine.Events;
 
public class GA_Player : GActorPlayerBase, IOtherSelectable
{
    // 为守护特殊定义的当前是否装备守护id
    public int serverGuardId;
 
    public static UnityAction<uint, bool> s_OnSelected;
    public static UnityAction<uint, ulong, ulong> s_OnRefreshLife;
 
    protected H0434_tagAreaPlayerAppearEx m_H0434;
 
    private CmdManager m_CmdManager;
 
    private int m_ComAtkIndex;// 普攻索引
 
    protected override void OnInit(GameNetPackBasic package)
    {
        m_H0434 = package as H0434_tagAreaPlayerAppearEx;
 
        if (m_H0434 == null)
        {
            return;
        }
 
        base.OnInit(package);
 
        if (CanBeSelected())
        {
            CapsuleCollider _capCollider = Root.AddMissingComponent<CapsuleCollider>();
            _capCollider.height = 1.2f;
            _capCollider.center = new Vector3(0, .6f, 0);
            _capCollider.radius = .4f;
 
            Evt_PlayerClick _evtClick = Root.AddMissingComponent<Evt_PlayerClick>();
            _evtClick.ownerSID = ServerInstID;
        }
 
        Root.gameObject.layer = LayerUtility.Player;
 
        // 初始化坐标
        AdjustPos(m_H0434.PosX, m_H0434.PosY);
 
        // 计算移动速度
        CalculateMoveSpeed(m_H0434.Speed);
 
        CalculateAtkSpeed((ushort)m_H0434.AtkInterval);
 
        // 处理职业配置
        JobSetup = Config.Instance.Get<JobSetupConfig>(m_H0434.Job);
 
        // 处理装备
        H0434_tagAreaPlayerAppearEx.tagEquipInfo _equipInfo;
 
        // 因为衣服是所有装备的父节点, 需要预先处理衣服
        for (int i = 0; i < m_H0434.EquipCount; ++i)
        {
            _equipInfo = m_H0434.EquipInfo[i];
            if (_equipInfo.Place == (byte)RoleEquipType.retClothes)
            {
                m_SuitLevel = 0;
                if (_equipInfo.IsSuite == 1)
                {
                    Dictionary<int, List<int>> _userData = ConfigParse.Analysis(_equipInfo.UserData);
                    if (_userData.ContainsKey(30))
                    {
                        m_SuitLevel = (byte)_userData[30][0];
                    }
                }
 
                SwitchClothes(_equipInfo.ItemID);
 
                ChangeEquip(_equipInfo.Place, _equipInfo.ItemID, m_SuitLevel);
                break;
            }
        }
 
        // 如果没有任何衣服, 则穿上默认装备
        if (ClothesItemID == 0 || ClothesItemID == uint.MaxValue)
        {
            SwitchClothes(0);
        }
 
        // 处理其他装备
        for (int i = 0; i < m_H0434.EquipCount; ++i)
        {
            _equipInfo = m_H0434.EquipInfo[i];
            if (_equipInfo.Place == (int)RoleEquipType.retWeapon)
            {
                SwitchWeapon(_equipInfo.ItemID);
            }
            else if (_equipInfo.Place == (int)RoleEquipType.retWeapon2)
            {
                SwitchSecondary(_equipInfo.ItemID);
            }
            else if (_equipInfo.Place == (int)RoleEquipType.retWing)
            {
                SwitchWing(_equipInfo.ItemID);
            }
            else if (_equipInfo.Place == (int)RoleEquipType.retSpiritAnimal)
            {
                SwitchGuard(_equipInfo.ItemID);
                serverGuardId = (int)_equipInfo.ItemID;
            }
            else if (_equipInfo.Place == (int)RoleEquipType.mount)
            {
                ActorInfo.horseItemID = _equipInfo.ItemID;
            }
 
            m_SuitLevel = 0;
            if (_equipInfo.IsSuite == 1)
            {
                Dictionary<int, List<int>> _userData = ConfigParse.Analysis(_equipInfo.UserData);
                if (_userData.ContainsKey(30))
                {
                    m_SuitLevel = (byte)_userData[30][0];
                }
            }
 
            ChangeEquip(_equipInfo.Place, _equipInfo.ItemID, m_SuitLevel);
        }
 
        if (ActorInfo.horseItemID != 0 && m_H0434.PlayerState == 2)
        {
            OnHorse(1);
        }
 
        if (WeaponItemID == 0 || WeaponItemID == uint.MaxValue)
        {
            SwitchWeapon(0);
        }
 
        ActorInfo.LV = m_H0434.LV;
        ActorInfo.familyName = m_H0434.FamilyName;
        ActorInfo.ReincarnationLv = m_H0434.ReincarnationLv;
        ActorInfo.Job = m_H0434.Job;
        ActorInfo.realm = m_H0434.OfficialRank;
        ActorInfo.titleID = m_H0434.CurDienstgradID;
        ActorInfo.PlayerName = m_H0434.PlayerName;
        ActorInfo.teamID = m_H0434.TeamID;
        ActorInfo.familyID = m_H0434.FamilyID;
        ActorInfo.faction = m_H0434.Faction;
        ActorInfo.Hp = m_H0434.HP;
        ActorInfo.MaxHp = m_H0434.MaxHP;
 
        RequestName();
 
        m_CmdManager = new CmdManager();
    }
 
    protected sealed override void OnUnit()
    {
        ShowOrHideModel(true);
 
        StatusMgr.Instance.ReleaseActor(ServerInstID);
 
        StopMoveToPosition();
 
        m_CmdManager = null;
        m_H0434 = null;
 
        base.OnUnit();
    }
 
    public override void Destroy()
    {
    }
 
    protected override void OnUpdate()
    {
        base.OnUpdate();
 
        if (m_CmdManager != null)
        {
            m_CmdManager.Update();
        }
    }
 
    protected sealed override void OnLateUpdate()
    {
        base.OnLateUpdate();
 
        UpdateMove();
    }
 
    private bool m_StartMove;
    private Vector3 m_TargetPos;
    private bool m_MoveToFinalPos;
    private Vector3 _dir;
 
    public void MoveToPosition(Vector3 pos, float angle, float speed, bool startOrStop)
    {
        ActorInfo.moveSpeed = 500f / speed;
        m_StartMove = startOrStop;
        TryGetValidPos(pos, ref m_TargetPos);
        _dir = MathUtility.ForwardXZ(m_TargetPos, Pos);
 
        if (m_StartMove)
        {
            State = E_ActorState.AutoRun;
            Run();
        }
        else
        {
            m_MoveToFinalPos = true;
        }
    }
 
    public void StopMoveToPosition()
    {
        m_StartMove = false;
        m_MoveToFinalPos = false;
    }
 
    private void UpdateMove()
    {
        if (SkillMgr.CurCastSkill != null)
        {
            if (!SkillMgr.CurCastSkill.SkillCompelete)
            {
                return;
            }
 
            if (SkillMgr.DoingPrepareSkill)
            {
                return;
            }
 
            if (IsRushing)
            {
                return;
            }
        }
 
        if (m_StartMove)
        {
            //if (_dir != Vector3.zero)
            //{
            //    Quaternion _quaternion = Quaternion.LookRotation(_dir, Vector3.up);
            //    Rotation = Quaternion.RotateTowards(Rotation, _quaternion, GeneralConfig.Instance.RotateSpeed);
            //    destForward = _dir;
            //}
 
            //Vector3 _pos = Pos + ActorInfo.moveSpeed * _dir * Time.deltaTime;
            //if (TryGetValidPos(_pos, ref _pos))
            //{
            //    _pos.y = Pos.y;
            //    Pos = _pos;
            //}
            if (MathUtility.DistanceSqrtXZ(Pos, m_TargetPos) > 0.1f)
            {
                MoveToPosition(m_TargetPos);
            }
        }
        else if (m_MoveToFinalPos)
        {
            MoveToPosition(m_TargetPos);
 
            if (MathUtility.DistanceSqrtXZ(Pos, m_TargetPos) < 0.01f)
            {
                Pos = new Vector3(m_TargetPos.x, Pos.y, m_TargetPos.z);
                m_MoveToFinalPos = false;
                Idle();
                if (State == E_ActorState.AutoRun)
                {
                    State = E_ActorState.Idle;
                }
            }
        }
    }
 
    protected sealed override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
    }
 
    protected sealed override void OnPutonClothes(uint clothesItemID, GameObject clothed)
    {
        clothed.layer = LayerUtility.Player;
 
        SkinnedMeshRenderer _renderer = clothed.GetComponentInChildren<SkinnedMeshRenderer>();
        _renderer.gameObject.SetLayer(LayerUtility.Player, false);
        MaterialUtility.SwitchXrayShader(m_Material, false);
    }
 
    protected sealed override void OnPutonSecondary(uint secondaryItemID, GameObject secondary)
    {
        Renderer _renderer = secondary.GetComponent<Renderer>();
        if (_renderer)
        {
            _renderer.gameObject.SetLayer(LayerUtility.Player, false);
            MaterialUtility.SwitchXrayShader(m_SecondaryMaterial, false);
        }
    }
 
    protected sealed override void OnPutonWeapon(uint weaponItemID, GameObject weapon)
    {
        Renderer _renderer = weapon.GetComponent<Renderer>();
        if (_renderer)
        {
            _renderer.gameObject.SetLayer(LayerUtility.Player, false);
            MaterialUtility.SwitchXrayShader(m_WeaponMaterial, false);
        }
    }
 
    protected sealed override void OnPutonWing(uint wingItemID, GameObject wing)
    {
        SkinnedMeshRenderer _renderer = wing.GetComponentInChildren<SkinnedMeshRenderer>();
        _renderer.gameObject.SetLayer(LayerUtility.Player, true);
        MaterialUtility.SwitchXrayShader(m_WingMaterial, false);
    }
 
    protected sealed override void OnSwitchHorse(uint horseID, GameObject horse)
    {
        horse.layer = LayerUtility.Player;
 
        SkinnedMeshRenderer _renderer = horse.GetComponentInChildren<SkinnedMeshRenderer>();
        _renderer.gameObject.SetLayer(LayerUtility.Player, false);
        MaterialUtility.SwitchXrayShader(m_HorseMaterial, false);
    }
 
    public sealed override void OnHorse(byte upOrDown)
    {
        if (upOrDown == 1)
        {
            SwitchHorse(ActorInfo.horseItemID);
        }
        else
        {
            SwitchHorse(0);
        }
    }
 
    public sealed override void RequestName()
    {
        ReleaseName();
        if (MovingState == E_MovingState.Ride)
        {
            m_HeadUpName = HeadUpName.RequireHeadUpName(HeadUpName.Pattern.Player, MP_Name1, 0, CameraController.Instance.CameraObject);
        }
        else
        {
            m_HeadUpName = HeadUpName.RequireHeadUpName(HeadUpName.Pattern.Player, MP_Name, 0, CameraController.Instance.CameraObject);
        }
 
        m_HeadUpName.SetPlayerInfo((int)ActorInfo.realm, ActorInfo.titleID, ActorInfo.PlayerName, ActorInfo.familyName, m_H0434.State == 1);
 
        if (StatusMgr.Instance.IsExist(ServerInstID, StatusMgr.Instance.bossBelongBuffID))
        {
            m_HeadUpName.SetBossDropout(true);
        }
 
        base.SetFairyLeagueHeadUp(PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON);
    }
 
    public sealed override void SwitchRedName(bool on)
    {
        if (PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON)
        {
            return;
        }
        base.SwitchRedName(on);
    }
 
    public sealed override void SwitchYellowName(bool on)
    {
        if (PlayerDatas.Instance.baseData.MapID == FairyLeagueModel.FAIRY_LEAGUE_DUNGEON)
        {
            return;
        }
        base.SwitchYellowName(on);
    }
 
    public sealed override void RefreshLifeBar(ulong value)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        if (_hero != null && _hero.SelectTarget == this)
        {
            if (s_OnRefreshLife != null)
            {
                s_OnRefreshLife(ServerInstID, ActorInfo.RealHp, ActorInfo.RealMaxHp);
            }
        }
    }
 
    public sealed override bool CanAtked()
    {
        if (ActorInfo.serverDie)
        {
            return false;
        }
 
        if (PlayerDatas.Instance.maliciousAtkPlayer.Contains(ServerInstID))
        {
            return true;
        }
 
        if (StatusMgr.Instance.IsInvisible(ServerInstID))
        {
            return false;
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
 
        if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Peace)
        {
            return false;
        }
        else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.All)
        {
            return true;
        }
        else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Family)
        {
            // 判断队伍
            if (ActorInfo.teamID != 0
             && _hero.ActorInfo.teamID != 0
             && ActorInfo.teamID == _hero.ActorInfo.teamID)
            {
                return false;
            }
 
            // 判断阵营
            if (ActorInfo.faction != 0
             && _hero.ActorInfo.faction != 0
             && ActorInfo.faction == _hero.ActorInfo.faction)
            {
                return false;
            }
 
            // 判断仙盟
            if (ActorInfo.familyID != 0
             && _hero.ActorInfo.familyID != 0
             && ActorInfo.familyID == _hero.ActorInfo.familyID)
            {
                return false;
            }
 
            if (StatusMgr.Instance.IsExist(ServerInstID, StatusMgr.Instance.redNameBuffID))
            {
                return true;
            }
        }
        else if ((E_AttackMode)PlayerDatas.Instance.baseData.AttackMode == E_AttackMode.Country)
        {
            return false;
        }
 
        return true;
    }
 
    public override void Die()
    {
        base.Die();
        StopMoveToPosition();
    }
 
    public bool CanBeSelected()
    {
        if (ActorInfo.serverDie)
        {
            return false;
        }
 
        if (StatusMgr.Instance.IsInvisible(ServerInstID))
        {
            return false;
        }
 
        return true;
    }
 
    public void OnClick()
    {
        if (ActorInfo.serverDie)
        {
            return;
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
        if (_hero == null)
        {
            return;
        }
 
        _hero.LockTarget = this;
        _hero.SelectTarget = this;
    }
 
    public void OnSelect()
    {
        if (CanAtked())
        {
            SelectionManager.Request(SelectionManager.E_Type.Red, this);
        }
        else
        {
            SelectionManager.Request(SelectionManager.E_Type.Green, this);
        }
 
        if (s_OnSelected != null)
        {
            s_OnSelected(ServerInstID, true);
        }
    }
 
    public void OnUnSelect()
    {
        SelectionManager.Release(SelectionManager.E_Type.Green);
        SelectionManager.Release(SelectionManager.E_Type.Red);
 
        if (s_OnSelected != null)
        {
            s_OnSelected(ServerInstID, false);
        }
    }
 
    public void Cmd_0614(H0614_tagUseSkillPos h0614)
    {
        Cmd0614 _cmd = new Cmd0614();
        _cmd.Init(h0614);
        m_CmdManager.Enqueue(_cmd);
    }
 
    public void Cmd_B402(HB402_tagMCRush hb402)
    {
        CmdB402 _cmd = new CmdB402();
        _cmd.Init(hb402);
        m_CmdManager.Enqueue(_cmd);
    }
 
    public void Cmd_0501(H0501_tagObjMove h0501)
    {
        Cmd0501 _cmd = new Cmd0501();
        _cmd.Init(h0501);
        m_CmdManager.Enqueue(_cmd);
    }
 
    public void ClearAllCMD()
    {
        m_CmdManager.Clear();
    }
 
    public void UpdateOffLineAction()
    {
        if (!IsIdle())
        {
            return;
        }
 
        if (SelectTarget == null)
        {
            SelectTarget = GAMgr.Instance.GetCloserFightNpc(Pos);
        }
 
        if (SelectTarget != null)
        {
            destForward = Forward = MathUtility.ForwardXZ(SelectTarget.Pos, Pos);
        }
 
        Skill _castSkill = null;
        int _skillIndex = UnityEngine.Random.Range(0, JobSetup.HangupSkillList.Length);
        if (SkillMgr.Get(JobSetup.HangupSkillList[_skillIndex]).IsValid())
        {
            _castSkill = SkillMgr.Get(JobSetup.HangupSkillList[_skillIndex]);
        }
 
        if (_castSkill == null)
        {
            if (m_ComAtkIndex > JobSetup.ComAtkIdList.Length - 1)
            {
                m_ComAtkIndex = 0;
            }
            int _comSkillId = JobSetup.ComAtkIdList[m_ComAtkIndex];
            _castSkill = SkillMgr.Get(_comSkillId);
            m_ComAtkIndex += 1;
        }
 
        if (_castSkill != null)
        {
            SkillMgr.CastSkill(ServerInstID, _castSkill.id, true);
 
            Vector3 _targetPosition = Pos + Forward * (_castSkill.skillInfo.config.AtkDist * .5f);
            _targetPosition.y = 0;
            UnityEngine.AI.NavMeshHit _navMeshHit;
            if (UnityEngine.AI.NavMesh.Raycast(Pos, _targetPosition, out _navMeshHit, -1))
            {
                _targetPosition = _navMeshHit.position;
            }
            _targetPosition.y = Pos.y;
            _castSkill.targetPosition = _targetPosition;
 
            if (_castSkill.skillInfo.config.Skillactmark > 0
             && _castSkill.skillInfo.config.Skillactmark < 20)
            {
                switch (_castSkill.skillInfo.config.Skillactmark)
                {
                    case 10:
                        Play(GAStaticDefine.State_Attack1Hash, 0);
                        break;
                    case 11:
                        Play(GAStaticDefine.State_Attack2Hash, 0);
                        break;
                    case 12:
                        Play(GAStaticDefine.State_Attack3Hash, 0);
                        break;
                    case 13:
                        Play(GAStaticDefine.State_Attack4Hash, 0);
                        break;
                }
 
            }
            else
            {
                switch (_castSkill.skillInfo.config.Skillactmark)
                {
                    case 21:
                        Play(GAStaticDefine.State_Skill21, 0);
                        break;
                    case 22:
                        Play(GAStaticDefine.State_Skill22, 0);
                        break;
                    case 23:
                        Play(GAStaticDefine.State_Skill23, 0);
                        break;
                    case 24:
                        Play(GAStaticDefine.State_Skill24, 0);
                        break;
                    case 25:
                        Play(GAStaticDefine.State_Skill25, 0);
                        break;
                    case 26:
                        Play(GAStaticDefine.State_Skill26, 0);
                        break;
                    case 27:
                        Play(GAStaticDefine.State_Skill27, 0);
                        break;
                    case 28:
                        Play(GAStaticDefine.State_Skill28, 0);
                        break;
                    case 29:
                        Play(GAStaticDefine.State_Skill29, 0);
                        break;
                    case 99:
                        Play(GAStaticDefine.State_RollHash, 0);
                        break;
                }
            }
        }
    }
}