261 lines
8.5 KiB
C#
261 lines
8.5 KiB
C#
using BrewMonster.Network;
|
|
using BrewMonster.Scripts.World;
|
|
using CSNetwork.GPDataType;
|
|
using PerfectWorld.Scripts.Managers.BrewMonster.Managers;
|
|
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class CECPet : CECNPC
|
|
{
|
|
// Data in database
|
|
PET_ESSENCE? m_pDBEssence;
|
|
string m_strCompName; // Complete name with master's name
|
|
|
|
public CECPet(CECNPCMan pNPCMan)
|
|
{
|
|
m_iCID = (int)Class_ID.OCID_PET;
|
|
m_pDBEssence = null;
|
|
m_fTouchRad = 1.0f;
|
|
}
|
|
|
|
// Initlaize object
|
|
public override bool Init(int tid, in info_npc Info, ReadOnlySpan<byte> packet, int infoOffset)
|
|
{
|
|
if (!base.Init(tid, Info, packet, infoOffset))
|
|
return false;
|
|
|
|
// Get database data
|
|
var pDB = ElementDataManProvider.GetElementDataMan();
|
|
DATA_TYPE DataType = new DATA_TYPE();
|
|
object pDBData = pDB.get_data_ptr((uint)tid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
|
|
|
|
if (pDBData == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
byte[] szModelFile = null;
|
|
|
|
if (DataType == DATA_TYPE.DT_MONSTER_ESSENCE)
|
|
{
|
|
MONSTER_ESSENCE pMonsterData = (MONSTER_ESSENCE)pDBData;
|
|
szModelFile = pMonsterData.file_model;
|
|
|
|
object pObEggData = pDB.get_data_ptr(pMonsterData.id_pet_egg_captured, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
|
|
if (pObEggData == null)
|
|
{
|
|
return false;
|
|
}
|
|
var pEggData = (PET_EGG_ESSENCE)pObEggData;
|
|
m_pDBEssence = (PET_ESSENCE)pDB.get_data_ptr((uint)pEggData.id_pet, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
|
|
m_NPCInfo.tid = pEggData.id_pet;
|
|
}
|
|
else
|
|
{
|
|
m_pDBEssence = (PET_ESSENCE)pDBData;
|
|
szModelFile = m_pDBEssence.Value.file_model;
|
|
}
|
|
|
|
if (m_pDBEssence == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
SetUseGroundNormal(m_pDBEssence.Value.stand_mode == 0 ? true : false);
|
|
m_fTouchRad = m_pDBEssence.Value.size;
|
|
m_BasicProps.iLevel = 1;
|
|
|
|
// Submit EC model loading request to loading thread
|
|
QueueLoadNPCModel();
|
|
|
|
float fExt = m_fTouchRad * 1.5f;
|
|
m_cdr.vExts.Set(fExt, fExt, fExt);
|
|
m_pNPCModelPolicy.SetDefaultPickAABBExt(m_cdr.vExts);
|
|
|
|
// If NPC doesn't have specific name, use the name in database
|
|
if ((Info.state & PlayerNPCState.GP_STATE_NPC_NAME) == 0)
|
|
{
|
|
m_strName = new string(m_pDBEssence.Value.name
|
|
.TakeWhile(c => c != 0)
|
|
.Select(c => (char)c)
|
|
.ToArray()
|
|
);
|
|
EC_Game.GetGameRun().GetUIManager().FilterBadWords(ref m_strName);
|
|
// Try to build complete name
|
|
BuildCompleteName();
|
|
}
|
|
|
|
if ((Info.state & PlayerNPCState.GP_STATE_NPC_PET) != 0)
|
|
{
|
|
if (!IsPlantPet())
|
|
{
|
|
// 非植物宠时,能够从宠物面板和玩家面板中相互追踪
|
|
CECPlayer pPlayer = EC_Game.GetGameRun().GetWorld().GetPlayerMan().GetPlayer(m_idMaster);
|
|
if (pPlayer)
|
|
{
|
|
pPlayer.SetCurPetID(Info.nid);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ((m_pDBEssence.Value.combined_switch & (uint)PET_COMBINED_SWITCH.PCS_FORBID_SELECTION) != 0)
|
|
{
|
|
SetSelectable(false);
|
|
}
|
|
|
|
A3DVECTOR3 vPos = Info.pos;
|
|
SetPos(EC_Utility.ToVector3(vPos));
|
|
SetDirAndUp(EC_Utility.ToVector3(EC_Utility.glb_DecompressDirH(Info.dir)), g_vAxisY);
|
|
|
|
StartWork((int)WorkType.WT_NOTHING, (int)WorkID.WORK_STAND);
|
|
|
|
return true;
|
|
}
|
|
|
|
// Tick routine
|
|
protected override void Update()
|
|
{
|
|
base.Update();
|
|
if (m_strCompName != null && m_strCompName.Length == 0)
|
|
{
|
|
// Try to build complete name
|
|
BuildCompleteName();
|
|
}
|
|
}
|
|
|
|
// Get NPC name color
|
|
public virtual uint GetNameColor()
|
|
{
|
|
EC_ManPlayer pPlayerMan = EC_Game.GetGameRun().GetWorld().GetPlayerMan();
|
|
CECPlayer pPlayer = pPlayerMan.GetPlayer(m_idMaster);
|
|
if (!pPlayer)
|
|
return base.GetNameColor();
|
|
|
|
return pPlayer.GetNameColor();
|
|
}
|
|
|
|
public virtual bool IsImmuneDisable()
|
|
{
|
|
if(m_pDBEssence == null)
|
|
{
|
|
return false;
|
|
}
|
|
if ((m_pDBEssence.Value.combined_switch & (uint)PET_COMBINED_SWITCH.PCS_HIDE_IMMUNE) != 0)
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
public virtual float GetTransparentLimit()
|
|
{
|
|
if (m_pDBEssence != null)
|
|
{
|
|
if ((m_pDBEssence.Value.combined_switch & (uint)PET_COMBINED_SWITCH.PCS_FORBID_SELECTION) != 0)
|
|
{
|
|
return -1.0f;
|
|
}
|
|
|
|
}
|
|
return base.GetTransparentLimit();
|
|
}
|
|
public virtual bool ShouldHideName()
|
|
{
|
|
if (m_pDBEssence == null) { return false; }
|
|
return (m_pDBEssence.Value.combined_switch & (uint)PET_COMBINED_SWITCH.PCS_HIDE_NAME) != 0;
|
|
}
|
|
|
|
// Is this host player's pet
|
|
public bool IsHostPet()
|
|
{
|
|
CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer();
|
|
return GetMasterID() == pHost.GetCharacterID();
|
|
}
|
|
// Is this pet attackable;
|
|
public bool CanBeAttacked()
|
|
{
|
|
return IsCombatPet()
|
|
|| IsSummonPet()
|
|
|| IsPlantPet()
|
|
|| IsEvolutionPet();
|
|
}
|
|
// Is a follow pet ?
|
|
public bool IsFollowPet()
|
|
{
|
|
if (m_pDBEssence != null)
|
|
return m_pDBEssence.Value.id_type == 8783;
|
|
|
|
return false;
|
|
}
|
|
// Is a combat pet ?
|
|
public bool IsCombatPet()
|
|
{
|
|
if (m_pDBEssence != null)
|
|
return m_pDBEssence.Value.id_type == 8782;
|
|
|
|
return false;
|
|
}
|
|
// 是否为召唤宠
|
|
public bool IsSummonPet()
|
|
{
|
|
if(m_pDBEssence == null) return false;
|
|
return m_pDBEssence.Value.id_type == 28752;
|
|
}
|
|
// 是否为植物宠
|
|
public bool IsPlantPet()
|
|
{
|
|
if (m_pDBEssence == null) return false;
|
|
return m_pDBEssence.Value.id_type == 28913;
|
|
}
|
|
// 是否是进化宠
|
|
public bool IsEvolutionPet()
|
|
{
|
|
if (m_pDBEssence == null) return false;
|
|
return m_pDBEssence.Value.id_type == 37698;
|
|
}
|
|
|
|
public PET_ESSENCE? GetDBEssence() { return m_pDBEssence; }
|
|
|
|
// Build complete name
|
|
public void BuildCompleteName()
|
|
{
|
|
//if (!m_npcUI) return;
|
|
//var szMasterName = EC_Game.GetGameRun().GetPlayerName(m_idMaster, false);
|
|
//if (!szMasterName) return;
|
|
|
|
//string strMasterName = szMasterName;
|
|
|
|
//CECWorld pWorld = EC_Game.GetGameRun().GetWorld();
|
|
//if (pWorld.IsCountryWarMap() &&
|
|
// !CECUIConfig::Instance().GetGameUI().bShowNameInCountryWar)
|
|
//{
|
|
// // 国战场景中,不直接显示宠物主人名称时,要求查询到此主人信息
|
|
// // 此改动(if语句中的内容)将导致主人未出现时无法看到宠物名称
|
|
// // if 括号中的判断是必要的,将增加看到宠物名称的机会
|
|
|
|
// EC_ManPlayer pPlayerMan = pWorld.GetPlayerMan();
|
|
// CECPlayer pPlayer = pPlayerMan.GetPlayer(m_idMaster);
|
|
// if (!pPlayer)
|
|
// {
|
|
// // 还没看到此玩家,无法判断其国家,还不能确定如何显示
|
|
// return;
|
|
// }
|
|
// if (pPlayer.GetShowNameInCountryWar())
|
|
// strMasterName = pPlayer.GetNameInCountryWar();
|
|
//}
|
|
|
|
//m_strCompName.Format(g_pGame.GetFixedMsgTab().GetWideString(FIXMSG_WHOSETHING), strMasterName, m_strName);
|
|
//m_npcUI.SetName(m_strCompName);
|
|
}
|
|
|
|
public override void SetUpCECNPC(CECNPCMan pNPCMan)
|
|
{
|
|
base.SetUpCECNPC(pNPCMan);
|
|
m_iCID = (int)Class_ID.OCID_PET;
|
|
m_pDBEssence = null;
|
|
m_fTouchRad = 1.0f;
|
|
}
|
|
}
|
|
}
|