From a4905d111f8cb0415efe44e25420ff40d7a33717 Mon Sep 17 00:00:00 2001 From: VDH Date: Wed, 19 Nov 2025 10:39:57 +0700 Subject: [PATCH] fix --- Assets/Scripts/CECHostPlayer.cs | 1127 +++++++++++++++---------------- 1 file changed, 556 insertions(+), 571 deletions(-) diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index 930d834b9b..1466c03fd1 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -62,30 +62,8 @@ namespace BrewMonster private List m_aEquipSkills = new List(); private List m_aGoblinSkills = new List(); - private bool m_bEnterGame; - public CECSkill m_pPrepSkill; - private float playerSpeed = 5.0f; - private float jumpHeight = 1.5f; - private float gravityValue = -9.81f; - private StateAnim stateAnim = StateAnim.Idle; - private Vector3 playerVelocity; - private bool isGrounded = false; - private bool isRun = false; - private Vector3 m_vLastSevPos; - public CDR_INFO m_CDRInfo; - public GNDINFO m_GndInfo; - private int m_idUCSelTarget; // Uncertificately selected object's ID - public float m_fVertSpeed = 0f; - int m_idSevNPC = 0; // Current service NPC - bool m_bTalkWithNPC = false; // true, is talking with NPC - List m_aWayPoints = new List(); // Active way points - bool m_bIsInKingService = false; // ÊÇ·ñÕýÔÚ½øÐйúÍõ·þÎñ²Ù×÷ - CECActionSwitcherBase m_pActionSwitcher; - private bool m_bSpellDSkill; private bool m_bEnterGame; public CECSkill m_pPrepSkill; - private CECSkill m_pCurSkill; - private CECCounter m_IncantCnt; private float playerSpeed = 5.0f; private float jumpHeight = 1.5f; private float gravityValue = -9.81f; @@ -98,7 +76,14 @@ namespace BrewMonster public GNDINFO m_GndInfo; private int m_idUCSelTarget; // Uncertificately selected object's ID public float m_fVertSpeed = 0f; + int m_idSevNPC = 0; // Current service NPC + bool m_bTalkWithNPC = false; // true, is talking with NPC + List m_aWayPoints = new List(); // Active way points + bool m_bIsInKingService = false; // ÊÇ·ñÕýÔÚ½øÐйúÍõ·þÎñ²Ù×÷ CECActionSwitcherBase m_pActionSwitcher; + private bool m_bSpellDSkill; + private CECSkill m_pCurSkill; + private CECCounter m_IncantCnt; // ====== Ground cast config ====== [Header("Ground Cast")] @@ -118,12 +103,12 @@ namespace BrewMonster [SerializeField] private float slopeToleranceDeg = 2f; - // cache tùy chọn (không bắt buộc) - float ccRadius, ccSkin; - RaycastHit lastGroundHit; - Camera mainCam; - Ray ray; - RaycastHit hit; + // cache tùy chọn (không bắt buộc) + float ccRadius, ccSkin; + RaycastHit lastGroundHit; + Camera mainCam; + Ray ray; + RaycastHit hit; private BaseVfxObject m_pSelectedGFX; private BaseVfxObject m_pHoverGFX; @@ -254,119 +239,119 @@ namespace BrewMonster int iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_NONE; bool bWikiMonster = false; - ray = mainCam.ScreenPointToRay(Input.mousePosition); + ray = mainCam.ScreenPointToRay(Input.mousePosition); - if (Physics.Raycast(ray, out hit)) - { - if (hit.collider.gameObject.TryGetComponent(out CECObject clickedObject)) + if (Physics.Raycast(ray, out hit)) { - int idObject = CECObject.GetObjectID(clickedObject); - if (idObject != 0) + if (hit.collider.gameObject.TryGetComponent(out CECObject clickedObject)) { - CECNPC pNPC = EC_ManMessageMono.Instance._CECNPCMan.GetNPC(idObject); - if (pNPC != null) + int idObject = CECObject.GetObjectID(clickedObject); + if (idObject != 0) { - if (!pNPC.IsDead() /* && m_idSelTarget == idObject*/) + CECNPC pNPC = EC_ManMessageMono.Instance._CECNPCMan.GetNPC(idObject); + if (pNPC != null) { - idTraceTarget = idObject; - idSelTarget = idObject; - } - - if (idTraceTarget != 0) - { - if (AttackableJudge(idObject, bForceAttack) == 1) - iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_ATTACK; - else if (pNPC.IsServerNPC()) + if (!pNPC.IsDead() /* && m_idSelTarget == idObject*/) { - if (!IsInBattle() || InSameBattleCamp(pNPC)) - iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_TALK; + idTraceTarget = idObject; + idSelTarget = idObject; } - } - } - else - { - // pCDS.m_RayTraceRt.iEntity == ECENT_PLAYER - CECPlayer pPlayer = EC_ManMessageMono.Instance.EC_ManPlayer.GetPlayer(idObject); - // 1. Msg.dwParam4 is double click flag. - // 2. Buddy player counld't be traced - if (!pPlayer.IsDead() /*&& pPlayer.GetCharacterID() != m_iBuddyId*/ && - (m_idSelTarget == idObject /*|| (Msg.dwParam4 && m_idUCSelTarget == idObject)*/)) - { - idTraceTarget = idObject; - //bForceAttack = glb_GetForceAttackFlag(&Msg.dwParam3); - - if (AttackableJudge(idObject, bForceAttack) == 1) - iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_ATTACK; - else if (pPlayer.GetBoothState() != 0) - iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_TALK; + if (idTraceTarget != 0) + { + if (AttackableJudge(idObject, bForceAttack) == 1) + iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_ATTACK; + else if (pNPC.IsServerNPC()) + { + if (!IsInBattle() || InSameBattleCamp(pNPC)) + iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_TALK; + } + } } else { - idSelTarget = idObject; + // pCDS.m_RayTraceRt.iEntity == ECENT_PLAYER + CECPlayer pPlayer = EC_ManMessageMono.Instance.EC_ManPlayer.GetPlayer(idObject); + + // 1. Msg.dwParam4 is double click flag. + // 2. Buddy player counld't be traced + if (!pPlayer.IsDead() /*&& pPlayer.GetCharacterID() != m_iBuddyId*/ && + (m_idSelTarget == idObject /*|| (Msg.dwParam4 && m_idUCSelTarget == idObject)*/)) + { + idTraceTarget = idObject; + //bForceAttack = glb_GetForceAttackFlag(&Msg.dwParam3); + + if (AttackableJudge(idObject, bForceAttack) == 1) + iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_ATTACK; + else if (pPlayer.GetBoothState() != 0) + iTraceReason = CECHPWorkTrace.Trace_reason.TRACE_TALK; + } + else + { + idSelTarget = idObject; + } + } + + // cancel this action if not selectable + if (!CanSelectTarget(idTraceTarget)) + { + idTraceTarget = 0; + //return; } } + } + } - // cancel this action if not selectable - if (!CanSelectTarget(idTraceTarget)) + // Tell server we select a target + if (idSelTarget != 0 && m_idSelTarget != idSelTarget) + { + m_idUCSelTarget = idSelTarget; + SelectTarget(m_idUCSelTarget); + } + + if (idTraceTarget != 0) + { + if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_ATTACK) + { + if (!CanDo(ActionCanDo.CANDO_MELEE)) + return; + NormalAttackObject(idTraceTarget, bForceAttack); + } + else + { + if (!CanDo(ActionCanDo.CANDO_MOVETO)) + return; + CECHPWork pWork; + if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_PICKUP) { - idTraceTarget = 0; - //return; + //PickupObject(idTraceTarget, false); + } + else if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_GATHER) + { + //PickupObject(idTraceTarget, true); + } + else if ((pWork = m_pWorkMan.GetWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT)) != null) + { + CECHPWorkTrace pWorkTrace = (pWork) as CECHPWorkTrace; + pWorkTrace.SetTraceTarget(pWorkTrace.CreatTraceTarget(idTraceTarget, iTraceReason, bForceAttack)); + } + else if (m_pWorkMan.CanStartWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT) && !bWikiMonster) + { + CECHPWorkTrace pWorkTrace = (CECHPWorkTrace)m_pWorkMan.CreateWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT); + pWorkTrace.SetTraceTarget(pWorkTrace.CreatTraceTarget(idTraceTarget, iTraceReason, bForceAttack)); + m_pWorkMan.StartWork_p1(pWorkTrace); } } } } + m_pWorkMan?.Tick(Time.deltaTime); - // Tell server we select a target - if (idSelTarget != 0 && m_idSelTarget != idSelTarget) - { - m_idUCSelTarget = idSelTarget; - SelectTarget(m_idUCSelTarget); - } + // Update cursor based on what's under mouse + EstimateCursor(); - if (idTraceTarget != 0) - { - if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_ATTACK) - { - if (!CanDo(ActionCanDo.CANDO_MELEE)) - return; - NormalAttackObject(idTraceTarget, bForceAttack); - } - else - { - if (!CanDo(ActionCanDo.CANDO_MOVETO)) - return; - CECHPWork pWork; - if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_PICKUP) - { - //PickupObject(idTraceTarget, false); - } - else if (iTraceReason == CECHPWorkTrace.Trace_reason.TRACE_GATHER) - { - //PickupObject(idTraceTarget, true); - } - else if ((pWork = m_pWorkMan.GetWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT)) != null) - { - CECHPWorkTrace pWorkTrace = (pWork) as CECHPWorkTrace; - pWorkTrace.SetTraceTarget(pWorkTrace.CreatTraceTarget(idTraceTarget, iTraceReason, bForceAttack)); - } - else if (m_pWorkMan.CanStartWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT) && !bWikiMonster) - { - CECHPWorkTrace pWorkTrace = (CECHPWorkTrace)m_pWorkMan.CreateWork(CECHPWork.Host_work_ID.WORK_TRACEOBJECT); - pWorkTrace.SetTraceTarget(pWorkTrace.CreatTraceTarget(idTraceTarget, iTraceReason, bForceAttack)); - m_pWorkMan.StartWork_p1(pWorkTrace); - } - } - } + // Update GFXs + UpdateGFXs(Time.deltaTime); } - m_pWorkMan?.Tick(Time.deltaTime); - - // Update cursor based on what's under mouse - EstimateCursor(); - - // Update GFXs - UpdateGFXs(Time.deltaTime); - } public void StopMovement() { @@ -1103,10 +1088,10 @@ namespace BrewMonster //CECAutoPolicy::GetInstance().SendEvent_BeHurt(pCmd.idAttacker); } - public void OnMsgHstAttackResult(ECMSG Msg) - { - byte[] data = Msg.dwParam1 as byte[]; - cmd_host_attack_result pCmd = EC_Utility.ByteArrayToStructure(data); + public void OnMsgHstAttackResult(ECMSG Msg) + { + byte[] data = Msg.dwParam1 as byte[]; + cmd_host_attack_result pCmd = EC_Utility.ByteArrayToStructure(data); int iAttackTime = 0; TurnFaceTo(pCmd.idTarget); @@ -1507,95 +1492,95 @@ namespace BrewMonster cmd_notify_hostpos pCmd = GPDataTypeHelper.FromBytes(buf); SetPos(new Vector3(pCmd.vPos.x, pCmd.vPos.y, pCmd.vPos.z)); - } - - private void OnMsgHstStartAttack(in ECMSG Msg) - { -// cmd_host_start_attack pCmd = (cmd_host_start_attack*)Msg.dwParam1; -// ASSERT(pCmd); -// -// // test code... -// // g_pGame->GetRTDebug()->OutputNotifyMessage(RTDCOL_WARNING, _AL("start attack !")); -// -// // Check whether target is the one that we have selected -// if (m_idSelTarget != pCmd->idTarget) -// g_pGame->RuntimeDebugInfo(RTDCOL_WARNING, _AL("Target has changed !")); -// -// // If target turn to be un-attackable, cancel action -// if (!AttackableJudge(pCmd->idTarget, true)) -// { -// g_pGame->GetGameSession()->c2s_CmdCancelAction(); -// g_pGame->RuntimeDebugInfo(RTDCOL_WARNING, _AL("Cannel attacking !")); -// return; -// } -// -// // Synchronize ammo amount -// CECIvtrItem* pItem = m_pEquipPack->GetItem(EQUIPIVTR_PROJECTILE); -// if (pItem) -// { -// if (!pCmd->ammo_remain) -// m_pEquipPack->SetItem(EQUIPIVTR_PROJECTILE, NULL); -// else -// pItem->SetAmount(pCmd->ammo_remain); -// } -// -// CECHPWorkMelee* pWork = (CECHPWorkMelee*)m_pWorkMan->CreateWork(CECHPWork::WORK_HACKOBJECT); -// m_pWorkMan->StartWork_p1(pWork); -// -// m_bMelee = true; -// AP_ActionEvent(AP_EVENT_STARTMELEE); - } - - private void OnMsgHstStopAttack(in ECMSG Msg) - { -// using namespace S2C; -// - // m_bMelee = false; -// -// // if there is an attack event currently, we should let it fire now. - ClearComActFlagAllRankNodes(true); - - cmd_host_stop_attack pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); - // ASSERT(pCmd); + } - /* If attack stopped for target is leave too far, trace it and continue - attacking. Stop reason defined as below: + private void OnMsgHstStartAttack(in ECMSG Msg) + { + // cmd_host_start_attack pCmd = (cmd_host_start_attack*)Msg.dwParam1; + // ASSERT(pCmd); + // + // // test code... + // // g_pGame->GetRTDebug()->OutputNotifyMessage(RTDCOL_WARNING, _AL("start attack !")); + // + // // Check whether target is the one that we have selected + // if (m_idSelTarget != pCmd->idTarget) + // g_pGame->RuntimeDebugInfo(RTDCOL_WARNING, _AL("Target has changed !")); + // + // // If target turn to be un-attackable, cancel action + // if (!AttackableJudge(pCmd->idTarget, true)) + // { + // g_pGame->GetGameSession()->c2s_CmdCancelAction(); + // g_pGame->RuntimeDebugInfo(RTDCOL_WARNING, _AL("Cannel attacking !")); + // return; + // } + // + // // Synchronize ammo amount + // CECIvtrItem* pItem = m_pEquipPack->GetItem(EQUIPIVTR_PROJECTILE); + // if (pItem) + // { + // if (!pCmd->ammo_remain) + // m_pEquipPack->SetItem(EQUIPIVTR_PROJECTILE, NULL); + // else + // pItem->SetAmount(pCmd->ammo_remain); + // } + // + // CECHPWorkMelee* pWork = (CECHPWorkMelee*)m_pWorkMan->CreateWork(CECHPWork::WORK_HACKOBJECT); + // m_pWorkMan->StartWork_p1(pWork); + // + // m_bMelee = true; + // AP_ActionEvent(AP_EVENT_STARTMELEE); + } - 0x00: attack is canceled or host want to do some other things. - 0x01: unable to attack anymore (no ammo, weapon is broken etc.) - 0x02: invalid target (target missed or died) - 0x04: target is out of range - */ - if ((pCmd.iReason & 0x04) !=0) - { - if (!m_pWorkMan.IsMovingToPosition() && - !m_pWorkMan.IsTracing()) - { - if (CmdNormalAttack(false, false, 0, -1)) //m_pComboSkill != NULL - { - // AP_ActionEvent(AP_EVENT_MELEEOUTOFRANGE, 1); - } - else - { - m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_HACKOBJECT); - // AP_ActionEvent(AP_EVENT_STOPMELEE); - } - } - else - { - // AP_ActionEvent(AP_EVENT_STOPMELEE); - } - } - else - { - m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_HACKOBJECT); - // AP_ActionEvent(AP_EVENT_STOPMELEE); - } + private void OnMsgHstStopAttack(in ECMSG Msg) + { + // using namespace S2C; + // + // m_bMelee = false; + // + // // if there is an attack event currently, we should let it fire now. + ClearComActFlagAllRankNodes(true); -// #ifdef _SHOW_AUTOPOLICY_DEBUG -// a_LogOutput(1, "Stop Attack, Reason = %d", pCmd->iReason); -// #endif - } + cmd_host_stop_attack pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); + // ASSERT(pCmd); + + /* If attack stopped for target is leave too far, trace it and continue + attacking. Stop reason defined as below: + + 0x00: attack is canceled or host want to do some other things. + 0x01: unable to attack anymore (no ammo, weapon is broken etc.) + 0x02: invalid target (target missed or died) + 0x04: target is out of range + */ + if ((pCmd.iReason & 0x04) != 0) + { + if (!m_pWorkMan.IsMovingToPosition() && + !m_pWorkMan.IsTracing()) + { + if (CmdNormalAttack(false, false, 0, -1)) //m_pComboSkill != NULL + { + // AP_ActionEvent(AP_EVENT_MELEEOUTOFRANGE, 1); + } + else + { + m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_HACKOBJECT); + // AP_ActionEvent(AP_EVENT_STOPMELEE); + } + } + else + { + // AP_ActionEvent(AP_EVENT_STOPMELEE); + } + } + else + { + m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_HACKOBJECT); + // AP_ActionEvent(AP_EVENT_STOPMELEE); + } + + // #ifdef _SHOW_AUTOPOLICY_DEBUG + // a_LogOutput(1, "Stop Attack, Reason = %d", pCmd->iReason); + // #endif + } // Message MSG_HST_SELTARGET handler void OnMsgHstSelTarget(ECMSG Msg) @@ -1849,9 +1834,9 @@ namespace BrewMonster { CECNPC pNPC = (CECNPC)pObject; - // If this npc is host's pet, cannot be attacked - if (pNPC.GetMasterID() == m_PlayerInfo.cid) - return 0; + // If this npc is host's pet, cannot be attacked + if (pNPC.GetMasterID() == m_PlayerInfo.cid) + return 0; // If it's a pet and can not be attacked, pet can be attacked only if it's a fighting pet //if (pNPC.IsPetNPC() && !((CECPet)pNPC).CanBeAttacked()) @@ -2232,21 +2217,21 @@ namespace BrewMonster return (m_dwLIES & mask) != 0; } - public bool IsInFortress() - { - return m_fortressEnter.role_in_war != 0; - } + public bool IsInFortress() + { + return m_fortressEnter.role_in_war != 0; + } bool IsPVPOpen() { return m_pvp.bEnable; } - // Get faction ID - public int GetFactionID() - { - return m_idFaction; - } + // Get faction ID + public int GetFactionID() + { + return m_idFaction; + } public bool IsJumping() { @@ -2882,11 +2867,11 @@ namespace BrewMonster //case ActionCanDo.CANDO_FLASHMOVE: - // if (IsDead() || IsAboutToDie() || IsTrading() || IsUsingTrashBox() || IsTalkingWithNPC() || - // IsJumping() || IsFlashMoving() || IsFalling() || IsChangingFace() || GetBoothState() != 0 || IsTakingOff() || - // m_pWorkMan.HasWorkRunningOnPriority(CECHPWorkMan::PRIORITY_2) || - // m_iBuddyId || IsOperatingPet() || IsRebuildingPet() || IsUsingItem() || IsPassiveMove()) - // bRet = false; + // if (IsDead() || IsAboutToDie() || IsTrading() || IsUsingTrashBox() || IsTalkingWithNPC() || + // IsJumping() || IsFlashMoving() || IsFalling() || IsChangingFace() || GetBoothState() != 0 || IsTakingOff() || + // m_pWorkMan.HasWorkRunningOnPriority(CECHPWorkMan::PRIORITY_2) || + // m_iBuddyId || IsOperatingPet() || IsRebuildingPet() || IsUsingItem() || IsPassiveMove()) + // bRet = false; // break; @@ -2972,211 +2957,211 @@ namespace BrewMonster // float fBorderLine = fWaterHeight - 2.0f; // if (vPos.y <= fBorderLine) break; - // // ·þÎñÆ÷¶Ë½«Ë®ÃæÒÔÏÂ2Ã×ÒÔÉÏ´¦ÀíΪ run_speed£¨ÓÐÎÊÌ⣩ - // // µ«Î´Ê¹ÓüÓËÙ¼¼ÄÜʱ swim_speed СÓÚ run_speed£¬ - // // ¿ÉÒÔÔÚË®ÃæÒÔÏÂ2Ã×ÒÔÉÏ»ñÈ¡³¬¹ý swim_speed µÄËÙ¶È£¬Òò´Ë£¬´Ë´¦È¡Á½Õß½ÏСֵΪºÏÀí×ö·¨ - // fSpeedSev = min(m_ExtProps.mv.run_speed, fSpeedSev); - // break; - // } - // return fSpeedSev; - //} - - private void OnMsgHstNPCGreeting(ECMSG Msg) - { - cmd_npc_greeting pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); - - if (GPDataTypeHelper.ISNPCID(pCmd.idObject)) - { - // רÃÅ´¦Àíѧϰ¼¼ÄܵÄÒþ²ØNPC - //if (CECHostSkillModel::Instance().IsSkillLearnNPC(pCmd.idObject)) - //{ - // CECGameUIMan* pGameUI = g_pGame.GetGameRun().GetUIManager().GetInGameUIMan(); - // //m_idSevNPC = pCmd.idObject; - // //m_bTalkWithNPC = true; - // //pGameUI.GetDialog("Win_SkillAction").Show(true); - // //CDlgSkillAction* dlg = dynamic_cast(pGameUI.GetDialog("Win_SkillAction")); - // //dlg.ForceShowDialog(); - // CDlgSkillAction* dlg = dynamic_cast(pGameUI.GetDialog("Win_SkillAction")); - // dlg.SetReceivedNPCGreeting(true); - // return; - //} - - CECNPC pNPC = EC_ManMessageMono.Instance._CECNPCMan.GetNPC(pCmd.idObject); - if (!pNPC || !pNPC.IsServerNPC()) - { - return; - } - - // Check distance again - if (!CanTouchTarget(pNPC.GetPos(), pNPC.GetTouchRadius(), 3)) - return; - - m_idSevNPC = pCmd.idObject; - m_bTalkWithNPC = true; - - // Check way point service on NPC - var dwID = (pNPC as CECNPCServer).GetWayPointID(); - if (dwID != null && !HasWayPoint(dwID)) - UnityGameSession.c2s_CmdNPCSevWaypoint(); - //g_pGame.GetGameSession().c2s_CmdNPCSevWaypoint(); - - var pGameUI = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan(); - NPC_ESSENCE? result = (pNPC as CECNPCServer).GetDBEssence(); - if (result != null) - { - pGameUI.PopupNPCDialog(result.Value); - } - } - //else if (GPDataTypeHelper.ISPLAYERID(pCmd.idObject)) - //{ - // EC_ElsePlayer pPlayer = m_pPlayerMan.GetElsePlayer(pCmd.idObject); - - // // Check distance again - // if (!pPlayer || !CanTouchTarget(pPlayer.GetPos(), 0.0f, 3)) - // return; - - // m_idSevNPC = pCmd.idObject; - // m_bTalkWithNPC = true; - // m_iBoothState = 3; - - // g_pGame.GetGameSession().c2s_CmdNPCSevGetContent(GP_NPCSEV_BOOTHSELL); - - // m_pBuyPack.RemoveAllItems(); - // m_pSellPack.RemoveAllItems(); - // m_pEPBoothBPack.RemoveAllItems(); - // m_pEPBoothSPack.RemoveAllItems(); - - // CECGameUIMan* pGameUI = g_pGame.GetGameRun().GetUIManager().GetInGameUIMan(); - // pGameUI.PopupBoothDialog(true, false, pCmd.idObject); + // // ·þÎñÆ÷¶Ë½«Ë®ÃæÒÔÏÂ2Ã×ÒÔÉÏ´¦ÀíΪ run_speed£¨ÓÐÎÊÌ⣩ + // // µ«Î´Ê¹ÓüÓËÙ¼¼ÄÜʱ swim_speed СÓÚ run_speed£¬ + // // ¿ÉÒÔÔÚË®ÃæÒÔÏÂ2Ã×ÒÔÉÏ»ñÈ¡³¬¹ý swim_speed µÄËÙ¶È£¬Òò´Ë£¬´Ë´¦È¡Á½Õß½ÏСֵΪºÏÀí×ö·¨ + // fSpeedSev = min(m_ExtProps.mv.run_speed, fSpeedSev); + // break; + // } + // return fSpeedSev; //} - else - { - return; - } - } - // Does host player have specified way point ? - bool HasWayPoint(uint? wID) - { - if (wID == null) + private void OnMsgHstNPCGreeting(ECMSG Msg) { + cmd_npc_greeting pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); + + if (GPDataTypeHelper.ISNPCID(pCmd.idObject)) + { + // רÃÅ´¦Àíѧϰ¼¼ÄܵÄÒþ²ØNPC + //if (CECHostSkillModel::Instance().IsSkillLearnNPC(pCmd.idObject)) + //{ + // CECGameUIMan* pGameUI = g_pGame.GetGameRun().GetUIManager().GetInGameUIMan(); + // //m_idSevNPC = pCmd.idObject; + // //m_bTalkWithNPC = true; + // //pGameUI.GetDialog("Win_SkillAction").Show(true); + // //CDlgSkillAction* dlg = dynamic_cast(pGameUI.GetDialog("Win_SkillAction")); + // //dlg.ForceShowDialog(); + // CDlgSkillAction* dlg = dynamic_cast(pGameUI.GetDialog("Win_SkillAction")); + // dlg.SetReceivedNPCGreeting(true); + // return; + //} + + CECNPC pNPC = EC_ManMessageMono.Instance._CECNPCMan.GetNPC(pCmd.idObject); + if (!pNPC || !pNPC.IsServerNPC()) + { + return; + } + + // Check distance again + if (!CanTouchTarget(pNPC.GetPos(), pNPC.GetTouchRadius(), 3)) + return; + + m_idSevNPC = pCmd.idObject; + m_bTalkWithNPC = true; + + // Check way point service on NPC + var dwID = (pNPC as CECNPCServer).GetWayPointID(); + if (dwID != null && !HasWayPoint(dwID)) + UnityGameSession.c2s_CmdNPCSevWaypoint(); + //g_pGame.GetGameSession().c2s_CmdNPCSevWaypoint(); + + var pGameUI = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan(); + NPC_ESSENCE? result = (pNPC as CECNPCServer).GetDBEssence(); + if (result != null) + { + pGameUI.PopupNPCDialog(result.Value); + } + } + //else if (GPDataTypeHelper.ISPLAYERID(pCmd.idObject)) + //{ + // EC_ElsePlayer pPlayer = m_pPlayerMan.GetElsePlayer(pCmd.idObject); + + // // Check distance again + // if (!pPlayer || !CanTouchTarget(pPlayer.GetPos(), 0.0f, 3)) + // return; + + // m_idSevNPC = pCmd.idObject; + // m_bTalkWithNPC = true; + // m_iBoothState = 3; + + // g_pGame.GetGameSession().c2s_CmdNPCSevGetContent(GP_NPCSEV_BOOTHSELL); + + // m_pBuyPack.RemoveAllItems(); + // m_pSellPack.RemoveAllItems(); + // m_pEPBoothBPack.RemoveAllItems(); + // m_pEPBoothSPack.RemoveAllItems(); + + // CECGameUIMan* pGameUI = g_pGame.GetGameRun().GetUIManager().GetInGameUIMan(); + // pGameUI.PopupBoothDialog(true, false, pCmd.idObject); + //} + else + { + return; + } + } + + // Does host player have specified way point ? + bool HasWayPoint(uint? wID) + { + if (wID == null) + { + return false; + } + for (int i = 0; i < m_aWayPoints.Count; i++) + { + if (m_aWayPoints[i] == wID) + return true; + } + return false; } - for (int i = 0; i < m_aWayPoints.Count; i++) + + void OnMsgHstWayPoint(ECMSG Msg) { - if (m_aWayPoints[i] == wID) - return true; + //CECGameUIMan pGameUI = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan(); + + //if (Convert.ToInt32(Msg.dwParam2) == CommandID.ACTIVATE_WAYPOINT) + //{ + // cmd_activate_waypoint pCmd = GPDataTypeHelper.FromBytes((byte[])Msg.dwParam1); + // m_aWayPoints.Add(pCmd.waypoint); + + // // add to waypoints array + // pGameUI.GetMapDlgsMgr().UpdateWayPoints(&pCmd.waypoint, 1, false); + + // // Print a notify message + // const CECMapDlgsMgr::PointMap& aWayPoints = pGameUI.GetMapDlgsMgr().GetTransPoint(); + // CECMapDlgsMgr::PointMap::const_iterator itr = aWayPoints.find(pCmd.waypoint); + // if(itr != aWayPoints.end()) + // { + // g_pGame.GetGameRun().AddFixedMessage(FIXMSG_NEWWAYPOINT, (itr.second).strName); + + // bool bCanPopUITips = true; + // int count = CECUIConfig::Instance().GetGameUI().GetTaskIDDisableWayPointsUITipsCount(); + // // ¼ì²éÉíÉÏÊÇ·ñÓнûÖ¹µ¯³ötipsµÄÈÎÎñ + // for (int i=0;i((byte[])Msg.dwParam1); - // m_aWayPoints.Add(pCmd.waypoint); - - // // add to waypoints array - // pGameUI.GetMapDlgsMgr().UpdateWayPoints(&pCmd.waypoint, 1, false); - - // // Print a notify message - // const CECMapDlgsMgr::PointMap& aWayPoints = pGameUI.GetMapDlgsMgr().GetTransPoint(); - // CECMapDlgsMgr::PointMap::const_iterator itr = aWayPoints.find(pCmd.waypoint); - // if(itr != aWayPoints.end()) - // { - // g_pGame.GetGameRun().AddFixedMessage(FIXMSG_NEWWAYPOINT, (itr.second).strName); - - // bool bCanPopUITips = true; - // int count = CECUIConfig::Instance().GetGameUI().GetTaskIDDisableWayPointsUITipsCount(); - // // ¼ì²éÉíÉÏÊÇ·ñÓнûÖ¹µ¯³ötipsµÄÈÎÎñ - // for (int i=0;i serverTime) + bInWar = true; + } + return bInWar; } - return pConfig; - } - public bool IsInFortressWar() - { - bool bInWar = false; - if (IsInFortress()) + public int GetCountry() { return m_idCountry; } + + // Get battle info. + //public BATTLEINFO GetBattleInfo() { return m_BattleInfo; } + + //public bool IsInCountryWar() { return IsInBattle() && GetBattleInfo().IsCountryWar(); } + + // End NPC service + public void EndNPCService() { - int serverTime = EC_Game.GetServerGMTTime(); - if (m_fortressEnter.end_time > serverTime) - bInWar = true; + m_idSevNPC = 0; + m_bTalkWithNPC = false; + m_iBoothState = 0; + m_bIsInKingService = false; + //m_pOffShopCtrl.SetNPCSevFlag(COfflineShopCtrl::NPCSEV_NULL); } - return bInWar; - } - public int GetCountry() { return m_idCountry; } - - // Get battle info. - //public BATTLEINFO GetBattleInfo() { return m_BattleInfo; } - - //public bool IsInCountryWar() { return IsInBattle() && GetBattleInfo().IsCountryWar(); } - - // End NPC service - public void EndNPCService() - { - m_idSevNPC = 0; - m_bTalkWithNPC = false; - m_iBoothState = 0; - m_bIsInKingService = false; - //m_pOffShopCtrl.SetNPCSevFlag(COfflineShopCtrl::NPCSEV_NULL); - } - - void UpdateGFXs(float dwDeltaTime) - { -// if (m_pLevelUpGFX) -// m_pLevelUpGFX->SetParentTM(GetAbsoluteTM()); + void UpdateGFXs(float dwDeltaTime) + { + // if (m_pLevelUpGFX) + // m_pLevelUpGFX->SetParentTM(GetAbsoluteTM()); if (m_pHoverGFX)// && m_idCurHover != m_idSelTarget) { @@ -3251,192 +3236,192 @@ namespace BrewMonster // // Get all extend properties // pSession->c2s_CmdGetExtProps(); -// if (m_pLevelUpGFX) -// m_pLevelUpGFX->Start(true); - PlayGfx(EC_Resource.res_GFXFile((int)GfxResourceType.RES_GFX_LEVELUP), null, 1f,1);//PLAYERMODEL_TYPEALL - - // // Popup notify bubble text - // BubbleText(BUBBLE_LEVELUP, 0); - // - // // Notify my friends that my level changed - // ACHAR szInfo[40]; - // a_sprintf(szInfo, _AL("L%d"), m_BasicProps.iLevel); - // - // for (int i=0; i < m_pFriendMan->GetGroupNum(); i++) - // { - // CECFriendMan::GROUP* pGroup = m_pFriendMan->GetGroupByIndex(i); - // for (int j=0; j < pGroup->aFriends.GetSize(); j++) - // { - // CECFriendMan::FRIEND* pFriend = pGroup->aFriends[j]; - // if (pFriend->IsGameOnline()) - // { - // pSession->SendPrivateChatData(pFriend->GetName(), - // szInfo, GNET::CHANNEL_USERINFO, pFriend->id); - // } - // } - // } - // - // if (GetBasicProps().iLevel==30) - // { - // CECGameUIMan* pGameUI = g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); - // pGameUI->AddChatMessage(pGameUI->GetStringFromTable(9638), GP_CHAT_SYSTEM); - // } - // if (GetBasicProps().iLevel>31) - // { - // CECGameUIMan* pGameUI = g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); - // ((CDlgOnlineAward*)pGameUI->GetDialog("Win_AddExp2"))->RestartWhenLevelup(); - // } - } - - // Estimate mouse cursor - private void EstimateCursor() - { - m_cursorUpdateTimer += Time.deltaTime; - if (m_cursorUpdateTimer < CURSOR_UPDATE_INTERVAL) - return; - m_cursorUpdateTimer = 0f; - - // Early exit checks - if (IsChangingFace() || mainCam == null || m_cachedMouse == null) - { - m_idCurHover = 0; - return; + // if (m_pLevelUpGFX) + // m_pLevelUpGFX->Start(true); + PlayGfx(EC_Resource.res_GFXFile((int)GfxResourceType.RES_GFX_LEVELUP), null, 1f, 1);//PLAYERMODEL_TYPEALL + + // // Popup notify bubble text + // BubbleText(BUBBLE_LEVELUP, 0); + // + // // Notify my friends that my level changed + // ACHAR szInfo[40]; + // a_sprintf(szInfo, _AL("L%d"), m_BasicProps.iLevel); + // + // for (int i=0; i < m_pFriendMan->GetGroupNum(); i++) + // { + // CECFriendMan::GROUP* pGroup = m_pFriendMan->GetGroupByIndex(i); + // for (int j=0; j < pGroup->aFriends.GetSize(); j++) + // { + // CECFriendMan::FRIEND* pFriend = pGroup->aFriends[j]; + // if (pFriend->IsGameOnline()) + // { + // pSession->SendPrivateChatData(pFriend->GetName(), + // szInfo, GNET::CHANNEL_USERINFO, pFriend->id); + // } + // } + // } + // + // if (GetBasicProps().iLevel==30) + // { + // CECGameUIMan* pGameUI = g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); + // pGameUI->AddChatMessage(pGameUI->GetStringFromTable(9638), GP_CHAT_SYSTEM); + // } + // if (GetBasicProps().iLevel>31) + // { + // CECGameUIMan* pGameUI = g_pGame->GetGameRun()->GetUIManager()->GetInGameUIMan(); + // ((CDlgOnlineAward*)pGameUI->GetDialog("Win_AddExp2"))->RestartWhenLevelup(); + // } } - - // Get mouse position using cached device - Vector2 mousePosition = m_cachedMouse.position.ReadValue(); - - // Early exit if mouse hasn't moved significantly (2 pixel threshold) - if (Vector2.Distance(mousePosition, m_lastMousePosition) < 2f) - return; - - m_lastMousePosition = mousePosition; - m_idCurHover = 0; - - CursorType cursorType = CursorType.RES_CUR_NORMAL; - - // Check modifier keys using cached keyboard - bool isShiftPressed = m_cachedKeyboard != null && - (m_cachedKeyboard.leftShiftKey.isPressed || m_cachedKeyboard.rightShiftKey.isPressed); - - Ray ray = mainCam.ScreenPointToRay(mousePosition); - RaycastHit hit; - - // You can add a layer mask here to only raycast against specific layers - // LayerMask interactableMask = LayerMask.GetMask("NPC", "Player", "Item"); - // if (Physics.Raycast(ray, out hit, 100f, interactableMask)) - - if (Physics.Raycast(ray, out hit, 1000f)) // Reduced from 1000f to 100f for better performance + + // Estimate mouse cursor + private void EstimateCursor() { - // Try to get CECObject component (cached lookup) - CECObject hitObject = hit.collider.GetComponent(); - - if (hitObject != null) + m_cursorUpdateTimer += Time.deltaTime; + if (m_cursorUpdateTimer < CURSOR_UPDATE_INTERVAL) + return; + m_cursorUpdateTimer = 0f; + + // Early exit checks + if (IsChangingFace() || mainCam == null || m_cachedMouse == null) { - int idHitObject = CECObject.GetObjectID(hitObject); - - if (idHitObject != 0) + m_idCurHover = 0; + return; + } + + // Get mouse position using cached device + Vector2 mousePosition = m_cachedMouse.position.ReadValue(); + + // Early exit if mouse hasn't moved significantly (2 pixel threshold) + if (Vector2.Distance(mousePosition, m_lastMousePosition) < 2f) + return; + + m_lastMousePosition = mousePosition; + m_idCurHover = 0; + + CursorType cursorType = CursorType.RES_CUR_NORMAL; + + // Check modifier keys using cached keyboard + bool isShiftPressed = m_cachedKeyboard != null && + (m_cachedKeyboard.leftShiftKey.isPressed || m_cachedKeyboard.rightShiftKey.isPressed); + + Ray ray = mainCam.ScreenPointToRay(mousePosition); + RaycastHit hit; + + // You can add a layer mask here to only raycast against specific layers + // LayerMask interactableMask = LayerMask.GetMask("NPC", "Player", "Item"); + // if (Physics.Raycast(ray, out hit, 100f, interactableMask)) + + if (Physics.Raycast(ray, out hit, 1000f)) // Reduced from 1000f to 100f for better performance + { + // Try to get CECObject component (cached lookup) + CECObject hitObject = hit.collider.GetComponent(); + + if (hitObject != null) { - bool bForceAttack = isShiftPressed; - - // Check object type and set appropriate cursor - if (GPDataTypeHelper.ISNPCID(idHitObject)) + int idHitObject = CECObject.GetObjectID(hitObject); + + if (idHitObject != 0) { - // NPC handling - CECNPC pNPC = EC_ManMessageMono.Instance?._CECNPCMan?.GetNPC(idHitObject); - if (pNPC != null && !pNPC.IsDead()) + bool bForceAttack = isShiftPressed; + + // Check object type and set appropriate cursor + if (GPDataTypeHelper.ISNPCID(idHitObject)) { - m_idCurHover = idHitObject; - - if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1) + // NPC handling + CECNPC pNPC = EC_ManMessageMono.Instance?._CECNPCMan?.GetNPC(idHitObject); + if (pNPC != null && !pNPC.IsDead()) { - cursorType = CursorType.RES_CUR_ATTACK; - } - else if (pNPC.IsServerNPC()) - { - if (!IsInBattle() || InSameBattleCamp(pNPC)) + m_idCurHover = idHitObject; + + if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1) { - cursorType = CursorType.RES_CUR_TALK; + cursorType = CursorType.RES_CUR_ATTACK; + } + else if (pNPC.IsServerNPC()) + { + if (!IsInBattle() || InSameBattleCamp(pNPC)) + { + cursorType = CursorType.RES_CUR_TALK; + } } } } - } - else if (GPDataTypeHelper.ISPLAYERID(idHitObject)) - { - // Player handling - EC_ElsePlayer pPlayer = EC_ManMessageMono.Instance?.GetECManPlayer?.GetPlayer(idHitObject) as EC_ElsePlayer; - if (pPlayer != null) + else if (GPDataTypeHelper.ISPLAYERID(idHitObject)) { - m_idCurHover = idHitObject; - - if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1) + // Player handling + EC_ElsePlayer pPlayer = EC_ManMessageMono.Instance?.GetECManPlayer?.GetPlayer(idHitObject) as EC_ElsePlayer; + if (pPlayer != null) { - cursorType = CursorType.RES_CUR_ATTACK; + m_idCurHover = idHitObject; + + if (m_idSelTarget == idHitObject && AttackableJudge(idHitObject, bForceAttack) == 1) + { + cursorType = CursorType.RES_CUR_ATTACK; + } } } - } - else if (GPDataTypeHelper.ISMATTERID(idHitObject)) - { - //todo - // BMLogger.LogError($"[EstimateCursor]- GPDataTypeHelper.ISMATTERID: {idHitObject}"); - // Matter/item handling (uncomment when CECMatter is implemented) - // CECMatter pMatter = GetMatterManager()?.GetMatter(idHitObject); - // if (pMatter != null) - // { - // if (!pMatter.IsMine()) - // cursorType = CursorType.Pickup; - // else if (CanGatherMatter(pMatter)) - // cursorType = pMatter.IsMonsterSpiritMine() ? CursorType.Swallow : CursorType.Dig; - // - // if (cursorType != CursorType.Normal) - // m_idCurHover = idHitObject; - // } + else if (GPDataTypeHelper.ISMATTERID(idHitObject)) + { + //todo + // BMLogger.LogError($"[EstimateCursor]- GPDataTypeHelper.ISMATTERID: {idHitObject}"); + // Matter/item handling (uncomment when CECMatter is implemented) + // CECMatter pMatter = GetMatterManager()?.GetMatter(idHitObject); + // if (pMatter != null) + // { + // if (!pMatter.IsMine()) + // cursorType = CursorType.Pickup; + // else if (CanGatherMatter(pMatter)) + // cursorType = pMatter.IsMonsterSpiritMine() ? CursorType.Swallow : CursorType.Dig; + // + // if (cursorType != CursorType.Normal) + // m_idCurHover = idHitObject; + // } + } } } } + + // Apply cursor change + EC_Game.ChangeCursor((int)cursorType); } - - // Apply cursor change - EC_Game.ChangeCursor((int)cursorType); - } - - // Start normal attacking to selected target - private bool CmdNormalAttack(bool bMoreClose/* false */, bool bCombo/* false */, - int idTarget/* 0 */, int iForceAtk/* -1 */) - { - // StackChecker::ACTrace(2); - // first of all see if we need to cancel sitdown work. - // if (m_pWorkMan.IsSitting()) - // { - // g_pGame->GetGameSession()->c2s_CmdStandUp(); - // return false; - // } + // Start normal attacking to selected target + private bool CmdNormalAttack(bool bMoreClose/* false */, bool bCombo/* false */, + int idTarget/* 0 */, int iForceAtk/* -1 */) + { + // StackChecker::ACTrace(2); - if (!CanDo(ActionCanDo.CANDO_MELEE)) - return false; + // first of all see if we need to cancel sitdown work. + // if (m_pWorkMan.IsSitting()) + // { + // g_pGame->GetGameSession()->c2s_CmdStandUp(); + // return false; + // } - // if (InSlidingState()) - // return false; + if (!CanDo(ActionCanDo.CANDO_MELEE)) + return false; - // if (!bCombo) + // if (InSlidingState()) + // return false; + + // if (!bCombo) // ClearComboSkill(); - if (idTarget<=0) - idTarget = m_idSelTarget; + if (idTarget <= 0) + idTarget = m_idSelTarget; - bool bForceAttack; - if (iForceAtk < 0) - bForceAttack = glb_GetForceAttackFlag(0); - else - bForceAttack = iForceAtk > 0 ? true : false; + bool bForceAttack; + if (iForceAtk < 0) + bForceAttack = glb_GetForceAttackFlag(0); + else + bForceAttack = iForceAtk > 0 ? true : false; - if (AttackableJudge(idTarget, bForceAttack) != 1) - return false; + if (AttackableJudge(idTarget, bForceAttack) != 1) + return false; - return NormalAttackObject(idTarget, bForceAttack, bMoreClose); + return NormalAttackObject(idTarget, bForceAttack, bMoreClose); + } } -} public enum StateAnim {