Esempio n. 1
0
            public UniqueInfo this[ItemType itemType]
            {
                get
                {
                    switch (itemType)
                    {
                    case ItemType.Weapon:
                        return(weaponUniqueInfo);

                    case ItemType.Ornament:
                        return(ornamentUniqueInfo);

                    case ItemType.Consumable:
                        return(consumableUniqueInfo);
                    }
                    return(null);
                }
                set
                {
                    if (value == null)
                    {
                        return;
                    }

                    Type type = value.GetType();

                    if (type == typeof(UniqueInfo))
                    {
                        return;
                    }

                    if (type == typeof(WeaponUniqueInfo))
                    {
                        weaponUniqueInfo = value as WeaponUniqueInfo;
                    }
                    else if (type == typeof(OrnamentUniqueInfo))
                    {
                        ornamentUniqueInfo = value as OrnamentUniqueInfo;
                    }
                    else if (type == typeof(ConsumableUniqueInfo))
                    {
                        consumableUniqueInfo = value as ConsumableUniqueInfo;
                    }
                }
            }
Esempio n. 2
0
        /// <summary>
        /// 获取物品数据模版,如果不存在则创建后获取
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ItemData GetOrCreateItemTemplate(int itemId)
        {
            ItemData data;

            if (!m_ItemTemplates.TryGetValue(itemId, out data))
            {
                ItemInfo info = GetItemInfo(itemId);
                if (info == null)
                {
                    return(null);
                }

                data = new ItemData()
                {
                    itemId = info.id
                };

                switch (info.itemType)
                {
                case ItemType.Weapon:
                    WeaponUniqueInfo weapon = info.uniqueInfo as WeaponUniqueInfo;
                    data.durability = weapon.durability;
                    break;

                case ItemType.Ornament:
                    break;

                case ItemType.Consumable:
                    ConsumableUniqueInfo consumable = info.uniqueInfo as ConsumableUniqueInfo;
                    data.durability = consumable.stackingNumber == 1 ? consumable.amountUsed : consumable.stackingNumber;
                    break;

                default:
                    break;
                }

                m_ItemTemplates.Add(itemId, data);
            }
            return(data);
        }