Exemplo n.º 1
0
        public string AddItemNEW(int itemId)
        {
            if (inventorySpace.Value < inventorySpace.GetCap())
            {
                IItem item = ItemDBCache.GetItem(itemId);
                if (item != null)
                {
                    switch (item.Type)
                    {
                    case ItemType.Weapon:
                    case ItemType.Armor:
                        Inventories[ItemType.Armor].Add(item);
                        break;

                    case ItemType.Consumable:
                        Inventories[ItemType.Consumable].Add(item);
                        break;

                    case ItemType.Material:
                        Inventories[ItemType.Material].Add(item);
                        break;

                    default: throw new InvalidEnumArgumentException("Unknown itemType enum passed to ItemHolder::AddNewItem");
                    }
                    inventorySpace.PutOne();
                }
            }
            return(string.Format("+item {0}, slot {1}", ItemDBCache.GetItem(itemId).Name, inventorySpace.Value - 1));
        }
Exemplo n.º 2
0
        public ItemDBCache(ItemFactory itemFactory)
        {
            Instance     = this;
            _itemFactory = itemFactory;

            var items = PullFromDB();

            foreach (ItemDBEntry item in items)
            {
                var result = _itemFactory.BuildItem(item); //builds each dbItem from SQL data to be usable in game
                Items.Add(result.ItemId, result);          //adds built items to in-game dbItem cache
            }
        }
Exemplo n.º 3
0
        public ItemHolder(ItemDBCache itemDb)
        {
            Inventories = new Dictionary <ItemType, List <IItem> >
            {
                { ItemType.Armor, new List <IItem>() },
                { ItemType.Consumable, new List <IItem>() },
                { ItemType.Material, new List <IItem>() }
            };
            inventorySpace = CappedByte.Init(0, byte.MaxValue);


            _inventory          = new Dictionary <int, IItem>();
            _equipment          = new Dictionary <ItemSlot, IItem>();
            InventorySlots      = Enum.GetNames(typeof(ItemSlot)).Length;
            _usedInventorySlots = 0;
        }
Exemplo n.º 4
0
 public string AddItem(int itemId)
 {
     if (_usedInventorySlots < InventorySlots)
     {
         IItem item = ItemDBCache.GetItem(itemId);
         if (item != null)
         {
             if (item.Type == ItemType.Weapon || item.Type == ItemType.Armor)
             {
                 _inventory.Add(++_usedInventorySlots, item);
             }
             else
             {
             }
         }
     }
     return(string.Format("+item {0}, slot {1}", ItemDBCache.GetItem(itemId).Name, _usedInventorySlots));
 }
Exemplo n.º 5
0
        //for initial loading
        public void EquipItemOnRestore(int itemId)
        {
            if (!ItemDBCache.Items.ContainsKey(itemId))
            {
                return;
            }

            var item = ItemDBCache.GetItem(itemId);

            if (_equipment.ContainsKey(item.Slot))
            {
                _equipment[item.Slot] = item;
            }
            else
            {
                _equipment.Add(item.Slot, item);
            }
        }