// Filename : CECShopItemOwnerNPC.cs // Creator : Xu Wenbin // Date : 2013/12/11 // Converted to C#: 2024 using System; namespace PerfectWorld.Scripts.Shop { // 封装 GSHOP_ITEM 的挂靠 NPC 查询 / Encapsulates NPC ownership query for GSHOP_ITEM public class CECShopItemOwnerNPC { private const int TREASURE_ITEM_OWNER_NPC_COUNT = 8; private uint m_ownerNPCID; public CECShopItemOwnerNPC(uint ownerNPCID = 0) { m_ownerNPCID = ownerNPCID; } public void SetOwnerNPCID(uint ownerNPCID) { m_ownerNPCID = ownerNPCID; } public uint GetOwnerNPCID() { return m_ownerNPCID; } public bool IsEmpty() { return GetOwnerNPCID() == 0; } public bool Equals(CECShopItemOwnerNPC rhs) { return GetOwnerNPCID() == rhs.GetOwnerNPCID(); } public bool MatchID(uint id) { return id == m_ownerNPCID; } public bool MatchItem(GShopItem item) { if (IsEmpty()) { return !HasOwnerNPC(item); } bool result = false; if (item.ownerNpcs != null) { for (int i = 0; i < TREASURE_ITEM_OWNER_NPC_COUNT && i < item.ownerNpcs.Length; ++i) { if (MatchID(item.ownerNpcs[i])) { result = true; // 找到了 / Found break; } if (item.ownerNpcs[i] == 0) { break; // 已经到最后一个了,后面都是0 / Already reached the last one, rest are 0 } } } return result; } public static bool HasOwnerNPC(GShopItem item) { // 编辑器保证数组中,第一个是非零的在前 / Editor ensures that in the array, the first non-zero is at the front return item.ownerNpcs != null && item.ownerNpcs.Length > 0 && item.ownerNpcs[0] != 0; } } }