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 BrewMonster.Scripts { /// /// Arrow item class (cac loai mui ten) /// public class CECIvtrArrow : EC_IvtrEquip { protected IVTR_ESSENCE_ARROW m_Essence; // Arrow essence data // Data in database protected PROJECTILE_TYPE m_pDBType; protected PROJECTILE_ESSENCE m_pDBEssence; /// /// Arrow item class (cac loai mui ten) /// /// Template id /// Expire date public CECIvtrArrow(int tid, int expire_date) : base(tid, expire_date) { m_iCID = (int)InventoryClassId.ICID_ARROW; m_Essence = new IVTR_ESSENCE_ARROW(); // Get database data elementdataman pDB = ElementDataManProvider.GetElementDataMan(); DATA_TYPE DataType = DATA_TYPE.DT_INVALID; m_pDBEssence = (PROJECTILE_ESSENCE)pDB.get_data_ptr((uint)tid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType); m_pDBType = (PROJECTILE_TYPE)pDB.get_data_ptr((uint)m_pDBEssence.type, 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 = EC_IvtrType.EQUIP_MASK64_PROJECTILE; } public CECIvtrArrow(CECIvtrArrow other) : base(other) { m_pDBType = other.m_pDBType; m_pDBEssence = other.m_pDBEssence; m_Essence = other.m_Essence; } public override bool SetItemInfo(byte[] pInfoData, int iDataLen) { base.SetItemInfo(pInfoData, iDataLen); if (pInfoData == null || iDataLen == 0) return true; try { CECDataReader dr = new CECDataReader(pInfoData, iDataLen); // Skip equip requirements and endurance dr.Offset(5 * sizeof(int), CECDataReader.SEEK_CUR); int iEssenceSize = dr.ReadInt(); //ASSERT(iEssenceSize == sizeof (IVTR_ESSENCE_ARROW)); m_Essence = new IVTR_ESSENCE_ARROW(dr.ReadData(iEssenceSize)); } catch (Exception e) { Debug.LogError("CECIvtrArrow::SetItemInfo, data read error (" + e.GetType() + e.StackTrace + ")"); return false; } 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 } public IVTR_ESSENCE_ARROW GetEssence() { return m_Essence; } public PROJECTILE_TYPE GetDBSubType() { return m_pDBType; } // Get item description text protected override string GetNormalDesc(bool bRepair) { if (m_bNeedUpdate) return ""; // Build addon and refine properties and save it m_strDesc = ""; BuildAddOnPropDesc(null, null); string strAddon = m_strDesc; m_strDesc = ""; // Try to build item description CECStringTab pDescTab = EC_Game.GetItemDesc(); int white = (int)DescriptipionMsg.ITEMDESC_COL_WHITE; int namecol = DecideNameCol(); 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(); // Weapon requirement AddDescText(white, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_WEAPONREQ), m_Essence.iWeaponReqLow, m_Essence.iWeaponReqHigh, m_pDBType.Name); // Damage enhance if (m_pDBEssence.damage_enhance != 0) { AddDescText(-1, false, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_ADDPHYDAMAGE)); AddDescText(-1, true, " %+d", m_pDBEssence.damage_enhance); } // Add addon properties if (strAddon.Length > 0) m_strDesc += strAddon; // Price AddPriceDesc(white, bRepair); // Suite description AddSuiteDesc(); // Extend description AddExtDescText(); return m_strDesc; } // Get drop model for shown public override string GetDropModel() { return m_pDBEssence.FileMatter; } } }