using BrewMonster; using CSNetwork.GPDataType; using CSNetwork.Protocols; using UnityEngine; public class CECNPCModelDefaultPolicy : CECNPCModelPolicy { CECModel m_pNPCModel; CECNPC m_pNPC; int m_nBrushes; A3DAABB m_CHAABB; // AABB Updated with m_ppBrushes // number of brush object used in collision public CECNPCModelDefaultPolicy(CECNPC pNPC) { m_pNPCModel = new CECModel(); m_pNPC = 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 PlayAttackAction(int nAttackSpeed, CECAttackEvent attackEvent) { int iAction = m_pNPC.IsMonsterOrPet() ? (int)NPCActionIndex.ACT_ATTACK1 + UnityEngine.Random.Range(0, 2) : (int)NPCActionIndex.ACT_NPC_ATTACK; if (!PlayModelAction(iAction, true, attackEvent)) { return false; } return true; } public override void StopChannelAction() { if (m_pNPCModel != null) { m_pNPCModel.StopChannelAction(0, true); } } public override bool GetCHAABB(ref A3DAABB aabb) { bool bRet = (false); if (HasCHAABB()) { aabb = m_CHAABB; // m_CHAABB ¸ù¾Ý͹°üÉϵĶ¥µãλÖÃÀ´¼ÆËã°üΧºÐ£¬¸ü׼ȷ²¢Óë͹°ü¼ì²â±£³ÖÒ»Ö // ²»ÄÜʹÓà GetPos() À´µ÷Õû m_CHAABB ºó×÷Ϊ¼ÆËã½á¹û·µ»Ø //aabb.Center = GetPos() + A3DVECTOR3(0.0f, m_CHAABB.Extents.y, 0.0f); //aabb.CompleteMinsMaxs(); bRet = true; } return bRet; } bool HasCHAABB() { return m_pNPCModel != null && m_pNPCModel.HasCHAABB() && m_nBrushes > 0; } public override bool PlayModelAction(int iAction, bool bRestart, CECAttackEvent cECAttackEvent) { /* 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, cECAttackEvent); } 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), cECAttackEvent, 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), cECAttackEvent); 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), cECAttackEvent); 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), cECAttackEvent); ; 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), cECAttackEvent); 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 { result = _npcVisual.TryPlayAction(GetActionName(iAction), cECAttackEvent); } 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; } public override void SetDefaultPickAABBExt(A3DVECTOR3 vExt) { } }