166 lines
5.8 KiB
C#
166 lines
5.8 KiB
C#
using BrewMonster;
|
|
using CSNetwork.Protocols;
|
|
using UnityEngine;
|
|
|
|
public class CECNPCModelDefaultPolicy
|
|
: CECNPCModelPolicy
|
|
{
|
|
CECModel m_pNPCModel;
|
|
|
|
public CECNPCModelDefaultPolicy(CECNPC pNPC)
|
|
{
|
|
|
|
}
|
|
|
|
public string GetActionName(int iAct, bool bAttackStart = false)
|
|
{
|
|
// Tạo builder thay cho static char[128]
|
|
var sb = new System.Text.StringBuilder();
|
|
|
|
// Thêm tên base action
|
|
sb.Append(CECNPC.GetBaseActionName(iAct));
|
|
|
|
// Nếu là attack action thì thêm hậu tố
|
|
if (CECNPC.IsAttackAction(iAct))
|
|
{
|
|
sb.Append(bAttackStart ? EC_Utility.FixGBKString("Æð") : EC_Utility.FixGBKString("Âä"));
|
|
}
|
|
|
|
// Xử lý loại bỏ dấu nháy kép (nếu có)
|
|
string result = sb.ToString().Replace("\"", "");
|
|
|
|
// Trả về kết quả đã clean
|
|
return result;
|
|
}
|
|
public override void ClearComActFlag(bool bSignalCurrent)
|
|
{
|
|
if (m_pNPCModel != null)
|
|
{
|
|
m_pNPCModel.ClearComActFlag(bSignalCurrent);
|
|
}
|
|
}
|
|
public override bool PlayModelAction(int iAction, bool bRestart)
|
|
{
|
|
|
|
/* if (m_pNPCModel == null)
|
|
{
|
|
return false;
|
|
}
|
|
*/
|
|
bool result = false;
|
|
bool ignoreRef = false;
|
|
|
|
if (iAction == (int)NPCActionIndex.ACT_WOUNDED)
|
|
{
|
|
string szAct = GetActionName(iAction);
|
|
if (!_npcVisual.IsAnimationExist(szAct))
|
|
{
|
|
szAct = GetActionName((int)NPCActionIndex.ACT_WOUNDED2);
|
|
}
|
|
result = _npcVisual.TryPlayAction(szAct);
|
|
}
|
|
else if (iAction == (int)NPCActionIndex.ACT_ATTACK1 || iAction == (int)NPCActionIndex.ACT_ATTACK2)
|
|
{
|
|
//bool bHideFX = !CECOptimize::Instance().GetGFX().CanShowAttack(m_pNPC->GetNPCID(), m_pNPC->GetClassID());
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction, true));
|
|
if (result)
|
|
{
|
|
string szAct = GetActionName(iAction, false);
|
|
string szAct2 = GetActionName((int)NPCActionIndex.ACT_GUARD);
|
|
|
|
if (!_npcVisual.IsAnimationExist(szAct))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct, ref ignoreRef, 0, 0, false, false, false);
|
|
}
|
|
if (!_npcVisual.IsAnimationExist(szAct2))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct2, ref ignoreRef, 300);
|
|
}
|
|
}
|
|
}
|
|
else if (iAction == (int)NPCActionIndex.ACT_IDLE)
|
|
{
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction));
|
|
if (result)
|
|
{
|
|
string szAct2 = GetActionName((int)NPCActionIndex.ACT_STAND);
|
|
if (!_npcVisual.IsAnimationExist(szAct2))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct2, ref ignoreRef, 300);
|
|
}
|
|
//m_pNPCModel->QueueAction(GetActionName((int)NPCActionIndex.ACT_STAND));
|
|
}
|
|
}
|
|
else if (iAction == (int)NPCActionIndex.ACT_NPC_IDLE1 || iAction == (int)NPCActionIndex.ACT_NPC_IDLE2)
|
|
{
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction));
|
|
if (result)
|
|
{
|
|
string szAct2 = GetActionName((int)NPCActionIndex.ACT_NPC_STAND);
|
|
if (!_npcVisual.IsAnimationExist(szAct2))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct2, ref ignoreRef, 300);
|
|
}
|
|
//m_pNPCModel->QueueAction(GetActionName((int)NPCActionIndex.ACT_NPC_STAND));
|
|
}
|
|
}
|
|
else if (iAction == (int)NPCActionIndex.ACT_NPC_ATTACK)
|
|
{
|
|
//bool bHideFX = !CECOptimize::Instance().GetGFX().CanShowAttack(m_pNPC->GetNPCID(), m_pNPC->GetClassID());
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction, true)); ;
|
|
if (result)
|
|
{
|
|
string szAct = GetActionName(iAction, false);
|
|
string szAct2 = GetActionName((int)NPCActionIndex.ACT_NPC_STAND);
|
|
if (!_npcVisual.IsAnimationExist(szAct))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct, ref ignoreRef, 0, 0, false, false, false);
|
|
}
|
|
if (!_npcVisual.IsAnimationExist(szAct2))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct2, ref ignoreRef, 300);
|
|
}
|
|
}
|
|
}
|
|
else if (iAction == (int)NPCActionIndex.ACT_COMMON_BORN)
|
|
{
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction));
|
|
if (result)
|
|
{
|
|
string szAct2 = GetActionName((int)NPCActionIndex.ACT_STAND);
|
|
if (!_npcVisual.IsAnimationExist(szAct2))
|
|
{
|
|
m_pNPCModel.QueueAction(_npcVisual.GetNPCINFO, szAct2, ref ignoreRef, 300);
|
|
}
|
|
//m_pNPCModel->QueueAction(GetActionName((int)NPCActionIndex.ACT_STAND));
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (iAction == (int)NPCActionIndex.ACT_DIE || iAction == (int)NPCActionIndex.ACT_NPC_DIE)
|
|
{
|
|
BMLogger.LogError(GetActionName(iAction));
|
|
}
|
|
result = _npcVisual.TryPlayAction(GetActionName(iAction));
|
|
}
|
|
return result;
|
|
}
|
|
public override bool IsPlayingAction()
|
|
{
|
|
return _npcVisual.IsPlayAnimation();
|
|
}
|
|
public override bool IsPlayingAction(int iAction)
|
|
{
|
|
return _npcVisual.IsPlayAnimation(GetActionName(iAction));
|
|
}
|
|
public override bool HasAction(int iAction)
|
|
{
|
|
return _npcVisual.IsAnimationExist(GetActionName(iAction));
|
|
}
|
|
public override void SetNpcVisual(NPCVisual npcVisual)
|
|
{
|
|
_npcVisual = npcVisual;
|
|
}
|
|
|
|
}
|