Files
test/Assets/PerfectWorld/Scripts/Players/EC_HostMsg.cs
T
2026-04-06 13:39:39 +07:00

574 lines
25 KiB
C#

using BrewMonster.Network;
using BrewMonster.Scripts;
using BrewMonster.Scripts.Pet;
using BrewMonster.UI;
using CSNetwork;
using CSNetwork.GPDataType;
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using static BrewMonster.Scripts.Pet.CECPetData;
namespace BrewMonster
{
public partial class CECHostPlayer
{
private readonly CECFriendMan _friendMan = new CECFriendMan();
public CECFriendMan GetFriendMan() => _friendMan;
// 服务器控制的额外操作限制
public enum PLAYER_LIMIT
{
PLAYER_LIMIT_NOFLY, // 禁止"飞行/取消飞行"
PLAYER_LIMIT_NOCHANGESELECT, // 禁止"选中/取消选中/协助攻击"
PLAYER_LIMIT_NOMOUNT, // 禁止召唤骑宠
PLAYER_LIMIT_NOBIND, // 禁止"发起/接收相依相偎"
PLAYER_LIMIT_MAX,
};
// Update pet shortcut when pet freeed
void UpdateFreedPetSC(int iPetIndex)
{
// TO DO: fix later
//int i;
//// Update shortcut sets 1
//for (i = 0; i < (int)Shortcut.NUM_HOSTSCSETS1; i++)
//{
// if (m_aSCSets1[i] != null)
// m_aSCSets1[i].UpdateFreedPetSC(iPetIndex);
//}
//// Update shortcut sets 2
//for (i = 0; i < (int)Shortcut.NUM_HOSTSCSETS2; i++)
//{
// if (m_aSCSets2[i] != null)
// m_aSCSets2[i].UpdateFreedPetSC(iPetIndex);
//}
}
bool OnPetSays(int tid, int nid, int type)
{
bool bSaid = false;
//CECNPC pNPC = EC_Game.GetGameRun().GetWorld().GetNPCMan().GetNPCFromAll(nid);
//if (pNPC && pNPC.GetMasterID() == GetCharacterID())
//{
// const ACHAR* szWords = m_pPetWords.GetWords(tid, (CECPetWords::TYPE_WORDS)type);
// if (szWords)
// {
// pNPC.SetLastSaidWords(szWords, 5000);
// bSaid = true;
// }
//}
return bSaid;
}
/* Is host operating pet ?
return value:
0: host doesn't operating pet.
1: host is summoning pet.
2: host is recalling pet.
3: host is banishing pet.
*/
int CIsOperatingPet()
{
CECHPWorkConcentrate pWork = (m_pWorkMan.GetRunningWork(CECHPWork.Host_work_ID.WORK_CONCENTRATE)) as CECHPWorkConcentrate;
if (pWork != null)
{
if (pWork.GetDoWhat() == (int)CECHPWorkConcentrate.eDO_PET.DO_SUMMONPET)
return 1;
else if (pWork.GetDoWhat() == (int)CECHPWorkConcentrate.eDO_PET.DO_RECALLPET)
return 2;
else if (pWork.GetDoWhat() == (int)CECHPWorkConcentrate.eDO_PET.DO_BANISHPET)
return 3;
else if (pWork.GetDoWhat() == (int)CECHPWorkConcentrate.eDO_PET.DO_RESTOREPET)
return 4;
}
return 0;
}
public override void OnMsgPlayerExtState(ECMSG Msg)
{
base.OnMsgPlayerExtState(Msg);
if (m_aIconStates != null && m_aIconStates.Count > 0)
{
foreach (var state in m_aIconStates)
{
if (state.id == 287) // Thunder ball logic
{
// TODO: Implement UI logic for Ice Thunder Ball
// bool bHideIceThunderBall = CECUIHelper.GetGame().GetConfigs().GetGameSettings().bHideIceThunderBall;
// if (!bHideIceThunderBall) ...
break;
}
}
}
}
void OnMsgHstPetOpt(ECMSG Msg)
{
CECGameRun pGameRun = EC_Game.GetGameRun();
int header = Convert.ToInt32(Msg.dwParam2);
switch (header)
{
case CommandID.GAIN_PET:
{
cmd_gain_pet pCmd = GPDataTypeHelper.FromBytes<cmd_gain_pet>((byte[])Msg.dwParam1);
m_pPetCorral.AddPet(pCmd.slot_index, pCmd.data);
// Print a notify
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.slot_index);
if (pPet != null)
{
if (pPet.IsFollowPet() || pPet.IsCombatPet() || pPet.IsEvolutionPet())
{
// TO DO: fix later
//pGameRun.AddFixedMessage(FIXMSG_PET_HATCH, pPet.GetName());
}
else if (pPet.IsSummonPet())
{
// TO DO: fix later
//pGameRun.AddFixedMessage(FIXMSG_SUMMON_PET_APPEAR, pPet.GetName());
}
}
break;
}
case CommandID.FREE_PET:
{
cmd_free_pet pCmd = GPDataTypeHelper.FromBytes<cmd_free_pet>((byte[])Msg.dwParam1);
// Print a notify
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.slot_index);
if (pPet != null)
{
if (pPet.IsFollowPet() || pPet.IsCombatPet() || pPet.IsEvolutionPet())
{
// TO DO: fix later
//pGameRun.AddFixedMessage(FIXMSG_PET_FREE, pPet.GetName());
}
else if (pPet.IsSummonPet())
{
// TO DO: fix later
//pGameRun.AddFixedMessage(FIXMSG_SUMMON_PET_DISAPPEAR, pPet.GetName());
}
}
// Remove pet from corral
m_pPetCorral.FreePet(pCmd.slot_index, pCmd.pet_id);
// Update pet shortcuts
UpdateFreedPetSC(pCmd.slot_index);
break;
}
case CommandID.SUMMON_PET:
{
cmd_summon_pet pCmd = GPDataTypeHelper.FromBytes<cmd_summon_pet>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.slot_index);
//ASSERT(pPet && pPet.GetTemplateID() == pCmd.pet_tid);
m_pPetCorral.SetActivePetIndex(pCmd.slot_index);
m_pPetCorral.SetActivePetNPCID(pCmd.pet_pid);
m_pPetCorral.SetActivePetLifetime(pCmd.life_time);
if (EC_Game.GetConfigs().GetGameSettings().bPetAutoSkill)
{
for (int i = 0; i < pPet.GetSkillNum(SKILLTYPE.EM_SKILL_DEFAULT); i++)
{
CECPetData.PETSKILL? pSkill = pPet.GetSkill(SKILLTYPE.EM_SKILL_DEFAULT, i);
if (pSkill != null && EC_Game.IsPetAutoSkill(pSkill.Value.idSkill))
pPet.AddAutoSkill(pSkill.Value.idSkill);
}
}
// TO DO: fix later
//OnPetSays(pCmd.pet_tid, pCmd.pet_pid, CECPetWords::TW_SUMMON);
//if (pPet.IsCombatPet() || pPet.IsSummonPet() || pPet.IsEvolutionPet())
// CDlgQuickBarPet::ResetAutoCastSkill();
break;
}
case CommandID.RECALL_PET:
{
cmd_recall_pet pCmd = GPDataTypeHelper.FromBytes<cmd_recall_pet>((byte[])Msg.dwParam1);
//ASSERT(pCmd.slot_index == m_pPetCorral.GetActivePetIndex());
int tid = pCmd.pet_id;
int nid = m_pPetCorral.GetActivePetNPCID();
// 宠物有话说
switch (pCmd.reason)
{
case (char)PET_RECALL_REASON.PET_RECALL_DEFAULT:
//OnPetSays(tid, nid, CECPetWords::TW_RECALL);
break;
case (char)PET_RECALL_REASON.PET_RECALL_DEATH:
//OnPetSays(tid, nid, CECPetWords::TW_DEAD);
break;
case (char)PET_RECALL_REASON.PET_RECALL_LIFE_EXHAUST:
//OnPetSays(tid, nid, CECPetWords::TW_DISAPPEAR);
break;
case (char)PET_RECALL_REASON.PET_RECALL_SACRIFICE:
//OnPetSays(tid, nid, CECPetWords::TW_SACRIFICE);
break;
}
CECPetData pPet = m_pPetCorral.GetActivePet();
if (pPet != null)
pPet.OnPetDead();
m_pPetCorral.SetActivePetIndex(-1);
m_pPetCorral.SetActivePetNPCID(0);
m_bPetInSanctuary = false;
break;
}
case CommandID.PLAYER_START_PET_OP:
{
cmd_player_start_pet_op pCmd = GPDataTypeHelper.FromBytes<cmd_player_start_pet_op>((byte[])Msg.dwParam1);
int iDoWhat;
if (pCmd.op == 0)
iDoWhat = (int)CECHPWorkConcentrate.eDO_PET.DO_SUMMONPET;
else if (pCmd.op == 1)
iDoWhat = (int)CECHPWorkConcentrate.eDO_PET.DO_RECALLPET;
else if (pCmd.op == 2)
iDoWhat = (int)CECHPWorkConcentrate.eDO_PET.DO_BANISHPET;
else if (pCmd.op == 3)
iDoWhat = (int)CECHPWorkConcentrate.eDO_PET.DO_RESTOREPET;
else
iDoWhat = (int)CECHPWorkConcentrate.eDO_PET.DO_UNKNOWN;
m_PetOptCnt.SetPeriod(pCmd.delay * 50);
m_PetOptCnt.Reset();
CECHPWorkConcentrate pWork = (CECHPWorkConcentrate)m_pWorkMan.CreateWork(CECHPWork.Host_work_ID.WORK_CONCENTRATE);
pWork.SetDoWhat(iDoWhat);
m_pWorkMan.StartWork_p1(pWork);
break;
}
case CommandID.PLAYER_STOP_PET_OP:
{
if (IsOperatingPet() != 0)
m_pWorkMan.FinishRunningWork(CECHPWork.Host_work_ID.WORK_CONCENTRATE);
break;
}
case CommandID.PET_RECEIVE_EXP:
{
cmd_pet_receive_exp pCmd = GPDataTypeHelper.FromBytes<cmd_pet_receive_exp>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.slot_index);
if (pPet != null)
{
//ASSERT(pPet.GetTemplateID() == pCmd.pet_id);
pPet.AddExp(pCmd.exp);
}
break;
}
case CommandID.PET_LEVELUP:
{
cmd_pet_levelup pCmd = GPDataTypeHelper.FromBytes<cmd_pet_levelup>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.slot_index);
if (pPet != null)
{
//ASSERT(pPet.GetTemplateID() == pCmd.pet_id);
pPet.LevelUp(pCmd.level, pCmd.exp);
}
//pGameRun.AddFixedMessage(FIXMSG_PET_LEVELUP, pCmd.level);
break;
}
case CommandID.PET_ROOM:
{
cmd_pet_room pCmd = GPDataTypeHelper.FromBytes<cmd_pet_room>((byte[])Msg.dwParam1);
m_pPetCorral.UpdatePets(pCmd, (byte[])Msg.dwParam1);
CECGameUIMan pGameUI = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
//if (pGameUI.GetDialog("Win_Teach").IsShow())
// {
// //pGameUI.UpdateTeach();
// }
break;
}
case CommandID.PET_ROOM_CAPACITY:
{
cmd_pet_room_capacity pCmd = GPDataTypeHelper.FromBytes<cmd_pet_room_capacity>((byte[])Msg.dwParam1);
m_pPetCorral.MagnifyPetSlots((int)pCmd.capacity);
if (m_pPetCorral.HasInit())
{
//pGameRun.AddFixedMessage(FIXMSG_PET_ROOM_SIZE, pCmd.capacity);
}
else
m_pPetCorral.SetHasInit(true);
break;
}
case CommandID.PET_HONOR_POINT:
{
cmd_pet_honor_point pCmd = GPDataTypeHelper.FromBytes<cmd_pet_honor_point>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.index);
if (pPet != null)
pPet.SetIntimacy(pCmd.cur_honor_point);
break;
}
case CommandID.PET_HUNGER_GAUGE:
{
cmd_pet_hunger_gauge pCmd = GPDataTypeHelper.FromBytes<cmd_pet_hunger_gauge>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.index);
if (pPet != null)
pPet.SetHunger(pCmd.cur_hunge_gauge);
break;
}
case CommandID.PET_DEAD:
{
cmd_pet_dead pCmd = GPDataTypeHelper.FromBytes<cmd_pet_dead>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData((int)pCmd.pet_index);
if (pPet != null)
{
pPet.SetHPFactor(0.0f);
pPet.SetHP(0);
pPet.OnPetDead();
}
//pGameRun.AddFixedMessage(FIXMSG_PET_DEAD);
break;
}
case CommandID.PET_REVIVE:
{
cmd_pet_revive pCmd = GPDataTypeHelper.FromBytes<cmd_pet_revive>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData((int)pCmd.pet_index);
if (pPet != null)
pPet.SetHPFactor(pCmd.hp_factor);
break;
}
case CommandID.PET_HP_NOTIFY:
{
cmd_pet_hp_notify pCmd = GPDataTypeHelper.FromBytes<cmd_pet_hp_notify>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData((int)pCmd.pet_index);
if (pPet != null)
{
int lastHP = pPet.GetHP();
pPet.SetHPFactor(pCmd.hp_factor);
pPet.SetHP(pCmd.cur_hp);
pPet.SetMPFactor(pCmd.mp_factor);
pPet.SetMP(pCmd.cur_mp);
// If HP is too low, popup a warning on pet's head
int iLimit = (int)(pPet.CalcMaxHP() * 0.3f);
if (pCmd.cur_hp < lastHP && lastHP != 0 && pCmd.cur_hp < iLimit)
{
CECNPC pNPC = EC_Game.GetGameRun().GetWorld().GetNPCMan().GetNPC(m_pPetCorral.GetActivePetNPCID());
if (pNPC && pNPC.GetMasterID() == GetCharacterID())
{
//pNPC.BubbleText(CECNPC::BUBBLE_HPWARN, 0);
}
}
}
break;
}
case CommandID.PET_AI_STATE:
{
cmd_pet_ai_state pCmd = GPDataTypeHelper.FromBytes<cmd_pet_ai_state>((byte[])Msg.dwParam1);
// 宠物有话说
CECPetData pPetData = m_pPetCorral.GetActivePet();
if (pPetData != null)
{
int tid = pPetData.GetTemplateID();
int nid = m_pPetCorral.GetActivePetNPCID();
if (m_pPetCorral.GetMoveMode() != pCmd.move)
{
switch (pCmd.move)
{
case (byte)CECPetCorral.ePet_MovingMode.MOVE_FOLLOW:
{
//OnPetSays(tid, nid, CECPetWords::TW_FOLLOW);
break;
}
case (byte)CECPetCorral.ePet_MovingMode.MOVE_STAND:
{
//OnPetSays(tid, nid, CECPetWords::TW_STOP);
break;
}
}
}
if (m_pPetCorral.GetAttackMode() != pCmd.attack)
{
switch (pCmd.attack)
{
case (byte)CECPetCorral.ePet_AttackingMode.ATK_DEFENSE:
//OnPetSays(tid, nid, CECPetWords::TW_DEFENSIVE);
break;
case (byte)CECPetCorral.ePet_AttackingMode.ATK_POSITIVE:
//OnPetSays(tid, nid, CECPetWords::TW_OFFENSIVE);
break;
case (byte)CECPetCorral.ePet_AttackingMode.ATK_PASSIVE:
//OnPetSays(tid, nid, CECPetWords::TW_PASSIVE);
break;
}
}
}
m_pPetCorral.SetMoveMode(pCmd.move);
m_pPetCorral.SetAttackMode(pCmd.attack);
break;
}
case CommandID.PET_SET_COOLDOWN:
{
cmd_pet_set_cooldown pCmd = GPDataTypeHelper.FromBytes<cmd_pet_set_cooldown>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.pet_index);
if (pPet != null)
pPet.SetSkillCoolTime(pCmd.cooldown_index, pCmd.cooldown_time);
break;
}
case CommandID.SUMMON_PLANT_PET:
{
int size = Marshal.SizeOf<cmd_summon_plant_pet>();
if (((byte[])Msg.dwParam1).Length >= size)
{
cmd_summon_plant_pet pCmd = GPDataTypeHelper.FromBytes<cmd_summon_plant_pet>((byte[])Msg.dwParam1);
m_pPetCorral.PlantPetEnter(pCmd);
}
break;
}
case CommandID.PLANT_PET_DISAPPEAR:
{
int size = Marshal.SizeOf<cmd_plant_pet_disapper>();
if (((byte[])Msg.dwParam1).Length >= size)
{
cmd_plant_pet_disapper pCmd = GPDataTypeHelper.FromBytes<cmd_plant_pet_disapper>((byte[])Msg.dwParam1);
m_pPetCorral.PlantPetDisappear(pCmd);
}
break;
}
case CommandID.PLANT_PET_HP_NOTIFY:
{
int size = Marshal.SizeOf<cmd_plant_pet_hp_notify>();
if (((byte[])Msg.dwParam1).Length >= size)
{
cmd_plant_pet_hp_notify pCmd = GPDataTypeHelper.FromBytes<cmd_plant_pet_hp_notify>((byte[])Msg.dwParam1);
m_pPetCorral.PlantPetInfo(pCmd);
}
break;
}
case CommandID.PET_PROPERTY:
{
cmd_pet_property pCmd = GPDataTypeHelper.FromBytes<cmd_pet_property>((byte[])Msg.dwParam1);
CECPetData pPet = m_pPetCorral.GetPetData(pCmd.pet_index);
if (pPet != null)
{
pPet.SetExtendProps(pCmd.prop);
}
break;
}
case CommandID.PET_REBUILD_INHERIT_START:
case CommandID.PET_REBUILD_INHERIT_INFO:
case CommandID.PET_REBUILD_INHERIT_END:
case CommandID.PET_EVOLUTION_DONE:
case CommandID.PET_REBUILD_NATURE_START:
case CommandID.PET_REBUILD_NATURE_INFO:
case CommandID.PET_REBUILD_NATURE_END:
{
CECGameUIMan pGameUI = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan();
if (pGameUI != null)
{
//((CDlgPreviewPetRebuild*)pGameUI.GetDialog("Win_PreviewPet")).OnServerNotify(Msg.dwParam2, (void*)Msg.dwParam1);
}
break;
}
default:
break;
}
}
void OnMsgHstSetPlayerLimit(ECMSG Msg)
{
cmd_set_player_limit pCmd = GPDataTypeHelper.FromBytes<cmd_set_player_limit>((byte[])Msg.dwParam1);
if (pCmd.index >= 0 && pCmd.index < (int)PLAYER_LIMIT.PLAYER_LIMIT_MAX)
m_playerLimits[pCmd.index] = (pCmd.b != 0);
}
// Get time counter of using item in pack
public bool GetUsingItemTimeCnt(ref uint dwCurTime, ref uint dwMaxTime, ref int? piItem/* NULL */)
{
if (m_pWorkMan == null)
{
return false;
}
if (!m_pWorkMan.IsUsingItem())
return false;
CECHPWorkUse pWork = (m_pWorkMan.GetRunningWork(CECHPWork.Host_work_ID.WORK_USEITEM)) as CECHPWorkUse;
CECCounter cnt = pWork.GetTimeCounter();
dwCurTime = (uint)cnt.GetCounter();
dwMaxTime = (uint)cnt.GetPeriod();
if (piItem != null)
piItem = pWork.GetItem();
return true;
}
void OnMsgHstSanctuary(ECMSG Msg)
{
if (Convert.ToInt32(Msg.dwParam2) == CommandID.ENTER_SANCTUARY)
{
cmd_object_enter_sanctuary pCmd = GPDataTypeHelper.FromBytes<cmd_object_enter_sanctuary>((byte[])Msg.dwParam1);
if (pCmd.id == m_PlayerInfo.cid)
{
m_bInSanctuary = true;
// Print a notify
EC_Game.GetGameRun().AddFixedMessage((int)FixedMsg.FIXMSG_ENTERSHELTER);
}
else
{
m_bPetInSanctuary = true;
EC_Game.GetGameRun().AddFixedMessage((int)FixedMsg.FIXMSG_PET_ENTERSHELTER);
}
}
else if (Convert.ToInt32(Msg.dwParam2) == CommandID.LEAVE_SANCTUARY)
{
cmd_object_leave_sanctuary pCmd = GPDataTypeHelper.FromBytes<cmd_object_leave_sanctuary>((byte[])Msg.dwParam1);
if (pCmd.id == m_PlayerInfo.cid)
{
m_bInSanctuary = false;
// Print a notify
EC_Game.GetGameRun().AddFixedMessage((int)FixedMsg.FIXMSG_LEAVESHELTER);
}
else
{
m_bPetInSanctuary = false;
EC_Game.GetGameRun().AddFixedMessage((int)FixedMsg.FIXMSG_PET_LEAVESHELTER);
}
}
}
}
}