示例#1
0
        // Upon being enabled, this event will grant the player the specific object
        public override void EventOutcome()
        {
            if (itemToGive is ItemData)
            {
                // We add the new item to the player inventory.
                // Depending on the amount of said item, we will increment or decrement from the player's inventory.
                InventoryItem newItem = new InventoryItem((ItemData)itemToGive, quantity);
                if (Mathf.Sign(quantity) < 0)
                {
                    Debug.Log("Took away " + newItem.SpecifiedItem.itemName + " from player.");
                    playerInventory.RemoveItemFromInventory(newItem, quantity);
                }
                else
                {
                    Debug.Log("Gave player " + newItem.SpecifiedItem.itemName);
                    playerInventory.AddToInventory(newItem);
                }
                isFinished = true;
            }
            else if (itemToGive is GearData)
            {
                // We add the new gear to the inventory
                // Depending on the amount of said item, we will increment or decrement from the player's inventory.
                InventoryGear newGear = new InventoryGear((GearData)itemToGive, quantity);
                if (Mathf.Sign(quantity) < 0)
                {
                    Debug.Log("Took away " + newGear.SpecifiedGear.gearName + " from player.");
                    playerInventory.RemoveGearFromInventory(newGear, quantity);
                }
                else
                {
                    Debug.Log("Gave player " + newGear.SpecifiedGear.gearName);
                    playerInventory.AddToInventory(newGear);
                }
                isFinished = true;
            }
            else if (itemToGive is CharacterData)
            {
                // We add the new party member to the player's inventory
                InventoryParty newCharacter = new InventoryParty((CharacterData)itemToGive);
                Debug.Log("Added " + newCharacter.SpecifiedCharacter.characterName + " to party.");
                playerInventory.AddToInventory(newCharacter);
                isFinished = true;
            }
            else if (itemToGive is LinkData)
            {
                // We add the new link to the player's inventory
                InventoryLink newLink = new InventoryLink((LinkData)itemToGive);
                Debug.Log("Added " + newLink.SpecifiedLink.linkName + " to inventory.");
                playerInventory.AddToInventory(newLink);
                isFinished = true;
            }

            if (canResetItself == true)
            {
                Invoke("ResetEvent", 0.5f);
            }
        }
 public void AddToInventory(InventoryGear newGear)
 {
     foreach (InventoryGear currGear in listOfGear)
     {
         // If this gear already exists in the list, we update the quantity
         if (currGear.SpecifiedGear.Equals(newGear.SpecifiedGear))
         {
             currGear.Quantity += newGear.Quantity;
             return;
         }
     }
     // If we haven't found an existing one, we add it to the list
     listOfGear.Add(newGear);
 }
 // Like the aboe method, but this one takes a InventoryGear
 public bool RemoveGearFromInventory(InventoryGear specificGear, int quantity)
 {
     foreach (InventoryGear currGear in listOfGear)
     {
         // If this gear already exists in the list, we update the quantity
         if (currGear.SpecifiedGear.Equals(specificGear.SpecifiedGear))
         {
             currGear.Quantity -= quantity;
             if (currGear.Quantity <= 0)
             {
                 listOfGear.Remove(currGear);
             }
             return(true);
         }
     }
     return(false);
 }
        // Removes a specified gear piece from the inventory using its index
        // Returns true if it was able to do this
        public bool RemoveGearFromInventory(int gearIndex, int quantity)
        {
            if (gearIndex < listOfItems.Count && gearIndex >= 0)
            {
                InventoryGear currGear = listOfGear[gearIndex];

                if (currGear.Quantity - quantity < 0)
                {
                    listOfGear.Remove(currGear);
                }
                else
                {
                    currGear.Quantity -= quantity;
                }
                return(true);
            }
            return(false);
        }