コード例 #1
0
    public void Equip(EquipableItem item)
    {
        if (Inventory.RemoveItem(item))
        {
            EquipableItem previousItem;
            if (EquipmentPanel.AddItem(item, out previousItem))
            {
                if (previousItem != null)
                {
                    Inventory.AddItem(previousItem);
                    previousItem.Unequip(this);
                    statPanel.UpdateStatValues();
                }
                item.Equip(this);
                statPanel.UpdateStatValues();

                if (item.equipmentType == EquipmentType.Weapon)
                {
                    string[] name = item.ItemName.Split(' ');
                    if (name[0] == "Sword" || name[0] == "Staff" || name[0] == "Bow")
                    {
                        player.SwapWeapons(name[0]);
                    }
                    else
                    {
                        player.SwapWeapons(name[1]);
                    }
                }
            }
            else
            {
                Inventory.AddItem(item);
            }
        }
    }
コード例 #2
0
ファイル: Hero.cs プロジェクト: madeer1331/InventorySystem
    public bool Equip(EquipableItem item)
    {
        if (item == null)
        {
            return(false);
        }

        switch (item.type)
        {
        default:
            Debug.Log("Hero doesnt know how to equip that");
            return(false);

        case EquipmentType.Accesorry:
            this.inventory.Add(accessory);
            accessory = item;
            accessory.Equip(this);
            break;

        case EquipmentType.Boots:
            this.inventory.Add(boots);
            boots = item;
            boots.Equip(this);
            break;

        case EquipmentType.Chest:
            this.inventory.Add(chest);
            chest = item;
            chest.Equip(this);
            break;

        case EquipmentType.Glove:
            this.inventory.Add(gloves);
            gloves = item;
            gloves.Equip(this);
            break;

        case EquipmentType.Helmet:
            this.inventory.Add(helmet);
            helmet = item;
            helmet.Equip(this);
            break;

        case EquipmentType.Weapon:
            this.inventory.Add(weapon);
            weapon = item;
            weapon.Equip(this);
            break;
        }
        if (OnChange != null)
        {
            Debug.Log("hero equipment changed");
            OnChange.Invoke(this);
        }
        return(true);
    }
コード例 #3
0
    private void swapItems(ItemSlot dropItem)
    {
        EquipableItem dragItem     = draggedSlot.Item as EquipableItem;
        EquipableItem dropSlotItem = dropItem.Item as EquipableItem;

        if (draggedSlot is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.UnEquip(this);
            }
            if (dropSlotItem != null)
            {
                dropSlotItem.Equip(this);
            }
        }

        if (dropItem is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.Equip(this);
            }
            if (dropSlotItem != null)
            {
                dropSlotItem.UnEquip(this);
            }
        }

        statPanel.UpdateStatValues();

        Item draggedItem       = draggedSlot.Item;
        int  draggedItemAmount = draggedSlot.Amount;

        draggedSlot.Item   = dropItem.Item;
        draggedSlot.Amount = dropItem.Amount;

        dropItem.Item   = draggedItem;
        dropItem.Amount = draggedItemAmount;

        Analytics.CustomEvent("Player swaps items ", new Dictionary <string, object>
        {
            { "item 1", dropItem.Item.itemName },
            { "item 2", draggedItem.itemName }
        });
    }
コード例 #4
0
 public void Equiping(EquipableItem itemSlot)
 {
     if (inventory.RemoveItem(itemSlot))
     {
         EquipableItem itemInSlot;
         if (equipmentPanel.AddItem(itemSlot, out itemInSlot))
         {
             if (itemInSlot != null)
             {
                 inventory.AddItem(itemInSlot);
                 itemInSlot.Unequip(this);
             }
             itemSlot.Equip(this);
         }
         else
         {
             Inventory.instance.AddItem(itemSlot);
         }
     }
 }
コード例 #5
0
 public void Equip(EquipableItem item)
 {
     if (inventory.RemoveItem(item))
     {
         EquipableItem previousItem;
         if (equipmentPanel.AddItem(item, out previousItem))
         {
             if (previousItem != null)
             {
                 inventory.AddItem(previousItem);
                 previousItem.Unequip(this);
                 statPanel.UpdateStatValues();
             }
             item.Equip(this);
             statPanel.UpdateStatValues();
         }
         else
         {
             inventory.AddItem(item);
         }
     }
 }
