using BrewMonster.Assets.PerfectWorld.Scripts.Players; using UnityEngine; namespace BrewMonster { public class CECActionSwitcher : CECActionSwitcherBase { private System.Collections.Generic.List m_actionContexts = new System.Collections.Generic.List(); public CECActionSwitcher(CECHostPlayer pHost) : base(pHost) { } public void Tick(float deltaTime) { ProcessMessage(); // Convert DWORD to uint for milliseconds (Unity deltaTime is in seconds) uint dt = (uint)(deltaTime * 1000f); // Iterate backwards to safely remove items during iteration for (int i = m_actionContexts.Count - 1; i >= 0; i--) { CECActionContext pContext = m_actionContexts[i]; if (pContext != null) { /*pContext.Update(dt); if (pContext.NeedBeRemoved()) { // In C#, we just remove from list - GC handles cleanup m_actionContexts.RemoveAt(i); }*/ } else { m_actionContexts.RemoveAt(i); } } } public void ProcessMessage() { for (int i = 0; i < m_msgs.Count; i++) { EMsgActionSwitcher eMsg = (EMsgActionSwitcher)m_msgs[i]; switch (eMsg) { case EMsgActionSwitcher.MSG_FLY: { OnFly(); } break; case EMsgActionSwitcher.MSG_MOUNTPET: { OnRide(); } break; case EMsgActionSwitcher.MSG_CASTSKILL: { OnCastSkill(); } break; } } m_msgs.Clear(); } public void OnFly() { RemoveRideFlyRelatedContext(); } public void OnRide() { RemoveRideFlyRelatedContext(); } public void OnCastSkill() { RemoveRideFlyRelatedContext(); } public void RemoveRideFlyRelatedContext() { // Iterate backwards to safely remove items while iterating for (int i = m_actionContexts.Count - 1; i >= 0; i--) { CECActionContext context = m_actionContexts[i]; if (context != null) { bool isRelated = context.IsContext(ActionContextType.AC_FLYTORIDE) || context.IsContext(ActionContextType.AC_RIDETOSKILL) || context.IsContext(ActionContextType.AC_RIDETOFLY) || context.IsContext(ActionContextType.AC_RIDETOUSETARGETITEM); if (isRelated) { // In C#, we don't need explicit delete - GC will handle it // But if context implements IDisposable, call Dispose() here if (context is System.IDisposable disposable) { disposable.Dispose(); } m_actionContexts.RemoveAt(i); } } } } } }