コード例 #1
0
 void InventoryChanged(InventoryChangedEvent e)
 {
     if (e.Id == _base.Inventory.Id)
     {
         UpdateInventory();
     }
 }
コード例 #2
0
    //Useful for removing items from the inventory. Calls for recalculate inventory map after compliting
    public void RemoveFromInventory(Point slot)
    {
        if (inventorySpace[slot.x, slot.y])
        {
            inventory.Remove(inventory.FirstOrDefault(z => z.LeftTopCornerCoordinate.x == slot.x && z.LeftTopCornerCoordinate.y == slot.y));
        }
        CheckSlots();

        if (InventoryChangedEvent != null)
        {
            InventoryChangedEvent.Invoke();
        }
    }
コード例 #3
0
ファイル: Inventory.cs プロジェクト: sergei201613/RPG
 public bool Add(Item item)
 {
     if (item.isDefaultItem)
     {
         return(true);
     }
     if (items.Count >= space)
     {
         Debug.Log("Not enough room.");
         return(false);
     }
     items.Add(item);
     InventoryChangedEvent?.Invoke();
     return(true);
 }
コード例 #4
0
    //Useful for adding items to the inventory. Checks for free slot, if there is one then it'll add it to the inventory collection.
    public void AddItemToInventory(InventoryItem item)
    {
        var slot = CheckForFreeSlot(item.Size);

        if (slot.x == -1 && slot.y == -1)
        {
            return;
        }
        item.LeftTopCornerCoordinate = slot;
        inventory.Add(item);
        CheckSlots();

        if (InventoryChangedEvent != null)
        {
            InventoryChangedEvent.Invoke();
        }
    }
コード例 #5
0
    /*
     * This method is used to equip item.
     * Slot - where will be that item equipped. For relation between numbers and slot types look to the Account.cs, Hero class
     * item - item that will be equipped.
     * TwoHanded - TwoHanded items have some special logic(checking if there is any off-hand which should be dropped to the inventory)
     * There is also some special logic for rings which is occupied number 7
     *
     * Base logic - check if there is any equipped item in that slot. If it is then drop swap it with item we want to equip. Calls for InventoryChanged event after completion
     */
    private void EquipItemToSlot(int slot, InventoryItem item, bool TwoHanded = false)
    {
        if (slot == 7)
        {
            InventoryItem equippedItem;
            if (Account.CurrentAccount.GetCurrentHero().EquippedItems[7] != null &&
                Account.CurrentAccount.GetCurrentHero().EquippedItems[8] == null)
            {
                item.LeftTopCornerCoordinate = new Point()
                {
                    x = -1, y = -1
                };
                Account.CurrentAccount.GetCurrentHero().EquippedItems[8] = item;
            }
            else
            {
                if (Account.CurrentAccount.GetCurrentHero().EquippedItems[7] != null)
                {
                    equippedItem = Account.CurrentAccount.GetCurrentHero().EquippedItems[7];
                    equippedItem.LeftTopCornerCoordinate = item.LeftTopCornerCoordinate;
                    inventory.Add(equippedItem);
                }
                item.LeftTopCornerCoordinate = new Point()
                {
                    x = -1, y = -1
                };
                Account.CurrentAccount.GetCurrentHero().EquippedItems[7] = item;
            }

            inventory.Remove(item);
        }
        else if (Account.CurrentAccount.GetCurrentHero().EquippedItems[slot] != null)
        {
            if (TwoHanded)
            {
                if (Account.CurrentAccount.GetCurrentHero().EquippedItems[12] != null &&
                    Account.CurrentAccount.GetCurrentHero().EquippedItems[12].Type != ItemType.Quiver)
                {
                    var freeSlot = CheckForFreeSlot(2);
                    if (freeSlot.x == -1 && freeSlot.y == -1)
                    {
                        return;
                    }
                    var equippedOffhand = Account.CurrentAccount.GetCurrentHero().EquippedItems[12];
                    equippedOffhand.LeftTopCornerCoordinate = freeSlot;
                    inventory.Add(equippedOffhand);
                    Account.CurrentAccount.GetCurrentHero().EquippedItems[12] = null;
                }
            }

            var equippedItem = Account.CurrentAccount.GetCurrentHero().EquippedItems[slot];
            equippedItem.LeftTopCornerCoordinate = item.LeftTopCornerCoordinate;
            item.LeftTopCornerCoordinate         = new Point {
                x = -1, y = -1
            };
            Account.CurrentAccount.GetCurrentHero().EquippedItems[slot] = item;
            inventory.Remove(item);
            inventory.Add(equippedItem);
        }
        else
        {
            item.LeftTopCornerCoordinate = new Point {
                x = -1, y = -1
            };
            Account.CurrentAccount.GetCurrentHero().EquippedItems[slot] = item;
            inventory.Remove(item);
        }

        CheckSlots();

        if (InventoryChangedEvent != null)
        {
            InventoryChangedEvent.Invoke();
        }
    }
コード例 #6
0
ファイル: Inventory.cs プロジェクト: sergei201613/RPG
 public void Remove(Item item)
 {
     items.Remove(item);
     InventoryChangedEvent?.Invoke();
 }