コード例 #6
0
    private void SwapItems(BaseItemSlot dropItemSlot)
    {
        EquipableItem dragItem = dragItemSlot.Item as EquipableItem;
        EquipableItem dropItem = dropItemSlot.Item as EquipableItem;

        if (dragItemSlot is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.Unequip(this);
            }
            if (dropItem != null)
            {
                dropItem.Equip(this);
            }
        }

        if (dropItemSlot is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.Equip(this);
            }
            if (dropItem != null)
            {
                dropItem.Unequip(this);
            }
        }
        statPanel.UpdateStatValues();

        Item draggedItem       = dragItemSlot.Item;
        int  draggedItemAmount = dragItemSlot.Amount;

        dragItemSlot.Item   = dropItemSlot.Item;
        dragItemSlot.Amount = dropItemSlot.Amount;

        dropItemSlot.Item   = draggedItem;
        dropItemSlot.Amount = draggedItemAmount;
    }
コード例 #7
0
    private void ItemDrop(ItemSlot itemSlot)
    {
        Debug.Log("trying");
        if (itemSlot.CanGetItem(draggedSlot.Item) && draggedSlot.CanGetItem(itemSlot.Item))
        {
        }
        EquipableItem dragItem = draggedSlot.Item as EquipableItem;
        EquipableItem dropItem = itemSlot.Item as EquipableItem;

        if (itemSlot is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.Unequip(this);
            }
            if (dropItem != null)
            {
                dropItem.Equip(this);
            }
        }
        if (draggedSlot is EquipmentSlot)
        {
            if (dragItem != null)
            {
                dragItem.Equip(this);
            }
            if (dropItem != null)
            {
                dropItem.Unequip(this);
            }
        }

        MainItems draggedItem = draggedSlot.Item;

        draggedSlot.Item = itemSlot.Item;
        itemSlot.Item    = draggedItem;
    }
コード例 #8
0
    private void Drop(ItemSlot dropItemSlot)
    {
        if (dragItemSlot == null)
        {
            return;
        }

        if (dropItemSlot.CanAddStacks(dragItemSlot.ItemGS))
        {
            int numAddableStacks = dropItemSlot.ItemGS.maxStack - dropItemSlot.Amount;
            int stacksToAdd      = Mathf.Min(numAddableStacks, dragItemSlot.Amount);

            dropItemSlot.Amount += stacksToAdd;
            dragItemSlot.Amount -= stacksToAdd;
        }

        else if (dropItemSlot.CanRecieveItem(dragItemSlot.ItemGS) && dragItemSlot.CanRecieveItem(dropItemSlot.ItemGS))
        {
            EquipableItem dragItem = dragItemSlot.ItemGS as EquipableItem;
            EquipableItem dropItem = dropItemSlot.ItemGS as EquipableItem;

            if (dragItemSlot is EquipmentSlot)
            {
                if (dragItem != null)
                {
                    dragItem.Unequip(this);
                }
                if (dropItem != null)
                {
                    dropItem.Equip(this);
                }
            }
            if (dropItemSlot is EquipmentSlot)
            {
                if (dragItem != null)
                {
                    dragItem.Equip(this);
                }
                if (dropItem != null)
                {
                    dropItem.Unequip(this);
                }
            }
            statPanel.UpdateStatValues();

            Items draggedItem       = dragItemSlot.ItemGS;
            int   draggedItemAmount = dragItemSlot.Amount;

            dragItemSlot.ItemGS = dropItemSlot.ItemGS;
            dragItemSlot.Amount = dropItemSlot.Amount;

            dropItemSlot.ItemGS = draggedItem;
            dropItemSlot.Amount = draggedItemAmount;

            if (dragItem.equipmentType == EquipmentType.Weapon)
            {
                string[] name = dragItem.ItemName.Split(' ');
                if (name[0] == "Sword" || name[0] == "Staff" || name[0] == "Bow")
                {
                    player.SwapWeapons(name[0]);
                }
                else
                {
                    player.SwapWeapons(name[1]);
                }
            }
            if (dragItem.equipmentType == EquipmentType.Gem)
            {
                string[] names = new string[3];
                for (int i = 5; i <= 7; i++)
                {
                    if (EquipmentPanel.EquipmentSlots[i].ItemGS != null)
                    {
                        names[i - 5] = EquipmentPanel.EquipmentSlots[i].ItemGS.ItemName;
                    }
                }
                player.SpellSelect(names);
            }
        }
    }