Files
test/Assets/Scripts/CECHostPlayer.Pet.cs
2026-04-06 13:39:39 +07:00

259 lines
9.0 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 BrewMonster.Assets.PerfectWorld.Scripts.Players;
using UnityEngine;
using static BrewMonster.Scripts.Pet.CECPetData;
using BrewMonster.Scripts.Managers;
using static BrewMonster.Scripts.EC_IvtrEquip;
using PerfectWorld.Scripts.Managers;
namespace BrewMonster
{
public partial class CECHostPlayer
{
private void OnMsgPlayerFly(ECMSG Msg)
{
if (Convert.ToInt32(Msg.dwParam2) == CommandID.OBJECT_TAKEOFF)
{
if ((m_dwStates & PlayerNPCState.GP_STATE_FLY) == 0)
{
m_dwStates |= PlayerNPCState.GP_STATE_FLY;
m_bRushFly = false;
CECHPWorkFly pWork = (CECHPWorkFly)m_pWorkMan.CreateWork(CECHPWork.Host_work_ID.WORK_FLYOFF);
if (m_pWorkMan.IsFreeFalling())
{
pWork.m_bContinueFly = true;
m_pWorkMan.StartWork_p1(pWork);
}
else
{
pWork.m_bContinueFly = false;
m_pWorkMan.StartWork_p2(pWork);
}
}
}
else if (Convert.ToInt32(Msg.dwParam2) == CommandID.OBJECT_LANDING)
{
if ((m_dwStates & PlayerNPCState.GP_STATE_FLY) != 0)
{
m_dwStates &= ~(uint)PlayerNPCState.GP_STATE_FLY;
if (IsDead() || m_bCandHangerOn || IsHangerOn())
ShowWing(false);
else
{
CECHPWorkFall pWork =
(CECHPWorkFall)m_pWorkMan.CreateWork(CECHPWork.Host_work_ID.WORK_FREEFALL);
pWork.SetFallType(CECHPWorkFall.Fall_type.TYPE_FLYFALL);
m_pWorkMan.StartWork_p1(pWork);
}
// Below two lines will fix the "host stand in air" bug.
m_iMoveEnv = Move_environment.MOVEENV_GROUND;
m_CDRInfo.vTPNormal.Clear();
}
}
else // HOST_RUSH_FLY
{
cmd_host_rush_fly pCmd = GPDataTypeHelper.FromBytes<cmd_host_rush_fly>((byte[])Msg.dwParam1);
m_bRushFly = pCmd.is_active != 0 ? true : false;
}
}
/* 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.
*/
public int IsOperatingPet()
{
if (m_pWorkMan == null)
{
return 0;
}
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;
}
// Summon pet
public bool SummonPet(int iPetIdx)
{
if (m_pActionSwitcher != null)
m_pActionSwitcher.PostMessge((int)EMsgActionSwitcher.MSG_MOUNTPET);
CECGameRun pGameRun = EC_Game.GetGameRun();
CECUIManager pGameUI = pGameRun.GetUIManager();
CECPetData pPet = m_pPetCorral.GetPetData(iPetIdx);
if (pPet == null)
return false;
if (!CanDo(ActionCanDo.CANDO_SUMMONPET))
return false;
// Couldn't summon daed pet
if (pPet.IsDead())
{
//pGameRun.AddFixedMessage(FIXMSG_PET_DEAD);
//Debug.LogError("FIXMSG_PET_DEAD");
// pGameUI.ShowMessageBox("MessageBox", "PET_DEAD", MessageBoxType.YesButton);
pGameUI.ShowMessageBoxYes("MessageBox", "PET_DEAD", null, null);
return false;
}
// If host could't stop naturally, cancel summoning
if (!NaturallyStopMoving())
return false;
// ¼ì²éµ±Ç°ÊÇ·ñ½ûÖ¹ÕÙ»½Æï³è
if (pPet.IsMountPet() && m_playerLimits[(int)PLAYER_LIMIT.PLAYER_LIMIT_NOMOUNT])
return false;
if (m_ReincarnationCount != 0)
{
int iLevelRequired = pPet.GetLevel() - 35 - m_ReincarnationCount * 5;
if (m_BasicProps.iLevel < iLevelRequired)
{
if (pGameUI != null)
{
string strText = "";
strText = string.Format(pGameUI.GetInGameUIMan().GetStringFromTable(10787), iLevelRequired);
// pGameUI.ShowMessageBox("MessageBox", strText, MessageBoxType.YesButton);
pGameUI.ShowMessageBoxYes("MessageBox", strText, null, null);
}
return false;
}
}
UnityGameSession.c2s_CmdPetSummon(iPetIdx);
return true;
}
// Recall pet
public bool RecallPet()
{
if (m_pActionSwitcher != null)
m_pActionSwitcher.PostMessge((int)EMsgActionSwitcher.MSG_MOUNTPET);
// If host could't stop naturally, cancel recalling
if (!NaturallyStopMoving())
return false;
UnityGameSession.c2s_CmdPetRecall();
return true;
}
// Get pet operation time counter
public CECCounter GetPetOptTime() { return m_PetOptCnt; }
public CECPetCorral GetPetCorral()
{
return m_pPetCorral;
}
// Hatch pet
public bool HatchPet(int iIvtrIdx)
{
EC_IvtrItem pItem = m_pPack.GetItem(iIvtrIdx);
if (pItem == null || pItem.GetClassID() != (int)EQUIP_CLASS_ID.ICID_PETEGG)
return false;
CECGameRun pGameRun = EC_Game.GetGameRun();
EC_IvtrPetEgg pEgg = (EC_IvtrPetEgg)pItem;
IVTR_ESSENCE_PETEGG e = pEgg.GetEssence();
// Check profession
if ((e.req_class & (1 << m_iProfession)) == 0)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_WRONGPROF);
return false;
}
// Check level
int iLevelReq = Math.Max((int)e.level, e.req_level);
if (GetMaxLevelSofar() < iLevelReq)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_LEVELTOOLOW);
return false;
}
// Check money
if (GetMoneyAmount() < pEgg.GetDBEssence().money_hatched)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_NEEDMONEY);
return false;
}
// Check whether pet corral is full
if (m_pPetCorral.GetEmptySlotNum() == 0)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_PET_CORRALFULL);
return false;
}
AddMoneyAmount(-pEgg.GetDBEssence().money_hatched);
UnityGameSession.c2s_CmdNPCSevHatchPet(iIvtrIdx, pItem.GetTemplateID());
return true;
}
// Restore pet
public bool RestorePet(int iPetIdx)
{
CECPetData pPet = m_pPetCorral.GetPetData(iPetIdx);
if (pPet == null || iPetIdx == m_pPetCorral.GetActivePetIndex())
return false;
CECGameRun pGameRun = EC_Game.GetGameRun();
// Check money
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
object ob_pdbe = ElementDataManProvider.GetElementDataMan().get_data_ptr((uint)pPet.GetEggID(), ID_SPACE.ID_SPACE_ESSENCE,ref DataType);
if (DataType != DATA_TYPE.DT_PET_EGG_ESSENCE || ob_pdbe == null)
return false;
PET_EGG_ESSENCE pdbe = (PET_EGG_ESSENCE)ob_pdbe;
if (GetMoneyAmount() < pdbe.money_restored)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_NEEDMONEY);
return false;
}
// Check package space
if (m_pPack.GetEmptySlotNum() == 0)
{
pGameRun.AddFixedMessage((int)FixedMsg.FIXMSG_PACKISFULL);
return false;
}
AddMoneyAmount(-pdbe.money_restored);
UnityGameSession.c2s_CmdNPCSevRestorePet(iPetIdx);
return true;
}
}
}