87 lines
2.8 KiB
C#
87 lines
2.8 KiB
C#
using BrewMonster;
|
|
using CSNetwork.GPDataType;
|
|
using System;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using UnityEngine;
|
|
using static CECNPC;
|
|
|
|
public class CECNPCServer : CECNPC
|
|
{
|
|
NPC_ESSENCE? m_pDBEssence;
|
|
MONSTER_ESSENCE? m_pMonEssence;
|
|
float m_fTaxRate = 0.05f; // Tax rate
|
|
public override void SetUpCECNPC(CECNPCMan pNPCMan)
|
|
{
|
|
base.SetUpCECNPC(pNPCMan);
|
|
m_iCID = (int)Class_ID.OCID_SERVER;
|
|
m_pDBEssence = null;
|
|
}
|
|
public override bool Init(int tid, in info_npc info, ReadOnlySpan<byte> packet, int infoOffset)
|
|
{
|
|
base.Init(tid, info, packet, infoOffset);
|
|
//BrewMonster.BMLogger.Log("HoangDev: MonsterInit");
|
|
var pDB = ElementDataManProvider.GetElementDataMan();
|
|
DATA_TYPE DataType = default;
|
|
var data = pDB.get_data_ptr((uint)tid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
|
|
m_pDBEssence = data != null ? (NPC_ESSENCE?)data : null;
|
|
|
|
var data1 = pDB.get_data_ptr(m_pDBEssence.Value.id_src_monster, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
|
|
|
|
if (data1 == null)
|
|
{
|
|
if ((data1 = (MONSTER_ESSENCE?)pDB.get_data_ptr(4249, ID_SPACE.ID_SPACE_ESSENCE, ref DataType)) == null)
|
|
{
|
|
BMLogger.LogError("HoangDEv : CECNPCServer::Init, server NPC reference to null monster data");
|
|
return false;
|
|
}
|
|
}
|
|
m_pMonEssence = (MONSTER_ESSENCE?)data1;
|
|
|
|
m_fTouchRad = m_pMonEssence.Value.size;
|
|
m_BasicProps.iLevel = m_pMonEssence.Value.level;
|
|
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 & (int)PlayerNPCState.GP_STATE_NPC_NAME) == 0)
|
|
{
|
|
m_strName = Encoding.Unicode.GetString(MemoryMarshal.AsBytes<ushort>(m_pDBEssence.Value.name));
|
|
m_npcUI.SetName(m_strName);
|
|
}
|
|
|
|
transform.forward = EC_Utility.ToVector3(EC_Utility.glb_DecompressDirH(info.dir));
|
|
transform.position = EC_Utility.ToVector3(info.pos);
|
|
|
|
StartWork((int)WorkType.WT_NOTHING, (int)WorkID.WORK_STAND);
|
|
|
|
UpdateTaskIcon();
|
|
return true;
|
|
}
|
|
|
|
// Get way point ID bound with this NPC
|
|
public uint? GetWayPointID()
|
|
{
|
|
uint? dwID = 0;
|
|
if ((m_pDBEssence?.combined_services & 0x08) != 0)
|
|
dwID = m_pDBEssence?.id_to_discover;
|
|
|
|
return dwID;
|
|
}
|
|
|
|
// Get essence data in database
|
|
public NPC_ESSENCE? GetDBEssence() { return m_pDBEssence; }
|
|
|
|
// Get tax rate
|
|
public float GetTaxRate() { return m_fTaxRate; }
|
|
|
|
// Get item price scale factor
|
|
public float GetPriceScale()
|
|
{
|
|
return 1.0f + m_pDBEssence.Value.tax_rate;
|
|
}
|
|
}
|