From 4d751188bfe2a3f77d42f8a8fecbf75b1736d376 Mon Sep 17 00:00:00 2001 From: HungDK <> Date: Mon, 6 Apr 2026 16:03:41 +0700 Subject: [PATCH] Update NPCShopUIManager.cs --- .../Scripts/UI/NPCShopUIManager.cs | 76 +++++++++---------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/UI/NPCShopUIManager.cs b/Assets/PerfectWorld/Scripts/UI/NPCShopUIManager.cs index 94820c8658..78e4bb9a2b 100644 --- a/Assets/PerfectWorld/Scripts/UI/NPCShopUIManager.cs +++ b/Assets/PerfectWorld/Scripts/UI/NPCShopUIManager.cs @@ -391,47 +391,45 @@ public class NPCShopUIManager : AUIDialog // Initialize buy array with at least one option shopItem.buy = new GShopBuyOption[4]; // GShopItem supports up to 4 buy options - // Get item name and price based on type - string itemName = "Unknown"; - int shopPrice = 0; - - switch (itemDataType) + // Resolve display name/price in a type-agnostic way. + // Some element types come back as DATA_TYPE values we don't special-case here (arrows, flyswords, fashion, etc). + string itemName = EC_IvtrItemUtils.Instance.ResolveItemName(unchecked((int)good.id)); + if (string.IsNullOrWhiteSpace(itemName)) + itemName = $"Item_{good.id}"; + + static int ExtractInt(object data, params string[] fieldOrPropNames) { - case DATA_TYPE.DT_WEAPON_ESSENCE: - var weaponEssence = (WEAPON_ESSENCE)itemData; - itemName = weaponEssence.Name; - shopPrice = weaponEssence.shop_price; - break; - case DATA_TYPE.DT_ARMOR_ESSENCE: - var armorEssence = (ARMOR_ESSENCE)itemData; - itemName = armorEssence.Name; - shopPrice = armorEssence.shop_price; - break; - case DATA_TYPE.DT_MEDICINE_ESSENCE: - var medicineEssence = (MEDICINE_ESSENCE)itemData; - itemName = ByteToStringUtils.UshortArrayToUnicodeString(medicineEssence.name); - shopPrice = medicineEssence.shop_price; - break; - case DATA_TYPE.DT_DECORATION_ESSENCE: - var decorationEssence = (DECORATION_ESSENCE)itemData; - itemName = ByteToStringUtils.UshortArrayToUnicodeString(decorationEssence.name); - shopPrice = decorationEssence.shop_price; - break; - case DATA_TYPE.DT_STONE_ESSENCE: - var stoneEssence = (STONE_ESSENCE)itemData; - itemName = ByteToStringUtils.UshortArrayToUnicodeString(stoneEssence.name); - shopPrice = stoneEssence.shop_price; - break; - case DATA_TYPE.DT_MATERIAL_ESSENCE: - var materialEssence = (MATERIAL_ESSENCE)itemData; - itemName = ByteToStringUtils.UshortArrayToUnicodeString(materialEssence.name); - shopPrice = materialEssence.shop_price; - break; - default: - itemName = $"Item_{good.id}"; - break; + if (data == null || fieldOrPropNames == null || fieldOrPropNames.Length == 0) + return 0; + + var t = data.GetType(); + for (int i = 0; i < fieldOrPropNames.Length; i++) + { + string name = fieldOrPropNames[i]; + if (string.IsNullOrEmpty(name)) + continue; + + var field = t.GetField(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase); + if (field != null && field.FieldType == typeof(int)) + { + try { return (int)field.GetValue(data); } catch { } + } + + var prop = t.GetProperty(name, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase); + if (prop != null && prop.PropertyType == typeof(int) && prop.CanRead) + { + try { return (int)prop.GetValue(data); } catch { } + } + } + + return 0; } - + + // Prefer shop_price; fall back to base price if that's all we have. + int shopPrice = ExtractInt(itemData, "shop_price"); + if (shopPrice <= 0) + shopPrice = ExtractInt(itemData, "price"); + shopItem.name = itemName; // Set price from contribution cost or shop price