少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-18 1868bc632a9134b6891d4fc5f427e3f280b9e973
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
using UnityEngine;
using TableConfig;
using Snxxz.UI;
using System.Collections.Generic;
using System.Collections;
 
public class GA_NpcFunc : GActorNpcNoFight
{
    protected HeadUpName m_HeadUpName;
    // 用于触发点击的组件
    protected NPCInteractProcessor m_NPCInteractProcessor;
    private H0406_tagNPCAppear m_H0406;
    private HeadUpQuestSign m_MissionSign;
 
    protected override void OnInit(GameNetPackBasic package)
    {
        m_H0406 = package as H0406_tagNPCAppear;
 
        if (m_H0406 == null)
        {
            Debug.LogErrorFormat("Npc 执行初始化时, 传入的包错误...{0}", package.GetType());
        }
 
        // 初始化坐标
        AdjustPos(m_H0406.PosX, m_H0406.PosY);
 
        ActorInfo.serverBornPos = new Vector2(m_H0406.PosX, m_H0406.PosY);
        ActorInfo.PlayerName = NpcConfig.charName;
 
        // 功能NPC需要读取配置朝向
        GAStaticDefine.NPCLocation _npcLocation;
        if (GAStaticDefine.TryGetMapNPCLocation(NpcConfig.NPCID, out _npcLocation))
        {
            Rotation = MathUtility.GetClientRotationFromAngle(_npcLocation.face);
        }
        else
        {
            Rotation = Quaternion.Euler(0, UnityEngine.Random.Range(0, 360), 0);
        }
 
        if (CanBeSelected())
        {
            m_NPCInteractProcessor = Root.AddMissingComponent<NPCInteractProcessor>();
            m_NPCInteractProcessor.npcIntergactEvent += OnClick;
        }
 
        GAStaticDefine.NpcID2ServerInstID[NpcConfig.NPCID] = ServerInstID;
 
        PlayerTaskDatas.Event_TaskResponse += OnTaskRefresh;
 
        RequestMissionSign();
 
        bool _needHide = (NpcConfig.Show == 0);
 
        PlayerTaskDatas _model = ModelCenter.Instance.GetModel<PlayerTaskDatas>();
        if (_model.NPCShowDic.ContainsKey(NpcConfig.NPCID)
         && _model.NPCShowDic[NpcConfig.NPCID] == 1)
        {
            _needHide = false;
        }
 
        if (_needHide)
        {
            Pos = Constants.Special_Hide_Position;
        }
    }
 
    protected override void OnUnit()
    {
        if (m_NPCInteractProcessor)
        {
            m_NPCInteractProcessor.npcIntergactEvent -= OnClick;
            Object.Destroy(m_NPCInteractProcessor);
            m_NPCInteractProcessor = null;
        }
        PlayerTaskDatas.Event_TaskResponse -= OnTaskRefresh;
        m_H0406 = null;
 
        ReleaseMissionSign();
 
        base.OnUnit();
    }
 
    protected virtual void OnTaskRefresh(int _nowNPCid, int _nPCLamp, Dictionary<int, int> _dic)
    {
        if (_nowNPCid == NpcConfig.NPCID)
        {
            RequestMissionSign();
        }
    }
 
    public override void OnClick()
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        _hero.LockTarget = this;
        _hero.SelectTarget = this;
 
