少年修仙传客户端代码仓库
hch
2025-03-03 28785d6ddf9c08e49527ede9405c7b6c93c6ed32
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
using UnityEngine;
using System.Collections.Generic;
 
 
public class RefreshNpcHandler
{
    private int NpcID;
    private Vector3 position;
    private bool randomPostion;
    private float randomDist;
    private Vector3 eulerAngles;
    private int count;
    private float refreshInterval;
    private int waveCount;
    private float waveInterval;
 
    private SoMap.E_TriggerType triggerType;
    private uint triggerID;
 
    private RefreshWaveProcess m_WaveProcess;
 
    private List<RefreshNpcProcess> m_WaveList = new List<RefreshNpcProcess>();
    private List<RefreshNpcProcess> m_RemoveList = new List<RefreshNpcProcess>();
 
    private bool m_Inited = false;
 
    public RefreshNpcHandler(SoMap.E_TriggerType type, uint id)
    {
        m_WaveProcess = new RefreshWaveProcess(this);
        triggerType = type;
        triggerID = id;
    }
 
    public void Init(SoMap.RefreshNPC data)
    {
        NpcID = data.NpcID;
        position = data.position;
        randomPostion = data.randomPostion;
        randomDist = data.randomDist;
        eulerAngles = data.eulerAngles;
        count = data.count;
        refreshInterval = data.refreshInterval;
        waveCount = data.waveCount;
        waveInterval = data.waveInterval;
        m_Inited = true;
    }
 
    public void Update()
    {
        if (!m_Inited)
        {
            return;
        }
 
        // 波更新
        if (!m_WaveProcess.IsOver())
        {
            m_WaveProcess.Update();
        }
 
        // 每波中的刷新更新
        m_RemoveList.Clear();
 
        for (int i = 0; i < m_WaveList.Count; ++i)
        {
            m_WaveList[i].Update();
 
            if (m_WaveList[i].IsOver())
            {
                m_RemoveList.Add(m_WaveList[i]);
            }
        }
 
        for (int i = 0; i < m_RemoveList.Count; ++i)
        {
            m_WaveList.Remove(m_RemoveList[i]);
        }
 
        m_RemoveList.Clear();
    }
 
    private void AddRefreshNpcProcess(RefreshNpcProcess process)
    {
        m_WaveList.Add(process);
    }
 
    private class RefreshWaveProcess
    {
        public float m_LastWaveStartTime;
 
        private int m_CurWaveCount;
        private RefreshNpcHandler m_Parent;
 
        public RefreshWaveProcess(RefreshNpcHandler parent)
        {
            m_Parent = parent;
        }
 
        public void Update()
        {
            if (m_Parent.waveCount - m_CurWaveCount > 0)
            {
                if (Time.time - m_LastWaveStartTime < m_Parent.waveInterval)
                {
                    return;
                }
 
                m_LastWaveStartTime = Time.time;
 
                RefreshNpcProcess _process = new RefreshNpcProcess(m_Parent);
                m_Parent.AddRefreshNpcProcess(_process);
 
                m_CurWaveCount += 1;
            }
        }
 
        public bool IsOver()
        {
            return m_Parent.waveCount == m_CurWaveCount;
        }
    }
 
    private class RefreshNpcProcess
    {
        private int m_CurRefreshCount;
        private float m_LastRefreshStartTime;
        RefreshNpcHandler m_Parent;
 
        public RefreshNpcProcess(RefreshNpcHandler parent)
        {
            m_Parent = parent;
        }
 
        public void Update()
        {
            if (m_Parent.refreshInterval == 0)
            {
                for (int i = 0; i < m_Parent.count; ++i)
                {
                    Refresh();
                }
            }
            else
            {
                if (m_Parent.count - m_CurRefreshCount > 0)
                {
                    if (Time.time - m_LastRefreshStartTime > m_Parent.refreshInterval)
                    {
                        Refresh();
                        m_LastRefreshStartTime = Time.time;
                    }
                }
            }
        }
 
        public bool IsOver()
        {
            return m_CurRefreshCount == m_Parent.count;
        }
 
        private void Refresh()
        {
            if (PreFightMission.Instance.needCreate1002 == false)
            {
                if (m_Parent.NpcID == 1002)
                {
                    return;
                }
            }
 
            NPCConfig _npcConfig = NPCConfig.Get(m_Parent.NpcID);
 
            GActorNpcFight _npcFight = null;
 
            if (_npcConfig.IsBoss > 1)
            {
                _npcFight = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>((uint)m_Parent.NpcID, E_ActorGroup.Enemy);
            }
            else
            {
                _npcFight = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>((uint)m_Parent.NpcID, E_ActorGroup.Enemy);
            }
 
            Vector3 _bornPosition = m_Parent.position;
 
            if (m_Parent.randomPostion)
            {
                _bornPosition = _bornPosition + Random.rotation * Vector3.forward * m_Parent.randomDist;
            }
 
            _npcFight.AdjustPos((ushort)(_bornPosition.x * 2), (ushort)(_bornPosition.z * 2), false);
            _npcFight.Root.eulerAngles = m_Parent.eulerAngles;
            _npcFight.Forward = _npcFight.Root.forward;
            _npcFight.BornPos = _npcFight.Pos;
            m_CurRefreshCount += 1;
 
            if (m_Parent.NpcID == 1000)
            {
                _npcFight.Play(GAStaticDefine.State_Open);
                SFXPlayUtility.Instance.PlayBattleEffect(1099, _npcFight.Pos, Vector3.forward);
            }
 
            if (m_Parent.triggerType == SoMap.E_TriggerType.Mission)
            {
                if (!PreFightMission.Instance.missionNpcDict[m_Parent.triggerID].Contains((int)_npcFight.ServerInstID))
                {
                    PreFightMission.Instance.missionNpcDict[m_Parent.triggerID].Add((int)_npcFight.ServerInstID);
                }
            }
        }
    }
}