Exemplo n.º 1
0
 public InventoryDisplay(SpriteBatch spriteBatch, EquipmentSystem equipmentSystem, InventoryComponent inventoryComponent, ToolbarComponent toolbarComponent)
 {
     _spriteBatch = spriteBatch;
     _equipmentSystem = equipmentSystem;
     _inventoryComponent = inventoryComponent;
     _toolbarComponent = toolbarComponent;
     _pixel = new Texture2D(_spriteBatch.GraphicsDevice, 1, 1);
     _pixel.SetData<Color>(new[] { Color.White });
 }
Exemplo n.º 2
0
 // addInventoryItem
 public void addInventoryItem(InventoryComponent inventoryComponent, ItemComponent item)
 {
     for (int i = 0; i < inventoryComponent.slots; i++)
     {
         if (!inventoryComponent.inventory.ContainsKey(i))
         {
             inventoryComponent.inventory.Add(i, item);
             return;
         }
     }
 }
Exemplo n.º 3
0
 // getInventorySlot
 public int getInventorySlot(InventoryComponent inventoryComponent, ItemComponent itemComponent)
 {
     foreach (KeyValuePair<int, ItemComponent> slotItemPair in inventoryComponent.inventory)
     {
         if (slotItemPair.Value == itemComponent)
         {
             return slotItemPair.Key;
         }
     }
     return -1;
 }
Exemplo n.º 4
0
        // getInventoryItem
        public ItemComponent getInventoryItem(InventoryComponent inventoryComponent, int i)
        {
            ItemComponent itemComponent;

            inventoryComponent.inventory.TryGetValue(i, out itemComponent);

            return itemComponent;
        }
Exemplo n.º 5
0
        // removeInventoryItem
        public void removeInventoryItem(InventoryComponent inventoryComponent, ItemComponent item)
        {
            int index = -1;
            foreach (KeyValuePair<int, ItemComponent> pair in inventoryComponent.inventory)
            {
                if (pair.Value == item)
                {
                    index = pair.Key;
                    break;
                }
            }

            if (index != -1)
            {
                inventoryComponent.inventory.Remove(index);
            }
        }
Exemplo n.º 6
0
        // Load player inventory
        public static void loadPlayerInventory()
        {
            XElement inventoryData = _playerData.Element("InventoryState");
            InventoryComponent inventoryComponent = new InventoryComponent(int.Parse(inventoryData.Attribute("slots").Value));
            EquipmentSystem equipmentSystem = _systemManager.getSystem(SystemType.Equipment) as EquipmentSystem;

            _entityManager.addComponent("global", PlayerSystem.PLAYER_ID, inventoryComponent);
            foreach (XElement itemStateData in inventoryData.Elements("ItemState"))
            {
                ItemDefinition itemDefinition = _itemManager.getItemDefinition(itemStateData.Attribute("item_uid").Value);
                ItemState itemState = new ItemState(
                    int.Parse(itemStateData.Attribute("quantity").Value),
                    float.Parse(itemStateData.Attribute("current_range_limit").Value),
                    false);
                ItemComponent itemComponent = new ItemComponent(itemDefinition, itemState, ResourceManager.getTexture(itemDefinition.inventoryTextureUid));

                equipmentSystem.addInventoryItem(inventoryComponent, itemComponent);
            }
        }