        // 这里判断是否要走向此对象
        float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
        if (_distSqrt > Mathf.Pow(GeneralDefine.CloseNpcDist + NpcConfig.ModelRadius + 0.4f, 2))
        {
            MapTransferUtility.Instance.MoveToNPC(NpcConfig.NPCID, (int)ServerInstID);
        }
        else
        {
            if (NpcConfig.AutomaticFace == 1)
            {
                Vector3 _forward = MathUtility.ForwardXZ(_hero.Pos, Pos);
                Forward = _forward;
            }
            NPCInteractProcessor.InvokeEvent(E_NpcType.Func, NpcConfig.NPCID, ServerInstID);
        }
    }
 
    protected override void OnLateUpdate() { }
    protected override void OnFixedUpdate() { }
    protected override void OnUpdate() { }
 
    public sealed override void Die() { }
    public sealed override void Hurt() { }
    public sealed override void HurtDown() { }
 
    public sealed override void RequestLifeBar() { }
    public sealed override void ReleaseLifeBar() { }
 
    public override void RequestName()
    {
        ReleaseName();
 
        if (!MP_Name)
        {
            return;
        }
 
        HeadUpName.Pattern _pattern = HeadUpName.Pattern.FunctionNPC;
 
        var _bossInfoConfig = BossInfoConfig.GetBossInfoByStoneId(NpcConfig.NPCID);
        if (_bossInfoConfig != null)
        {
            _pattern = HeadUpName.Pattern.NpcReborn;
        }
 
        m_HeadUpName = HeadUpName.RequireHeadUpName(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
 
        if (_bossInfoConfig != null)
        {
            m_HeadUpName.SetNpcReborn(_bossInfoConfig.NPCID);
        }
        else
        {
            m_HeadUpName.SetNPCName(NpcConfig.NPCID);
        }
    }
 
    public sealed override void ReleaseName()
    {
        if (m_HeadUpName)
        {
            m_HeadUpName.target = null;
            HeadUpName.Recycle(m_HeadUpName);
            m_HeadUpName = null;
        }
    }
 
    PlayerTaskDatas m_TaskModel;
    PlayerTaskDatas taskmodel
    {
        get
        {
            return m_TaskModel ?? (m_TaskModel = ModelCenter.Instance.GetModel<PlayerTaskDatas>());
        }
    }
 
    public void RequestMissionSign()
    {
        ReleaseMissionSign();
        int _status = taskmodel.StatusLightQuery(NpcConfig.NPCID);
        if (_status >= 0)
        {
            HeadUpQuestSign.Pattern _pattern = (HeadUpQuestSign.Pattern)_status;
            m_MissionSign = HeadUpQuestSign.RequireHeadUpQuestSign(_pattern, MP_Name, 0, CameraController.Instance.CameraObject);
        }
    }
 
    public void ReleaseMissionSign()
    {
        if (m_MissionSign)
        {
            HeadUpQuestSign.Recycle(m_MissionSign);
            m_MissionSign = null;
        }
    }
 
    public override void OnSelect()
    {
        if (NpcConfig.NPCID != 10204200)
        {
            SelectionManager.Request(SelectionManager.E_Type.Green, this, NpcConfig.ModelRadius * 2);
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
        Vector3 _forward = MathUtility.ForwardXZ(Pos, _hero.Pos);
        _hero.Forward = _forward;
 
        if (NpcConfig.AutomaticFace == 1)
        {
            _forward = MathUtility.ForwardXZ(_hero.Pos, Pos);
            Forward = _forward;
        }
    }
 
    public override void OnUnSelect()
    {
        SelectionManager.Release(SelectionManager.E_Type.Green);
    }
 
    public override bool CanBeSelected()
    {
        return true;
    }
 
    private static Dictionary<int, bool> s_VisibleNpcFunc = new Dictionary<int, bool>();
 
    public static void SetNpcFuncVisible(int npcID, bool visible,
                                         float delayTime = 0,
                                         UnityEngine.Events.UnityAction<Vector3> callback1 = null,
                                         float timeBeforeDisappare = 0)
    {
        if (delayTime == 0)
        {
            SetNpcFuncVisibleFunc(npcID, visible);
        }
        else
        {
            SnxxzGame.Instance.StartCoroutine(DelaySetVisible(npcID, visible, delayTime, timeBeforeDisappare, callback1));
        }
    }
 
    private static IEnumerator DelaySetVisible(int npcID,
                                               bool visible,
                                               float delayTime,
                                               float timeCallback,
                                               UnityEngine.Events.UnityAction<Vector3> callback)
    {
        float _waitTime = delayTime - timeCallback;
 
        yield return new WaitForSeconds(timeCallback);
 
        GActor _disappearTarget = null;
 
        s_VisibleNpcFunc[npcID] = visible;
        List<GActor> _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.Collect);
        if (_actorList != null)
        {
            GActorNpcNoFight _target = null;
 
            for (int i = 0; i < _actorList.Count; ++i)
            {
                _target = _actorList[i] as GActorNpcNoFight;
 
                if (_target.NpcConfig.NPCID == npcID)
                {
                    if (visible)
                    {
                        _target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
                    }
                    else
                    {
                        if (callback != null)
                        {
                            callback(_target.Pos);
                        }
 
                        _disappearTarget = _target;
                    }
                }
            }
        }
 
        if (_disappearTarget == null)
        {
            _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
 
            if (_actorList != null)
            {
                GActorNpcNoFight _target = null;
 
                for (int i = 0; i < _actorList.Count; ++i)
                {
                    _target = _actorList[i] as GActorNpcNoFight;
 
                    if (_target.NpcConfig.NPCID == npcID)
                    {
                        if (visible)
                        {
                            _target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
                        }
                        else
                        {
                            if (callback != null)
                            {
                                callback(_target.Pos);
                            }
                            _disappearTarget = _target;
                        }
                        break;
                    }
                }
            }
        }
 
        if (_disappearTarget != null)
        {
            yield return new WaitForSeconds(_waitTime);
            _disappearTarget.Pos = Constants.Special_Hide_Position;
        }
 
    }
 
    private static void SetNpcFuncVisibleFunc(int npcID, bool visible)
    {
        s_VisibleNpcFunc[npcID] = visible;
        List<GActor> _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.Collect);
        if (_actorList != null)
        {
            GActorNpcNoFight _target = null;
 
            for (int i = 0; i < _actorList.Count; ++i)
            {
                _target = _actorList[i] as GActorNpcNoFight;
 
                if (_target.NpcConfig.NPCID == npcID)
                {
                    if (visible)
                    {
                        _target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
                    }
                    else
                    {
                        _target.Pos = Constants.Special_Hide_Position;
                    }
                    return;
                }
            }
        }
 
        _actorList = GAMgr.Instance.GetGroupList(E_ActorGroup.FuncNpc);
 
        if (_actorList != null)
        {
            GActorNpcNoFight _target = null;
 
            for (int i = 0; i < _actorList.Count; ++i)
            {
                _target = _actorList[i] as GActorNpcNoFight;
 
                if (_target.NpcConfig.NPCID == npcID)
                {
                    if (visible)
                    {
                        _target.AdjustPos((ushort)_target.ActorInfo.serverBornPos.x, (ushort)_target.ActorInfo.serverBornPos.y);
                    }
                    else
                    {
                        _target.Pos = Constants.Special_Hide_Position;
                    }
                    break;
                }
            }
        }
    }
}