少年修仙传客户端代码仓库
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
using UnityEngine;
using H2Engine;
 
public class EventRefreshNPCHandler : IEventHandler
{
    private Evt_RefreshMonster m_Evt = null;
 
    private int m_DeadCount = 0;
    private float m_Duration = 0;
    private int m_RefreshCount = -1;
    private float m_RefreshInterval = 0;
 
    public int GetEventID()
    {
        if (m_Evt != null)
        {
            return m_Evt.id;
        }
        return -1;
    }
 
    public Evt.E_EventType GetEventType()
    {
        return Evt.E_EventType.Enemy;
    }
 
    public void Init(Evt evt)
    {
        m_Evt = evt as Evt_RefreshMonster;
        m_DeadCount = 0;
        m_Duration = 0;
        m_RefreshCount = -1;
        m_RefreshInterval = 0;
    }
 
    public void Update()
    {
        if (IsCompelete() && m_Duration > 0)
        {
            return;
        }
 
        m_Duration += Time.deltaTime;
 
        // 此模式下刷出第一只怪
        if (m_Evt.refreshType == Evt_RefreshMonster.E_RefreshType.OneByOnePrevDie)
        {
            if (m_RefreshCount == -1)
            {
                RefreshNpc();
            }
        }
        else if (m_Evt.refreshType == Evt_RefreshMonster.E_RefreshType.All)
        {
            RefreshAll();
        }
        else if (m_Evt.refreshType == Evt_RefreshMonster.E_RefreshType.OneByOneTime)
        {
            m_RefreshInterval += Time.deltaTime;
            if (m_RefreshInterval > m_Evt.refreshParam)
            {
                m_RefreshInterval = 0;
                RefreshNpc();
            }
        }
    }
 
    public void NpcDead(int npcID)
    {
        m_DeadCount += 1;
        // Debug.LogFormat("通知死亡: {0}, 当前计数: {1}", npcID, m_DeadCount);
        if (m_Evt.refreshType == Evt_RefreshMonster.E_RefreshType.OneByOnePrevDie)
        {
            RefreshNpc();
        }
 
        CA225_tagCMClientTaskCount _a225 = new CA225_tagCMClientTaskCount
        {
            CountID = (uint)npcID,
            Type = 1
        };
        GameNetSystem.Instance.SendInfo(_a225);
    }
 
    private void RefreshNpc()
    {
        m_RefreshCount += 1;
        if (m_RefreshCount >= 0 && m_RefreshCount < m_Evt.monsters.Length)
        {
            var _data = m_Evt.monsters[m_RefreshCount];
            var _npcConfig = NPCConfig.Get((int)_data.npcID);
            GActor _npc = null;
            if (_npcConfig.NPCType == (int)E_NpcType.Collect)
            {
                _npc = GAMgr.Instance.ReqClntNoFightNpc<GA_NpcClientCollect>(_data.npcID, E_ActorGroup.FuncNpc);
            }
            else
            {
                _npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>(_data.npcID, E_ActorGroup.Enemy);
            }
            _npc.BornPos = _npc.Pos = _data.position;
            _npc.belongEventID = m_Evt.id;
            if (_data.faceDir != 0)
            {
                _npc.EulerAngles = _data.faceDir;
            }
            ClientSceneManager.Instance.NpcBorn(m_Evt.id, _npc);
        }
    }
 
    private void RefreshAll()
    {
        if (m_RefreshCount < m_Evt.monsters.Length)
        {
            foreach (var _data in m_Evt.monsters)
            {
                var _npcConfig = NPCConfig.Get((int)_data.npcID);
                GActor _npc = null;
                if (_npcConfig.NPCType == (int)E_NpcType.Collect)
                {
                    _npc = GAMgr.Instance.ReqClntNoFightNpc<GA_NpcClientCollect>(_data.npcID, E_ActorGroup.FuncNpc);
                }
                else
                {
                    if (_npcConfig.IsBoss > 1)
                    {
                        _npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightBoss>(_data.npcID, E_ActorGroup.Enemy);
                    }
                    else
                    {
                        _npc = GAMgr.Instance.ReqClntFightNpc<GA_NpcClientFightNorm>(_data.npcID, E_ActorGroup.Enemy);
                    }
                }
                if (_npc != null)
                {
                    _npc.BornPos = _npc.Pos = _data.position;
                    _npc.belongEventID = m_Evt.id;
                    if (_data.faceDir != 0)
                    {
                        _npc.EulerAngles = _data.faceDir;
                    }
                    ClientSceneManager.Instance.NpcBorn(m_Evt.id, _npc);
                }
            }
            m_RefreshCount = m_Evt.monsters.Length;
        }
    }
 
    public void UnInit()
    {
        Debug.LogFormat("事件: {0} => UnInit()", m_Evt.id);
    }
 
    public bool IsCompelete()
    {
        if (m_Evt == null)
        {
            return true;
        }
 
        if (m_Evt.overCondition == Evt_RefreshMonster.E_OverCondition.DeadCount)
        {
            if (m_Evt.conditionParam <= 0)
            {
                return m_DeadCount >= m_Evt.monsters.Length;
            }
 
            return m_DeadCount >= m_Evt.conditionParam;
        }
        else if (m_Evt.overCondition == Evt_RefreshMonster.E_OverCondition.Time)
        {
            return m_Duration >= m_Evt.conditionParam && m_DeadCount >= m_Evt.monsters.Length;
        }
        return false;
    }
}