Ejemplo n.º 1
0
        /// <summary>
        /// Equips/Swaps the equipment.  This will check the types of equipment to send that Item and its stat to the player.
        /// </summary>
        public void UseEquipment(Item usedItem)
        {
            // Get the Character_Manager component.
            Character_Manager character = Character_Helper.GetPlayerManager().GetComponent <Character_Manager> ();

            // Get the Equipment component.
            Equipment equipment = character.GetComponentInChildren <Equipment> ();
            // Create a temp variable for our item that is swapped out by whatever we are currently equipping.
            Item swappedItem = null;

            // IF we have a weapon item,
            // ELSE IF we have a armour item,
            // ELSE IF we have a ring item,
            // ELSE IF we have a bracelet item,
            // ELSE we dont have an item to equip and we made an error somewhere as we should of not been in here.  One of the IF statements SHOULD work.
            if (usedItem.Type == "Weapon")
            {
                // Set the new weapon to the player while returning the old weapon (if the player wielded one).
                swappedItem = equipment.EquipWeapon(usedItem);
            }
            else if (usedItem.Type == "Armour")
            {
                // Set the new Armour to the player while returning the old Armour (if the player wearing one).
                swappedItem = equipment.EquipArmour(usedItem);
            }
            else if (usedItem.Type == "Ring")
            {
                // Set the new Ring to the player while returning the old Ring (if the player wearing one).
                swappedItem = equipment.EquipRing(usedItem);
            }
            else if (usedItem.Type == "Bracelet")
            {
                // Set the new Bracelet to the player while returning the old Bracelet (if the player wearing one).
                swappedItem = equipment.EquipBracelet(usedItem);
            }
            else
            {
                // Nothing we can equip so lets leave.
                Debug.Log("We entered the UseEquipment method but didnt equip anything.  Something isnt right with the labeling of the Types.");
                return;
            }

            // Loop the amount of times we have inventory spaces.
            for (int i = 0; i < defaultSlotAmount + extraInventorySlots; i++)
            {
                // IF the IDs match.
                if (items [i].ID == usedItem.ID)
                {
                    // IF we have an item being swapped out.
                    if (swappedItem != null)
                    {
                        // Add the swapped out equipped item to the inventory.
                        AddItem(swappedItem.ID, 1);
                    }
                    // Play the Pickup Sound.
                    Grid_Helper.soundManager.PlaySound(usedItem.UsedSound);
                    // Do not show the tooltip.
                    Grid_Helper.tooltip.DeactivateItemTooltip();
                    // Clear the inventory slot.
                    ClearSlotInInventory(i, slots [i].GetComponentInChildren <Item_Data> ().gameObject);
                    // Since we found a match lets get out of this loop.
                    break;
                }
            }
        }
Ejemplo n.º 2
0
        public void OnPointerUp(PointerEventData data)
        {
            // IF we Right Click so we can USE or EQUIP an item.
            if (item != null && data.button == PointerEventData.InputButton.Right && !data.dragging)
            {
                // Get the Player_Manager component.
                Player_Manager player = Character_Manager.GetPlayerManager().GetComponent <Player_Manager> ();
                // IF this item is a consumable,
                if (item.Type == "Consumable")
                {
                    // Add "usage" attributes associated with this item.  At this current time if you are looking at the demo we only add HP.
                    player.AddHealth((float)item.RestoreHP);
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    if (amount - 1 == 0)
                    {
                        // Clear the old slot.
                        GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                        // Destroy this gameobject as it holds no item.
                        Destroy(gameObject);
                        // Do not show the tooltip.
                        Grid.tooltip.Deactivate();
                        return;
                    }
                    --amount;
                    GetComponentInParent <Inventory>().slots [slotNumber].GetComponentInChildren <Text> ().text = amount.ToString();
                    return;
                }
                // IF this item is a piece of equipment, such as a Weapon, Armour, Ring or a Bracelet.
                if (item.Type == "Weapon" || item.Type == "Armour" || item.Type == "Ring" || item.Type == "Bracelet")
                {
                    // Get the Equipment component.
                    Equipment equipment = player.GetComponentInChildren <Equipment> ();
                    // Play the Pickup Sound.
                    Grid.soundManager.PlaySound(item.UsedSound);
                    Item swappedItem = null;
                    if (item.Type == "Weapon")
                    {
                        // Set the new weapon to the player while returning the old weapon (if the player wielded one).
                        swappedItem = equipment.EquipWeapon(item);
                    }
                    else if (item.Type == "Armour")
                    {
                        // Set the new Armour to the player while returning the old Armour (if the player wearing one).
                        swappedItem = equipment.EquipArmour(item);
                    }
                    else if (item.Type == "Ring")
                    {
                        // Set the new Ring to the player while returning the old Ring (if the player wearing one).
                        swappedItem = equipment.EquipRing(item);
                    }
                    else if (item.Type == "Bracelet")
                    {
                        // Set the new Bracelet to the player while returning the old Bracelet (if the player wearing one).
                        swappedItem = equipment.EquipBracelet(item);
                    }

                    // Remove this item from this List of Items.
                    GetComponentInParent <Inventory>().items [slotNumber] = new Item();
                    // IF we have an item being swapped out.
                    if (swappedItem != null)
                    {
                        // Add the swapped out equipped item to the inventory.
                        GetComponentInParent <Inventory>().AddItem(swappedItem.ID, 1);
                    }
                    // Do not show the tooltip.
                    Grid.tooltip.Deactivate();
                    // Destroy this item in the inventory list.
                    Destroy(gameObject);
                }
            }
        }