少年修仙传客户端代码仓库
hch
2025-01-08 dbb7a55e47da81a8c7c2b4bff7e053ff36af3d5a
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
using System;
using System.Collections.Generic;
using vnxbqy.UI;
using UnityEngine;
using UnityEngine.Events;
 
public class ClientCollectUtility
{
    public static List<GA_NpcClientCollect> m_ArriveList = new List<GA_NpcClientCollect>();
 
    public static UnityAction<uint, int> OnShowCollectIcon;
    public static UnityAction<uint, int> OnHideCollectIcon;
    public static UnityAction<uint> OnCollectFinished;
 
    private static bool m_StartCollect;
    private static float m_CollectTime;
    private static uint m_CurrentSID;
    private static float m_CollectTotalTime;
 
    public static void StartCollect(GA_NpcClientCollect npc)
    {
        if (m_StartCollect)
        {
            if (m_CurrentSID != npc.ServerInstID)
            {
                StopCollect();
            }
            return;
        }
        m_CollectTime = 0;
        m_CurrentSID = npc.ServerInstID;
        m_CollectTotalTime = 2 * (1 - VipPrivilegeConfig.GetVipPrivilegeData(8, PlayerDatas.Instance.baseData.VIPLv) * Constants.F_DELTA);
        NormalCollectWin.s_CollectInfo = new PrepareHandler.ClientH0812()
        {
            PlayerID = PlayerDatas.Instance.PlayerId,
            PrepareState = (byte)PrepareHandler.E_PrepareType.pstMissionCollecting,
            MaxTime = m_CollectTotalTime * 1000,
            PrepareID = npc.NpcConfig.NPCID,
        };
        PrepareHandler.Instance.isPreparing = true;
        WindowCenter.Instance.Open<NormalCollectWin>();
        m_StartCollect = true;
        var _hero = PlayerDatas.Instance.hero;
        if (_hero != null && !_hero.ActorInfo.serverDie)
        {
            _hero.Collect();
        }
    }
 
    public static void StopCollect()
    {
        PrepareHandler.Instance.isPreparing = false;
        WindowCenter.Instance.Close<NormalCollectWin>();
        m_StartCollect = false;
        var _hero = PlayerDatas.Instance.hero;
        if (_hero != null && !_hero.ActorInfo.serverDie)
        {
            if (_hero.IsCollect() && _hero.NextAction == GAStaticDefine.Act_Collect)
            {
                _hero.IdleImmediate();
            }
        }
    }
 
    public static void Arrive(GA_NpcClientCollect npc)
    {
        if (!m_ArriveList.Contains(npc))
        {
            if (m_ArriveList.Count == 0)
            {
                if (OnShowCollectIcon != null)
                {
                    OnShowCollectIcon(npc.ServerInstID, npc.NpcConfig.NPCID);
                }
            }
 
            m_ArriveList.Add(npc);
        }
    }
 
    public static void Leave(GA_NpcClientCollect npc)
    {
        if (m_ArriveList.Contains(npc))
        {
            m_ArriveList.Remove(npc);
            if (m_ArriveList.Count == 0)
            {
                if (OnHideCollectIcon != null)
                {
                    OnHideCollectIcon(npc.ServerInstID, npc.NpcConfig.NPCID);
                }
            }
        }
    }
 
    public static void Init()
    {
        WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon;
        WindowCenter.Instance.windowAfterOpenEvent += CheckOpenCollectIcon;
        WindowCenter.Instance.windowAfterCloseEvent -= CheckCloseCollectIcon;
        WindowCenter.Instance.windowAfterCloseEvent += CheckCloseCollectIcon;
    }
 
