少年修仙传客户端代码仓库
leonard Wu
2018-08-03 c2d2d5d3a840bf50968b3f95e304929bc62a7b70
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
using UnityEngine;
using System.Collections;
using Snxxz.UI;
 
public class GA_NpcFightNorm : GActorNpcFight
{
    protected HeadUpName m_HeadUpName;
    protected LifeBar m_LifeBar;
 
    // 用于触发点击的组件
    private NPCInteractProcessor m_NPCInteractProcessor;
 
    protected override void OnInit(GameNetPackBasic package)
    {
        base.OnInit(package);
 
        // 可选择对象创建碰撞区
        if (CanBeSelected())
        {
            m_NPCInteractProcessor = Root.AddMissingComponent<NPCInteractProcessor>();
            m_NPCInteractProcessor.npcIntergactEvent += OnClick;
        }
 
        H0406_tagNPCAppear _h0406 = package as H0406_tagNPCAppear;
 
        if (_h0406 == null)
        {
            Debug.LogErrorFormat("Npc 执行初始化时, 传入的包错误...{0}", package.GetType());
        }
 
        ActorInfo.LV = _h0406.CurLV;
        ActorInfo.PlayerName = NpcConfig.charName;
        ActorInfo.faction = NpcConfig.Country;
        ActorInfo.Hp = _h0406.NPCHP;
        ActorInfo.HpEx = (ushort)_h0406.NPCHPEx;
        ActorInfo.MaxHp = _h0406.MaxHP;
        ActorInfo.MaxHpEx = (ushort)_h0406.MaxHPEx;
        ActorInfo.realm = (uint)NpcConfig.Realm;
 
        // 初始化移动速度
        ActorInfo.moveSpeed = 500f / _h0406.Speed;
        ActorInfo.serverBornPos = new Vector2(_h0406.PosX, _h0406.PosY);
 
        if (NpcConfig.NPCID == 32502001
         || NpcConfig.Dig == 1)// 针对守护笼子的临时骚操作
        {
            float _x = _h0406.PosX * .5f;
            float _z = _h0406.PosY * .5f;
            Pos = new Vector3(_x, PlayerDatas.Instance.hero.Pos.y, _z);
        }
        else
        {
            // 初始化坐标
            AdjustPos(_h0406.PosX, _h0406.PosY);
        }
 
        // 战斗类型的怪物随机朝向
        Rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
 
    }
 
    protected override void OnAfterInit()
    {
        if (NpcConfig.IsBoss < 2
         && SystemSetting.Instance.GetSystemSettingSwitch(SystemSwitch.HideMonster))
        {
            ShowOrHideModel(false);
        }
    }
 
    public override void OnClick()
    {
        if (ActorInfo.serverDie
         || BossShowModel.Instance.BossShowing
         || StatusMgr.Instance.IsInvisible(ServerInstID))
        {
            return;
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
 
        // 当前锁定的目标已经是此对象
        if (_hero.LockTarget == this)
        {
            // 开启攻击至死AI
            _hero.Behaviour.StartKillUntilDieAI();
        }
        else
        {
            // 设置锁定目标为此对象
            _hero.LockTarget = this;
            _hero.SelectTarget = this;
        }
    }
 
    protected override void OnUnit()
    {
        if (m_NPCInteractProcessor)
        {
            m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
            m_NPCInteractProcessor = null;
        }
 
        base.OnUnit();
    }
 
    protected override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
 
        if (!ActorInfo.serverDie)
        {
            UpdateTimeDialogueBubble();
        }
    }
 
    protected override void OnLateUpdate()
    {
    }
 
    protected override void OnUpdate()
    {
        base.OnUpdate();
    }
 
    public override void RequestLifeBar()
    {
        ReleaseLifeBar();
        m_LifeBar = LifeBar.RequireLifeBar(MP_Name, 0, CameraController.Instance.CameraObject);
        m_LifeBar.neverHide = true;
        m_LifeBar.Set(ActorInfo.RealHp, ActorInfo.RealMaxHp);
    }
 
