331 lines
8.8 KiB
C#
331 lines
8.8 KiB
C#
![]() |
// ***********************************************************************
|
|||
|
// Assembly : Game
|
|||
|
// Author : Kimch
|
|||
|
// Created : 2020-09-02
|
|||
|
// Description :
|
|||
|
// Last Modified By :
|
|||
|
// Last Modified On :
|
|||
|
// ***********************************************************************
|
|||
|
// <copyright file= "Stat_IdleAction" company="Kimch"></copyright>
|
|||
|
// <summary></summary>
|
|||
|
// ***********************************************************************
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
namespace G
|
|||
|
{
|
|||
|
public class Stat_StateManager : MonoBehaviour
|
|||
|
{
|
|||
|
private Dictionary<enStat, Stat_Base> m_actionStateMgr;
|
|||
|
|
|||
|
private Dictionary<enStat, Stat_Base> m_controlStateMgr;
|
|||
|
|
|||
|
private enStat m_preActionState;
|
|||
|
|
|||
|
private enStat m_curActionState;
|
|||
|
|
|||
|
private enStat m_curControlState = enStat.STAT_CONTROL;
|
|||
|
|
|||
|
private TimerManager m_timerMgr = new TimerManager();
|
|||
|
|
|||
|
private enStat m_nextStat;
|
|||
|
|
|||
|
public EntityCha m_char
|
|||
|
{
|
|||
|
get;
|
|||
|
set;
|
|||
|
}
|
|||
|
|
|||
|
public enStat NextStat => m_nextStat;
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
m_actionStateMgr = new Dictionary<enStat, Stat_Base>();
|
|||
|
m_controlStateMgr = new Dictionary<enStat, Stat_Base>();
|
|||
|
}
|
|||
|
|
|||
|
private void Start()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
private void Update()
|
|||
|
{
|
|||
|
if (m_actionStateMgr.ContainsKey(m_curActionState))
|
|||
|
{
|
|||
|
m_actionStateMgr[m_curActionState].Update();
|
|||
|
}
|
|||
|
if (m_controlStateMgr.ContainsKey(m_curControlState))
|
|||
|
{
|
|||
|
m_controlStateMgr[m_curControlState].Update();
|
|||
|
}
|
|||
|
m_timerMgr.Update();
|
|||
|
}
|
|||
|
|
|||
|
public void SetCharacter(EntityCha character)
|
|||
|
{
|
|||
|
m_char = character;
|
|||
|
}
|
|||
|
|
|||
|
public void ResetState()
|
|||
|
{
|
|||
|
SetCurActionState(enStat.STAT_ACTION_IDLE, null, true);
|
|||
|
}
|
|||
|
|
|||
|
public Stat_Base CreateStat(enStat stat)
|
|||
|
{
|
|||
|
switch (stat)
|
|||
|
{
|
|||
|
case enStat.STAT_ACTION_IDLE:
|
|||
|
return new Stat_IdleAction(this);
|
|||
|
case enStat.STAT_ACTION_ATK:
|
|||
|
return new Stat_AtkAction(this);
|
|||
|
case enStat.STAT_ACTION_SKILL:
|
|||
|
return new Stat_SkillAction(this);
|
|||
|
case enStat.STAT_ACTION_MOVE:
|
|||
|
return new Stat_MoveAction(this);
|
|||
|
case enStat.STAT_ACTION_ATK_MOVE:
|
|||
|
return new Stat_MoveAction(this);
|
|||
|
case enStat.STAT_ACTION_DODGE:
|
|||
|
return new Stat_DodegeAction(this);
|
|||
|
case enStat.STAT_ACTION_BORN:
|
|||
|
return new Stat_BornAction(this);
|
|||
|
case enStat.STAT_ACTION_DEAD:
|
|||
|
return new Stat_DeadAction(this);
|
|||
|
case enStat.STAT_ACTION_HIT:
|
|||
|
return new Stat_HitAction(this);
|
|||
|
//case enStat.STAT_ACTION_XULI_HIT:
|
|||
|
// return new Stat_XuLiHitAction(this);
|
|||
|
case enStat.STAT_ACTION_SHIELD:
|
|||
|
return new Stat_ShieldAction(this);
|
|||
|
case enStat.STAT_ACTION_RUN_AWAY:
|
|||
|
return new Stat_RunAwayAction(this);
|
|||
|
case enStat.STAT_ACTION_FOLLOW:
|
|||
|
return new Stat_FollowAction(this);
|
|||
|
case enStat.STAT_ACTION_CHARM:
|
|||
|
return new Stat_CharmAction(this);
|
|||
|
case enStat.STAT_ACTION_CHACKLES:
|
|||
|
return new Stat_ShacklesAction(this);
|
|||
|
//case enStat.STAT_ACTION_AVATAR:
|
|||
|
// return new Stat_AvatarAction(this);
|
|||
|
case enStat.STAT_ACTION_REVIVE:
|
|||
|
return new Stat_ReviveAction(this);
|
|||
|
case enStat.STAT_ACTION_COMMONANI:
|
|||
|
return new Stat_CommonAniAction(this);
|
|||
|
//case enStat.STAT_ACTION_GRABATK:
|
|||
|
// return new Stat_GrabAtkAction(this);
|
|||
|
case enStat.STAT_ACTION_SPRINT:
|
|||
|
return new Stat_SprintAction(this);
|
|||
|
case enStat.STAT_ACTION_SUPERSPRINT:
|
|||
|
return new Stat_SuperSprintAction(this);
|
|||
|
case enStat.STAT_ACTION_ANGER:
|
|||
|
return new Stat_AngerAction(this);
|
|||
|
//case enStat.STAT_ACTION_GRABED:
|
|||
|
// return new Stat_GrabedAction(this);
|
|||
|
case enStat.STAT_ACTION_JUMP_SKILL:
|
|||
|
return new Stat_JumpSkillAction(this);
|
|||
|
case enStat.STAT_ACTION_WHEEL_SKILL:
|
|||
|
return new Stat_WheelSkillAction(this);
|
|||
|
case enStat.STAT_ACTION_ROLL_SKILL:
|
|||
|
return new Stat_RollSkillAction(this);
|
|||
|
case enStat.STAT_ACTION_SPURT_SKILL:
|
|||
|
return new Stat_SpurtSkillAction(this);
|
|||
|
//case enStat.STAT_ACTION_ZHANGFEI2_SKILL:
|
|||
|
// return new Stat_Zhangfei2SkillAction(this);
|
|||
|
//case enStat.STAT_ACTION_LVBU3_SKILL:
|
|||
|
// return new Stat_Lvbu3SkillAction(this);
|
|||
|
//case enStat.STAT_ACTION_DIANWEI3_SKILL:
|
|||
|
// return new Stat_Dianwei3SkillAction(this);
|
|||
|
//case enStat.STAT_ACTION_XULI_SKILL:
|
|||
|
// return new Stat_XuLiSkillAction(this);
|
|||
|
case enStat.STAT_ACTION_GENERAL_CAST:
|
|||
|
return new Stat_GeneralCastAction(this);
|
|||
|
case enStat.STAT_ACTION_WALK:
|
|||
|
return new Stat_WalkAction(this);
|
|||
|
case enStat.STAT_ACTION_SHOCK:
|
|||
|
return new Stat_ShockAction(this);
|
|||
|
case enStat.STAT_ACTION_FREEZE:
|
|||
|
return new Stat_FreezeAction(this);
|
|||
|
case enStat.STAT_ACTION_DARKEN:
|
|||
|
return new Stat_DarkenAction(this);
|
|||
|
case enStat.STAT_ACTION_DASHATTACK:
|
|||
|
return new Stat_DashAttackAction(this);
|
|||
|
//case enStat.STAT_ACTION_ZHAOYUNER_AVATAR:
|
|||
|
// return new Stat_ZhaoyunAvatarAction(this);
|
|||
|
case enStat.STAT_CONTROL_AI:
|
|||
|
return new Stat_AIControl(this);
|
|||
|
case enStat.STAT_CONTROL_USER:
|
|||
|
return new Stat_UserControl(this);
|
|||
|
case enStat.STAT_CONTROL_CUTSCENES:
|
|||
|
return new Stat_CutscenesControl(this);
|
|||
|
default:
|
|||
|
Debug.LogError("stat is not have stat=" + stat);
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public enStat GetCurActionState()
|
|||
|
{
|
|||
|
return m_curActionState;
|
|||
|
}
|
|||
|
|
|||
|
public enStat GetCurControlState()
|
|||
|
{
|
|||
|
return m_curControlState;
|
|||
|
}
|
|||
|
|
|||
|
public void ProcessCurDelegate()
|
|||
|
{
|
|||
|
m_actionStateMgr[m_curActionState]?.ProcessDelegate();
|
|||
|
}
|
|||
|
|
|||
|
public bool CanCurActionStateTransition(enStat stat)
|
|||
|
{
|
|||
|
if (m_actionStateMgr.ContainsKey(m_curActionState))
|
|||
|
{
|
|||
|
return m_actionStateMgr[m_curActionState].CanTransition(stat);
|
|||
|
}
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool SetCurActionState(enStat stat, Dictionary<string, object> param = null, bool bForce = false, bool clearDelegates = false)
|
|||
|
{
|
|||
|
#pragma warning disable CS0219 // 变量“flag”已被赋值,但从未使用过它的值
|
|||
|
bool flag = true;
|
|||
|
#pragma warning restore CS0219 // 变量“flag”已被赋值,但从未使用过它的值
|
|||
|
m_nextStat = stat;
|
|||
|
if (m_actionStateMgr.ContainsKey(m_curActionState))
|
|||
|
{
|
|||
|
if (!bForce && !m_actionStateMgr[m_curActionState].CanTransition(stat))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
m_actionStateMgr[m_curActionState].Exit();
|
|||
|
}
|
|||
|
if (!m_actionStateMgr.ContainsKey(stat))
|
|||
|
{
|
|||
|
AddActionState(stat);
|
|||
|
}
|
|||
|
ClearTimer();
|
|||
|
if (m_curActionState != stat)
|
|||
|
{
|
|||
|
m_preActionState = m_curActionState;
|
|||
|
}
|
|||
|
m_curActionState = stat;
|
|||
|
if (!m_actionStateMgr[stat].Enter(param, clearDelegates))
|
|||
|
{
|
|||
|
m_actionStateMgr[m_curActionState].Exit();
|
|||
|
return false;
|
|||
|
}
|
|||
|
m_char.OnStateChange(stat, param);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool SetCurControlState(enStat stat, Dictionary<string, object> param = null)
|
|||
|
{
|
|||
|
if (m_controlStateMgr.ContainsKey(m_curControlState))
|
|||
|
{
|
|||
|
if (!m_controlStateMgr[m_curControlState].CanTransition(stat))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
m_controlStateMgr[m_curControlState].Exit();
|
|||
|
}
|
|||
|
if (!m_controlStateMgr.ContainsKey(stat))
|
|||
|
{
|
|||
|
AddControlState(stat);
|
|||
|
}
|
|||
|
m_curControlState = stat;
|
|||
|
m_controlStateMgr[stat].Enter(param);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public Stat_BaseControl GetStatControl(enStat stat)
|
|||
|
{
|
|||
|
if (m_controlStateMgr.ContainsKey(stat))
|
|||
|
{
|
|||
|
return (Stat_BaseControl)m_controlStateMgr[stat];
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
public bool SetControlStatDelegates(enStat stat, string key, StatDelegate del)
|
|||
|
{
|
|||
|
if (!m_controlStateMgr.ContainsKey(stat))
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
Dictionary<string, StatDelegate> delegateMgr = m_controlStateMgr[stat].m_delegateMgr;
|
|||
|
if (!delegateMgr.ContainsKey(key))
|
|||
|
{
|
|||
|
delegateMgr.Add(key, del);
|
|||
|
return true;
|
|||
|
}
|
|||
|
delegateMgr[key] = del;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public bool SetActionStatDelegates(enStat stat, string key, StatDelegate del = null)
|
|||
|
{
|
|||
|
if (!m_actionStateMgr.ContainsKey(stat))
|
|||
|
{
|
|||
|
AddActionState(stat);
|
|||
|
}
|
|||
|
Dictionary<string, StatDelegate> delegateMgr = m_actionStateMgr[stat].m_delegateMgr;
|
|||
|
if (!delegateMgr.ContainsKey(key))
|
|||
|
{
|
|||
|
delegateMgr.Add(key, del);
|
|||
|
return true;
|
|||
|
}
|
|||
|
delegateMgr[key] = del;
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private bool AddActionState(enStat e)
|
|||
|
{
|
|||
|
if (e <= enStat.STAT_ACTION || e >= enStat.STAT_ACTION_MAX)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (m_actionStateMgr.ContainsKey(e))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
Stat_Base value = CreateStat(e);
|
|||
|
m_actionStateMgr.Add(e, value);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
private bool AddControlState(enStat e)
|
|||
|
{
|
|||
|
if (e <= enStat.STAT_CONTROL || e >= enStat.STAT_CONTROL_MAX)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (m_controlStateMgr.ContainsKey(e))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
Stat_Base value = CreateStat(e);
|
|||
|
m_controlStateMgr.Add(e, value);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public Timer AddTimer(float delay, Timer.TimerCallFunc func, object[] param = null, bool _loop = false)
|
|||
|
{
|
|||
|
Timer timer = new Timer(delay, func, _loop, param);
|
|||
|
m_timerMgr.Add(timer);
|
|||
|
return timer;
|
|||
|
}
|
|||
|
|
|||
|
public bool RemoveTimer(Timer timer)
|
|||
|
{
|
|||
|
m_timerMgr.Remove(timer);
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
public void ClearTimer()
|
|||
|
{
|
|||
|
m_timerMgr.m_aryTimers.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|