Files
test/Assets/PerfectWorld/Scripts/Managers/EC_IvtrItem/EC_IvtrPetFood.cs
T
2026-01-29 17:08:58 +07:00

153 lines
5.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using System.IO;
using BrewMonster;
using ModelRenderer.Scripts.Common;
using ModelRenderer.Scripts.GameData;
using UnityEngine;
using PerfectWorld.Scripts.Managers;
using BrewMonster.Network;
using BrewMonster.Scripts.Managers;
using BrewMonster.Scripts;
using CSNetwork.GPDataType;
using System.Runtime.InteropServices;
namespace PerfectWorld.Scripts.Managers
{
public class EC_IvtrPetFood : EC_IvtrItem
{
protected PET_FOOD_ESSENCE m_pDBEssence;
/// <summary>
/// Not create logic yet (add summary later)
/// </summary>
/// <param name="tid">Template id</param>
/// <param name="expire_date">Expire date</param>
public EC_IvtrPetFood(int tid, int expire_date) : base(tid, expire_date)
{
m_iCID = (int)InventoryClassId.ICID_PETFOOD;
// Get database data
elementdataman pDB = ElementDataManProvider.GetElementDataMan();
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
m_pDBEssence = (PET_FOOD_ESSENCE)pDB.get_data_ptr((uint)tid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
m_iPileLimit = m_pDBEssence.pile_num_max;
m_iPrice = m_pDBEssence.price;
m_iShopPrice = m_pDBEssence.shop_price;
m_iProcType = (int)m_pDBEssence.proc_type;
m_i64EquipMask = 0;
m_bUseable = true;
m_bNeedUpdate = false;
}
public EC_IvtrPetFood(EC_IvtrPetFood other) : base(other)
{
m_pDBEssence = other.m_pDBEssence;
}
public override bool SetItemInfo(byte[] pInfoData, int iDataLen)
{
base.SetItemInfo(pInfoData, iDataLen);
return true;
}
// Get item icon file name
public override string GetIconFile()
{
return m_pDBEssence.FileIcon;
}
// Get item name
public override string GetName()
{
// Try Unicode first (for Vietnamese/wide char names), then fallback to CP936
if (m_pDBEssence.name != null && m_pDBEssence.name.Length > 0)
{
string s = ByteToStringUtils.UshortArrayToUnicodeString(m_pDBEssence.name);
if (!string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s))
return s;
// Fallback to legacy CP936 if Unicode was empty
s = ByteToStringUtils.UshortArrayToCP936String(m_pDBEssence.name);
if (!string.IsNullOrEmpty(s))
return s;
}
return base.GetName(); // Fallback to base class method
}
// Get item cool time
public int GetCoolTime(ref int piMax)
{
CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer();
if (!pHost)
return 0;
int iTime = pHost.GetCoolTime((int)CoolTimeIndex.GP_CT_FEED_PET, out piMax);
return iTime;
}
// Check item use condition
public override bool CheckUseCondition()
{
CECPetData pPet = EC_Game.GetGameRun().GetHostPlayer().GetPetCorral().GetActivePet();
if (pPet == null)
return false;
DATA_TYPE DataType = DATA_TYPE.DT_INVALID;
object temp = ElementDataManProvider.GetElementDataMan().get_data_ptr((uint)pPet.GetTemplateID(), ID_SPACE.ID_SPACE_ESSENCE, ref DataType);
if (temp == null)
return false;
PET_ESSENCE pPetEssence = (PET_ESSENCE)temp;
return ((m_pDBEssence.food_type & pPetEssence.food_mask) != 0) ? true : false;
}
// Get item description text
protected override string GetNormalDesc(bool bRepair)
{
m_strDesc = "";
// Try to build item description
CECStringTab pDescTab = EC_Game.GetItemDesc();
int white = (int)DescriptipionMsg.ITEMDESC_COL_WHITE;
int namecol = DecideNameCol();
// Item name
if (m_iCount > 1)
AddDescText(namecol, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_NAMENUMBER), GetName(), m_iCount);
else
AddDescText(namecol, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_NAME), GetName());
AddIDDescText();
AddExpireTimeDesc();
// Food type
for (int i=0; i < (int)PetFoodType.MAX_PET_FOOD; i++)
{
if ((m_pDBEssence.food_type & (1 << i)) != 0)
{
AddDescText(white, false, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_FOODTYPE));
m_strDesc += " ";
AddDescText(-1, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_FOOD_GRASS+i));
break;
}
}
// Price
AddPriceDesc(white, bRepair);
// Extend description
AddExtDescText();
return m_strDesc;
}
// Get drop model for shown
public override string GetDropModel()
{
return m_pDBEssence.FileMatter;
}
}
}