// *********************************************************************** // Assembly : Game // Author : Kimch // Created : 2020-09-02 // Description : // Last Modified By : // Last Modified On : // *********************************************************************** // // // *********************************************************************** using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace G { public class Stat_Base { protected EntityCha m_char; protected Stat_StateManager m_statMgr; protected ArrayList m_transitionList = new ArrayList(); public Dictionary m_delegateMgr; protected StatDelegate m_updateDelegate; protected StatDelegate m_exitDelegate; protected StatDelegate m_warningDelegate; public Stat_Base(Stat_StateManager statMgr) { m_delegateMgr = new Dictionary(); m_statMgr = statMgr; m_char = m_statMgr.m_char; } public void SetCharacter(EntityCha character) { m_char = character; } public bool SetCurActionState(enStat stat, Dictionary param = null, bool bForce = false, bool clearDelegates = false) { return m_statMgr.SetCurActionState(stat, param, bForce, clearDelegates); } public bool SetCurControlState(enStat stat) { return m_statMgr.SetCurControlState(stat); } public void AddTransition(enStat stat) { m_transitionList.Add(stat); } public void ProcessDelegate() { m_updateDelegate = UpdateDelegate; m_exitDelegate = ExitDelegate; m_warningDelegate = WarningDelegate; for (int i = 0; i < m_delegateMgr.Count; i++) { KeyValuePair keyValuePair = m_delegateMgr.ElementAt(i); switch (keyValuePair.Key) { case "update": m_updateDelegate = keyValuePair.Value; break; case "exit": m_exitDelegate = keyValuePair.Value; break; case "warning": m_warningDelegate = keyValuePair.Value; break; default: Debug.LogError("not have key = " + keyValuePair.Key); break; } } } public virtual bool Enter(Dictionary param, bool clearDelegates = false) { if (clearDelegates) { ClearDelegates(); } ParseParam(param); ProcessDelegate(); return true; } public bool Update() { if (m_updateDelegate != null) { return m_updateDelegate(); } return true; } public bool Warning() { if (m_warningDelegate != null) { return m_warningDelegate(); } return true; } public virtual bool Exit() { if (m_exitDelegate != null) { return m_exitDelegate(); } return true; } public virtual bool UpdateDelegate() { return true; } public virtual bool ExitDelegate() { return true; } public virtual bool WarningDelegate() { return true; } public virtual bool CanTransition(enStat stat) { return true; } public virtual void Transition(enStat stat) { } private void ParseParam(Dictionary param) { if (param != null) { if (param.ContainsKey("update")) { StatDelegate value = (StatDelegate)param["update"]; m_delegateMgr.Add("update", value); } if (param.ContainsKey("exit")) { StatDelegate value2 = (StatDelegate)param["exit"]; m_delegateMgr.Add("exit", value2); } if (param.ContainsKey("warning")) { StatDelegate value3 = (StatDelegate)param["warning"]; m_delegateMgr.Add("warning", value3); } } } public void ClearDelegates() { m_delegateMgr.Clear(); } } }