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(_data.npcID, E_ActorGroup.FuncNpc); } else { _npc = GAMgr.Instance.ReqClntFightNpc(_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(_data.npcID, E_ActorGroup.FuncNpc); } else { if (_npcConfig.IsBoss > 1) { _npc = GAMgr.Instance.ReqClntFightNpc(_data.npcID, E_ActorGroup.Enemy); } else { _npc = GAMgr.Instance.ReqClntFightNpc(_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; } }