    public override void RefreshLifeBar(uint value)
    {
        if (m_LifeBar)
        {
            m_LifeBar.Show(ActorInfo.RealHp, ActorInfo.RealMaxHp);
        }
    }
 
    public override void ReleaseLifeBar()
    {
        if (m_LifeBar != null)
        {
            m_LifeBar.target = null;
            m_LifeBar.neverHide = false;
            LifeBar.Recycle(m_LifeBar);
            m_LifeBar = null;
        }
    }
 
    public override void ReleaseName()
    {
        if (m_HeadUpName != null)
        {
            m_HeadUpName.target = null;
            HeadUpName.Recycle(m_HeadUpName);
            m_HeadUpName = null;
        }
    }
 
    public override void RequestName()
    {
        ReleaseName();
 
        HeadUpName.Pattern _pattern = HeadUpName.Pattern.Monster;
        m_HeadUpName = HeadUpName.RequireHeadUpName(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
        m_HeadUpName.SetMonsterInfo(NpcConfig.NPCID, ActorInfo.LV);
    }
 
    public override void RequestDialogueBubble()
    {
        if (m_DialogAppear)
        {
            NPCDialogueBubble.Recyle(m_DialogAppear);
        }
    }
 
    protected override void UpdateTimeDialogueBubble()
    {
        // 瞎BB逻辑
        if (Time.realtimeSinceStartup - m_LastTalkTime > 5)
        {
            if (m_DialogTiming != null)
            {
                NPCDialogueBubble.Recyle(m_DialogTiming);
            }
            m_DialogTiming = NPCDialogueBubble.TimingShow(NpcConfig.NPCID, MP_Name, CameraController.Instance.CameraObject);
            m_LastTalkTime = Time.realtimeSinceStartup;
        }
    }
 
    public override bool CanBeSelected()
    {
        return NpcConfig.NPCType != (int)E_NpcType.BreakableObj
            && NpcConfig.Country != 1
            && !StatusMgr.Instance.IsInvisible(ServerInstID)
            && NpcConfig.NPCType != (int)E_NpcType.Ghost;
    }
 
    public override void OnSelect()
    {
        SelectionManager.Request(SelectionManager.E_Type.Red, this, NpcConfig.ModelRadius * 2);
 
        RequestName();
        RequestLifeBar();
    }
 
    public override void OnUnSelect()
    {
        SelectionManager.Release(SelectionManager.E_Type.Red);
 
        if (!ActorInfo.serverDie)
        {
            ReleaseName();
            ReleaseLifeBar();
        }
    }
 
    public override bool CanPushedBack()
    {
        return NpcConfig.weight != 0
            && (IsHurt() || IsIdle());
    }
 
    public override bool CanHurted()
    {
        return NpcConfig.hurtFeedback == 1
            && (IsIdle() || IsRun() || IsHurt())
            && !SkillMgr.DoingPrepareSkill
            && (SkillMgr.CurCastSkill == null
             || SkillMgr.CurCastSkill.SkillCompelete);
    }
 
    public override bool CanDieFly()
    {
        return NpcConfig.NPCType != (int)E_NpcType.BreakableObj;
    }
 
    public override bool CanAtked()
    {
        // 判断是否相同阵营
        bool _sameFaction = NpcConfig.Country != 0
                         && NpcConfig.Country == PlayerDatas.Instance.baseData.faction;
 
        return !_sameFaction
            && NpcConfig.NPCType != (int)E_NpcType.Func
            && NpcConfig.NPCType != (int)E_NpcType.Collect
            && NpcConfig.NPCType != (int)E_NpcType.Pet
            && !ActorInfo.serverDie;
    }
 
    public override bool CanAtkedRotate()
    {
        return NpcConfig.NPCType != (int)E_NpcType.BreakableObj
            && NpcConfig.AIType != 201
            && NpcConfig.AIType != 49
            && NpcConfig.AIType != 50
            && !IsRun()
            && !SkillMgr.DoingPrepareSkill
            && (SkillMgr.CurCastSkill == null
             || SkillMgr.CurCastSkill.SkillCompelete)
            && (Time.time - m_LastCantAtkedTime > NpcConfig.AtkInterval * Constants.F_GAMMA + 1f);
    }
}