Files
test/Assets/Scripts/CECHostPlayer.Interaction.cs
NguyenVanDat 2d85773f0e REFACTOR CECHostPlayer
separate class to partial class
2026-02-24 10:57:12 +07:00

266 lines
12 KiB
C#

using BrewMonster.Managers;
using BrewMonster.Network;
using BrewMonster.Scripts;
using BrewMonster.UI;
using CSNetwork;
using CSNetwork.GPDataType;
using ModelRenderer.Scripts.GameData;
using PerfectWorld.Scripts;
using PerfectWorld.Scripts.Managers;
using System;
using UnityEngine;
using static BrewMonster.Scripts.CECHPWork;
namespace BrewMonster
{
public partial class CECHostPlayer
{
private void OnMsgHstNPCGreeting(ECMSG Msg)
{
cmd_npc_greeting pCmd = GPDataTypeHelper.FromBytes<cmd_npc_greeting>((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<CDlgSkillAction*>(pGameUI.GetDialog("Win_SkillAction"));
// //dlg.ForceShowDialog();
// CDlgSkillAction* dlg = dynamic_cast<CDlgSkillAction*>(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
//TODO: Fix later
//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;
}
}
private void OnMsgPlayerDoEmote(ECMSG Msg)
{
if (!m_pWorkMan.IsStanding() &&
!m_pWorkMan.IsBeingBound())
return;
int cmd = Convert.ToInt32(Msg.dwParam2);
if (cmd == CommandID.OBJECT_DO_EMOTE)
{
cmd_object_do_emote pCmd = GPDataTypeHelper.FromBytes<cmd_object_do_emote>((byte[])Msg.dwParam1);
DoEmote(pCmd.emotion);
// if( m_iBuddyId )
// {
// CECPlayer pBuddy = m_pPlayerMan.GetPlayer(m_iBuddyId);
// if (pBuddy)
// pBuddy.DoEmote(pCmd.emotion);
// }
GetTaskInterface().SetEmotion(pCmd.emotion);
}
else if (cmd == CommandID.OBJECT_EMOTE_RESTORE)
{
CECHPWork pWork = m_pWorkMan.GetRunningWork((int)WorkID.WORK_STAND);
if (pWork != null)
{
((CECHPWorkStand)pWork).SetPoseAction((int)PLAYER_ACTION_TYPE.ACT_STAND, false);
}
}
}
// Do emote action
private bool DoEmote(int idEmote)
{
if (!m_pWorkMan.IsStanding())
return false;
CECHPWorkStand pWork = m_pWorkMan.GetRunningWork(Host_work_ID.WORK_STAND) as CECHPWorkStand;
if (pWork == null)
{
Debug.LogError("Null CECHPWorkStand");
}
int iAction = (int)PLAYER_ACTION_TYPE.ACT_STAND;
bool bSession = false;
// Select action according to pose
switch (idEmote)
{
case (int)RoleExpression.ROLEEXP_WAVE: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_WAVE; break;
case (int)RoleExpression.ROLEEXP_NOD: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_NOD; break;
case (int)RoleExpression.ROLEEXP_SHAKEHEAD: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_SHAKEHEAD; break;
case (int)RoleExpression.ROLEEXP_SHRUG: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_SHRUG; break;
case (int)RoleExpression.ROLEEXP_LAUGH: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_LAUGH; break;
case (int)RoleExpression.ROLEEXP_ANGRY: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ANGRY; break;
case (int)RoleExpression.ROLEEXP_STUN: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_STUN; break;
case (int)RoleExpression.ROLEEXP_DEPRESSED: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_DEPRESSED; break;
case (int)RoleExpression.ROLEEXP_KISSHAND: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_KISSHAND; break;
case (int)RoleExpression.ROLEEXP_SHY: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_SHY; break;
case (int)RoleExpression.ROLEEXP_SALUTE: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_SALUTE; break;
case (int)RoleExpression.ROLEEXP_SITDOWN:
iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_SITDOWN;
bSession = true;
break;
case (int)RoleExpression.ROLEEXP_ASSAULT: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ASSAULT; break;
case (int)RoleExpression.ROLEEXP_THINK: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_THINK; break;
case (int)RoleExpression.ROLEEXP_DEFIANCE: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_DEFIANCE; break;
case (int)RoleExpression.ROLEEXP_VICTORY: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_VICTORY; break;
case (int)RoleExpression.ROLEEXP_GAPE: iAction = (int)PLAYER_ACTION_TYPE.ACT_GAPE; break;
case (int)RoleExpression.ROLEEXP_KISS: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_KISS; break;
case (int)RoleExpression.ROLEEXP_FIGHT: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_FIGHT; break;
case (int)RoleExpression.ROLEEXP_ATTACK1: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ATTACK1; break;
case (int)RoleExpression.ROLEEXP_ATTACK2: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ATTACK2; break;
case (int)RoleExpression.ROLEEXP_ATTACK3: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ATTACK3; break;
case (int)RoleExpression.ROLEEXP_ATTACK4: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_ATTACK4; break;
case (int)RoleExpression.ROLEEXP_DEFENCE: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_DEFENCE; break;
case (int)RoleExpression.ROLEEXP_FALL: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_FALL; break;
case (int)RoleExpression.ROLEEXP_FALLONGROUND:
iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_FALLONGROUND; break;
case (int)RoleExpression.ROLEEXP_LOOKAROUND:
iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_LOOKAROUND; break;
case (int)RoleExpression.ROLEEXP_DANCE: iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_DANCE; break;
case (int)RoleExpression.ROLEEXP_FASHIONWEAPON:
iAction = (int)PLAYER_ACTION_TYPE.ACT_EXP_FASHIONWEAPON; break;
case (int)RoleExpression.ROLEEXP_TWO_KISS: iAction = (int)PLAYER_ACTION_TYPE.ACT_TWO_KISS; break;
case (int)RoleExpression.ROLEEXP_FIREWORK: iAction = (int)PLAYER_ACTION_TYPE.ACT_ATTACK_TOSS; break;
default:
break;
}
pWork.SetPoseAction(iAction, bSession);
return true;
}
void OnMsgPlayerGather(ECMSG Msg)
{
int cmd = Convert.ToInt32(Msg.dwParam2);
if (cmd == CommandID.PLAYER_GATHER_START)
{
cmd_player_gather_start pCmd = GPDataTypeHelper.FromBytes<cmd_player_gather_start>((byte[])Msg.dwParam1);
EC_ManMatter pMatterMan = EC_ManMessageMono.Instance.GetECManMatter;//g_pGame.GetGameRun().GetWorld().GetMatterMan();
CECMatter pMatter = pMatterMan.GetMatter(pCmd.mid);
// if (pMatter && pMatter.IsMonsterSpiritMine()) {
// CECHPWorkUse* pWork = (CECHPWorkUse*)m_pWorkMan.CreateWork(CECHPWork::WORK_USEITEM);
// if (pWork) {
// pWork.SetParams(pCmd.mid, pCmd.use_time * 1000, pCmd.mid, true);
// m_pWorkMan.StartWork_p1(pWork);
// }
// StartMonsterSpiritConnectGfx(pCmd.mid, pMatter.GetPos());
// } else {
EC_HPWorkPick pWork = (EC_HPWorkPick)m_pWorkMan.CreateWork(Host_work_ID.WORK_PICKUP);
if (pWork != null)
{
pWork.SetGather(true, pMatter ? pMatter.GetTemplateID() : 0);
m_pWorkMan.StartWork_p1(pWork);
}
// }
// Start time counter
m_GatherCnt.SetPeriod(pCmd.use_time * 1000);
m_GatherCnt.Reset();
}
else if (cmd == CommandID.PLAYER_GATHER_STOP)
{
cmd_player_gather_stop pCmd = GPDataTypeHelper.FromBytes<cmd_player_gather_stop>((byte[])Msg.dwParam1);
m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_PICKUP);
m_pWorkMan.FinishRunningWork(Host_work_ID.WORK_USEITEM);
// StopMonsterSpiritConnectGfx();
var pDlg = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan().GetDialog("Win_Prgs2");
if (pDlg == null)
{
BMLogger.LogError("Null Win_Prgs2");
return;
}
if (pDlg is not DlgWinPrgs2 dlgWinPrgs)
{
BMLogger.LogError("Can not cast Win_Prgs2");
return;
}
dlgWinPrgs.SetActiveProgress(false);
}
else if (cmd == CommandID.MINE_GATHERED)
{
cmd_mine_gathered pCmd = GPDataTypeHelper.FromBytes<cmd_mine_gathered>((byte[])Msg.dwParam1);
// ASSERT(pCmd && pCmd.player_id == m_PlayerInfo.cid);
elementdataman pDataMan = EC_Game.GetElementDataMan();
DATA_TYPE DataType = pDataMan.get_data_type((uint)pCmd.item_type, ID_SPACE.ID_SPACE_ESSENCE);
if (DataType == DATA_TYPE.DT_MONSTER_SPIRIT_ESSENCE)
{
// StartMonsterSpiritBallGfx();
// m_CardHolder.gain_times++;
}
}
}
// Is doing session pose ?
private bool DoingSessionPose()
{
var pCurWork = m_pWorkMan.GetRunningWork(Host_work_ID.WORK_STAND);
if (pCurWork != null)
{
if (((CECHPWorkStand)pCurWork).DoingSessionPose())
{
return true;
}
}
return false;
}
}
}