少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 6d101512ba4cb8e37a98ace6320a0b70c96efa2b
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
using System;
using System.Collections.Generic;
using Snxxz.UI;
using UnityEngine;
using UnityEngine.Events;
 
public class GA_NpcClientCollect : GA_NpcClientFunc
{
    public static UnityAction<uint> OnCollectFinished;
    private static List<uint> m_ArrivedList = new List<uint>();
    public static event UnityAction<uint, int> OnArrive;
    public static event UnityAction<uint, int> OnLeave;
 
    private bool m_IsMainWinOpen = false;
 
    protected override void OnInit(GameNetPackBasic package)
    {
        base.OnInit(package);
 
        WindowCenter.Instance.windowAfterOpenEvent += CheckOpenCollectIcon;
        WindowCenter.Instance.windowAfterCloseEvent += AfterCloseMainWin;
 
        NPCInteractProcessor.s_NpcInteractEvent += HandleCallback;
    }
 
    private void HandleCallback(E_NpcType type, int npcID, uint sid)
    {
        if (sid == ServerInstID)
        {
            OnClick();
        }
    }
 
    protected override void OnUnit()
    {
        base.OnUnit();
 
        if (m_ArrivedList.Contains(ServerInstID))
        {
            m_ArrivedList.Remove(ServerInstID);
        }
 
        if (OnLeave != null)
        {
            OnLeave(ServerInstID, NpcConfig.NPCID);
        }
 
        WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon;
        WindowCenter.Instance.windowAfterCloseEvent -= AfterCloseMainWin;
    }
 
    private void CheckOpenCollectIcon(Window obj)
    {
        if (obj is MainInterfaceWin)
        {
            m_IsMainWinOpen = true;
 
            if (NpcConfig.NPCID != GeneralDefine.GatherSoulDZ)
            {
                GA_Hero _hero = PlayerDatas.Instance.hero;
 
                if (_hero != null)
                {
                    float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
 
                    if (_distSqrt < Mathf.Pow(NpcConfig.ModelRadius + 0.4f + GeneralDefine.CloseNpcDist, 2))
                    {
                        Arrive();
                    }
                }
            }
        }
    }
 
    private void AfterCloseMainWin(Window obj)
    {
        if (obj is MainInterfaceWin)
        {
            m_IsMainWinOpen = false;
            Leave();
        }
    }
 
    public override void OnClick()
    {
        if (GA_Hero.s_MapSwitching)
        {
            return;
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
 
        if (_hero == null)
        {
            return;
        }
 
        _hero.LockTarget = this;
        _hero.SelectTarget = this;
 
        float _chkDistSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
 
        // 这里判断是否要走向此对象
        if (_chkDistSqrt > 2f)
        {
            _hero.MoveToPosition(Pos, 1f);
        }
 
        if (_chkDistSqrt < 4)
        {
            var _model = ModelCenter.Instance.GetModel<HazyGrassModel>();
            if (_model.CanCollectClientNpc(NpcConfig.NPCID))
            {
                StartCollect();
            }
            else
            {
                _model.DisplayCollectErrorTip();
            }
        }
    }
 
    private bool m_StartCollect;
    private float m_CollectTime;
 
    public void StartCollect()
    {
        if (m_StartCollect)
        {
            return;
        }
        m_CollectTime = 0;
        NormalCollectWin.s_CollectInfo = new PrepareHandler.ClientH0812()
        {
            PlayerID = PlayerDatas.Instance.PlayerId,
            PrepareState = (byte)PrepareHandler.E_PrepareType.pstMissionCollecting,
            MaxTime = 2000,
            PrepareID = NpcConfig.NPCID,
        };
        PrepareHandler.Instance.isPreparing = true;
        WindowCenter.Instance.Open<NormalCollectWin>();
        m_StartCollect = true;
    }
 
    public void StopCollect()
    {
        PrepareHandler.Instance.isPreparing = false;
        WindowCenter.Instance.Close<NormalCollectWin>();
        m_StartCollect = false;
    }
 
    protected override void OnUpdate()
    {
        if (m_StartCollect)
        {
            GA_Hero m_Hero = PlayerDatas.Instance.hero;
 
            m_CollectTime += Time.deltaTime;
 
            if (m_CollectTime > 2f)
            {
                StopCollect();
 
                if (m_Hero != null)
                {
                    if (m_Hero.LockTarget == this)
                    {
                        m_Hero.LockTarget = null;
                    }
                    if (m_Hero.SelectTarget == this)
                    {
                        m_Hero.SelectTarget = null;
                    }
                }
 
                if (belongEventID != -1)
                {
                    ClientSceneManager.Instance.NpcDead(belongEventID, this, NpcConfig.NPCID);
                }
                else
                {
                    if (OnCollectFinished != null)
                    {
                        OnCollectFinished(ServerInstID);
                    }
                }
 
                GAMgr.Instance.Release(this);
            }
 
            if (!m_Hero.IsIdle() && !m_Hero.IsCollect())
            {
                StopCollect();
            }
        }
    }
 
    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()
    {
        base.OnUnSelect();
        if (OnLeave != null)
        {
            OnLeave(ServerInstID, NpcConfig.NPCID);
        }
    }
 
    protected override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
 
        if (!m_IsMainWinOpen)
        {
            m_IsMainWinOpen = WindowCenter.Instance.IsOpen<MainInterfaceWin>();
            return;
        }
 
        GA_Hero _hero = PlayerDatas.Instance.hero;
 
        if (_hero != null)
        {
            float _distSqrt = MathUtility.DistanceSqrtXZ(_hero.Pos, Pos);
 
            if (_distSqrt < Mathf.Pow(NpcConfig.ModelRadius + 0.4f + GeneralDefine.CloseNpcDist, 2))
            {
                Arrive();
            }
            else
            {
                if (m_ArrivedList.Contains(ServerInstID))
                {
                    if (OnLeave != null)
                    {
                        OnLeave(ServerInstID, NpcConfig.NPCID);
                    }
                    m_ArrivedList.Remove(ServerInstID);
                }
            }
        }
    }
 
    public void Arrive()
    {
        if (OnArrive != null)
        {
            OnArrive(ServerInstID, NpcConfig.NPCID);
        }
    }
 
    public void Leave()
    {
        if (OnLeave != null)
        {
            OnLeave(ServerInstID, NpcConfig.NPCID);
        }
    }
}