using UnityEngine; using System.Collections.Generic; using TableConfig; 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 m_WaveList = new List(); private List m_RemoveList = new List(); 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 = Config.Instance.Get(m_Parent.NpcID); GActorNpcFight _npcFight = null; if (_npcConfig.IsBoss > 1) { _npcFight = GAMgr.Instance.ReqClntFightNpc((uint)m_Parent.NpcID, E_ActorGroup.Enemy); } else { _npcFight = GAMgr.Instance.ReqClntFightNpc((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); } } } } }