    public static void HandleCallback(E_NpcType type, int npcID, uint sid)
    {
        var _hero = PlayerDatas.Instance.hero;
        if (_hero != null)
        {
            var _npc = _hero.SelectTarget as GA_NpcClientCollect;
            var _checkDis = 0f;
 
            if (_npc == null || !(_npc is GA_NpcClientCollect))
            {
                var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcClientCollect);
                if (_list != null)
                {
                    _list.Sort((a1, a2) =>
                    {
                        var _d1 = MathUtility.DistanceSqrtXZ(a1.Pos, _hero.Pos);
                        var _d2 = MathUtility.DistanceSqrtXZ(a2.Pos, _hero.Pos);
                        if (_d1 > _d2)
                        {
                            return 1;
                        }
                        else if (_d1 < _d2)
                        {
                            return -1;
                        }
                        return 0;
                    });
 
                    foreach (var _a in _list)
                    {
                        if (!(_a is GA_NpcClientCollect))
                        {
                            continue;
                        }
 
                        _npc = _a as GA_NpcClientCollect;
                        break;
                    }
                }
            }
 
            if (_npc != null)
            {
                if (_hero.SelectTarget == null || !(_hero.SelectTarget is GA_NpcClientCollect))
                {
                    _hero.SelectTarget = _npc;
                }
 
                _checkDis = MathUtility.DistanceSqrtXZ(_hero.Pos, _npc.Pos);
 
                if (_checkDis < 4f)
                {
                    if (OnShowCollectIcon != null)
                    {
                        OnShowCollectIcon(_npc.ServerInstID, _npc.NpcConfig.NPCID);
                    }
 
                    var _model = ModelCenter.Instance.GetModel<HazyGrassModel>();
                    if (_model.CanCollectClientNpc(_npc.NpcConfig.NPCID))
                    {
                        StartCollect(_npc);
                        var _dir = MathUtility.ForwardXZ(_npc.Pos, _hero.Pos);
                        _hero.Forward = _dir;
                    }
                    else
                    {
                        _model.DisplayCollectErrorTip();
                    }
                }
                else
                {
                    _hero.MoveToPosition(_npc.Pos, 1f);
                }
            }
        }
    }
 
    public static void UnInit()
    {
        WindowCenter.Instance.windowAfterOpenEvent -= CheckOpenCollectIcon;
        WindowCenter.Instance.windowAfterCloseEvent -= CheckCloseCollectIcon;
    }
 
    private static void CheckOpenCollectIcon(Window win)
    {
        GA_Hero _hero = PlayerDatas.Instance.hero;
        if (_hero == null)
        {
            return;
        }
 
        if (win is MainInterfaceWin)
        {
            if (m_ArriveList.Count > 0)
            {
                if (OnShowCollectIcon != null)
                {
                    var _collect = _hero.SelectTarget as GA_NpcClientCollect;
                    if (_collect == null)
                    {
                        _collect = m_ArriveList[0];
                    }
 
                    OnShowCollectIcon(_collect.ServerInstID, _collect.NpcConfig.NPCID);
                }
            }
        }
    }
 
    private static void CheckCloseCollectIcon(Window win)
    {
        if (win is MainInterfaceWin)
        {
            if (OnHideCollectIcon != null)
            {
                OnHideCollectIcon(0, 0);
            }
        }
    }
 
    public static void Update()
    {
        if (m_StartCollect)
        {
            GA_Hero _hero = PlayerDatas.Instance.hero;
 
            if (_hero.SkillMgr.CurCastSkill != null && !_hero.SkillMgr.CurCastSkill.SkillCompelete)
            {
                return;
            }
 
            m_CollectTime += Time.deltaTime;
 
            if (m_CollectTime > m_CollectTotalTime)
            {
                StopCollect();
 
                GA_NpcClientCollect _npc = null;
 
                if (m_CurrentSID > 0)
                {
                    _npc = GAMgr.Instance.GetBySID(m_CurrentSID) as GA_NpcClientCollect;
 
                    if (_npc != null)
                    {
                        if (_npc.belongEventID != -1)
                        {
                            ClientSceneManager.Instance.NpcDead(_npc.belongEventID, _npc, _npc.NpcConfig.NPCID);
                        }
 
                        if (_hero != null)
                        {
                            if (_hero.LockTarget == _npc)
                            {
                                _hero.LockTarget = null;
                            }
                            if (_hero.SelectTarget == _npc)
                            {
                                _hero.SelectTarget = null;
                            }
                        }
 
                        GAMgr.Instance.Release(_npc);
                    }
 
                    if (OnCollectFinished != null)
                    {
                        OnCollectFinished(m_CurrentSID);
                    }
 
                    if (DungeonStage.CurrentMapType == MapType.OpenCountry)
                    {
                        var _list = GAMgr.Instance.GetTypeList(E_ActorClassType.NpcClientCollect);
                        if (_list != null)
                        {
                            foreach (var _next in _list)
                            {
                                if (_next is GA_NpcClientCollect)
                                {
                                    var _collect = _next as GA_NpcClientCollect;
                                    MapTransferUtility.Instance.MoveToNPC(_collect.NpcConfig.NPCID);
                                }
                            }
                        }
                    }
                }
            }
 
            if (_hero.IsCollect())
            {
                if (!_hero.IsIdle() && !(_hero.NextAction == GAStaticDefine.Act_Collect))
                {
                    StopCollect();
                }
            }
 
            if (_hero.SelectTarget != null)
            {
                if (_hero.SelectTarget.ServerInstID != m_CurrentSID)
                {
                    StopCollect();
                }
            }
        }
    }
 
}