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 { public class EC_IvtrFashion : EC_IvtrEquip { protected int m_iGender; // required gender protected ushort m_wColor; // color in X1R5G5B5 format protected uint m_color; // color in X8R8G8B8 format protected IVTR_ESSENCE_FASHION m_Essence; // Fashion essence data // Data in database protected FASHION_MAJOR_TYPE m_pDBMajorType; protected FASHION_SUB_TYPE m_pDBSubType; protected FASHION_ESSENCE m_pDBEssence; /// /// Not create logic yet (add summary later) /// /// Template id /// Expire date public EC_IvtrFashion(int tid, int expire_date) : base(tid, expire_date) { m_iCID = (int)InventoryClassId.ICID_FASHION; m_Essence = new IVTR_ESSENCE_FASHION(); // Get database data elementdataman pDB = ElementDataManProvider.GetElementDataMan(); DATA_TYPE DataType = DATA_TYPE.DT_INVALID; m_pDBEssence = (FASHION_ESSENCE)pDB.get_data_ptr((uint)tid, ID_SPACE.ID_SPACE_ESSENCE, ref DataType); m_pDBMajorType = (FASHION_MAJOR_TYPE)pDB.get_data_ptr(m_pDBEssence.id_major_type, ID_SPACE.ID_SPACE_ESSENCE, ref DataType); m_pDBSubType = (FASHION_SUB_TYPE)pDB.get_data_ptr(m_pDBEssence.id_sub_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_i64EquipMask = m_pDBSubType.equip_fashion_mask; m_iProcType = (int)m_pDBEssence.proc_type; // reset the info DefaultInfo(); } public EC_IvtrFashion(EC_IvtrFashion other) : base(other) { m_pDBEssence = other.m_pDBEssence; m_pDBMajorType = other.m_pDBMajorType; m_pDBSubType = other.m_pDBSubType; m_Essence = other.m_Essence; m_iGender = other.m_iGender; m_wColor = other.m_wColor; m_color = other.m_color; } // Set item detail information public override bool SetItemInfo(byte[] pInfoData, int iDataLen) { // Note: because fashion is not an absolute equipment, so skip // CECIvtrEquip::SetItemInfo(). if (pInfoData == null || iDataLen == 0) { m_bNeedUpdate = false; return true; } try { CECDataReader dr = new CECDataReader(pInfoData, iDataLen); var size = Marshal.SizeOf(); m_Essence = new IVTR_ESSENCE_FASHION(dr.ReadData(size)); } catch (Exception e) { Debug.LogError("CECIvtrFashion::SetItemInfo, data read error (" + e.GetType() + e.StackTrace + ")"); return false; } LevelReq = m_Essence.require_level; m_wColor = m_Essence.color; m_iGender = m_Essence.gender; m_color = (uint)FASHION_WORDCOLOR_TO_A3DCOLOR(m_wColor).GetHashCode(); m_bNeedUpdate = false; return true; } // Get item default information from database public override void DefaultInfo() { LevelReq = m_pDBEssence.require_level; m_wColor = 0x7fff; m_iGender = m_pDBEssence.gender; m_color = 0xffffffff; // these data also stored in essence, sync it here m_Essence.require_level = LevelReq; m_Essence.color = m_wColor; m_Essence.gender = (ushort)m_iGender; } public static Color FASHION_WORDCOLOR_TO_A3DCOLOR(ushort color) { return new Color(((color & (0x1f << 10)) >> 7), ((color & (0x1f << 5)) >> 2), ((color & 0x1f) << 3)); } public ushort GetWordColor() { return m_wColor; } public string GetSubTypeName() { // Try Unicode first (for Vietnamese/wide char names), then fallback to CP936 if (m_pDBSubType.name != null && m_pDBSubType.name.Length > 0) { string s = ByteToStringUtils.UshortArrayToUnicodeString(m_pDBSubType.name); if (!string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s)) return s; // Fallback to legacy CP936 if Unicode was empty s = ByteToStringUtils.UshortArrayToCP936String(m_pDBSubType.name); if (!string.IsNullOrEmpty(s)) return s; } return ""; } protected override string GetNormalDesc(bool bRepair) { if (m_bNeedUpdate) return ""; m_strDesc = ""; // Try to build item description CECStringTab pDescTab = EC_Game.GetItemDesc(); CECHostPlayer pHost = EC_Game.GetGameRun().GetHostPlayer(); int white = (int)DescriptipionMsg.ITEMDESC_COL_WHITE; int red = (int)DescriptipionMsg.ITEMDESC_COL_RED; int namecol = DecideNameCol(); // Item name AddDescText(namecol, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_NAME), GetName()); AddIDDescText(); AddBindDescText(); AddExpireTimeDesc(); // Sub class name AddDescText(white, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_CLASSNAME), GetSubTypeName()); // Color // Use m_iScaleType == SCALE_BUY to judge whether this item is in NPC's pack, // this may not be a valid way if (m_pDBEssence.equip_location != (int)enumSkinShow.enumSkinShowArmet && m_pDBEssence.equip_location != (int)enumSkinShow.enumSkinShowHand) { if (m_iScaleType == (int)EC_IvtrItem.ScaleType.SCALE_BUY) { AddDescText(white, false, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_COLOR)); AddDescText(white, true, (" ???")); } else { // Extract RGB components from m_color (X8R8G8B8 format) int colorRed = (int)((m_color >> 16) & 0xFF); int colorGreen = (int)((m_color >> 8) & 0xFF); int colorBlue = (int)(m_color & 0xFF); string szCol = string.Format("^{0:X2}{1:X2}{2:X2}", colorRed, colorGreen, colorBlue); AddDescText(white, false, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_COLOR)); m_strDesc += " "; AddDescText(-1, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_COLORRECT), szCol); } } // Level requirment if (LevelReq > 0) { int lcol = pHost.GetMaxLevelSofar() >= LevelReq ? white : red; AddDescText(lcol, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_LEVELREQ), LevelReq); } // fashion weapon profession requirment and weapon action type if (m_pDBEssence.equip_location == (int)enumSkinShow.enumSkinShowHand) { AddDescText(-1, true, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_LEVEL), m_pDBEssence.level); AddProfReqDesc(m_pDBEssence.character_combo_id); AddActionTypeDescText((int)m_pDBEssence.action_type); } // Gender requirement CECStringTab pFixMsg = EC_Game.GetFixedMsgs(); int col = (pHost.GetGender() == m_iGender) ? white : red; AddDescText(col, false, pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_GENDERREQ)); m_strDesc += " "; if (m_iGender == (int)GENDER.GENDER_MALE) AddDescText(col, true, pFixMsg.GetWideString((int)FixedMsg.FIXMSG_GENDER_MALE)); else AddDescText(col, true, pFixMsg.GetWideString((int)FixedMsg.FIXMSG_GENDER_FEMALE)); // Price AddPriceDesc(white, bRepair); // Fashion level if (m_pDBEssence.level > 0) { m_strDesc += "\\r"; m_strDesc += pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_COL_WHITE); for (int i=0; i < m_pDBEssence.level; i++) m_strDesc += pDescTab.GetWideString((int)DescriptipionMsg.ITEMDESC_PENTAGON); } // Extend description AddExtDescText(); return m_strDesc; } public bool HasRandomProp() { return false; } // Get drop model for shown public override string GetDropModel() { return m_pDBEssence.FileMatter; } public int GetFashionSuiteID() { Dictionary suiteEquipTab = EC_Game.GetSuiteEquipTab(); return suiteEquipTab.ContainsKey(TemplateId) ? suiteEquipTab[TemplateId] : 0; } } }