// 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); } }
// The actions that are taken when we are in the item context private void ItemMenuActions() { if (currentState == MenuStates.ITEM) { // We selected an item if (currentSubMenuState == SubMenuStates.HIDDEN) { // We first activate our menus, setting them to how they should look itemMenuObject.transform.GetChild(1).gameObject.SetActive(true); itemMenuObject.transform.GetChild(3).gameObject.SetActive(true); ChangeSelectedText(currentMenuIndex, -1); prevIndexMenus.Push(currentMenuIndex); // We then set up the logic for the sub menu that follows currentSubMenuState = SubMenuStates.SUB1; currentMenuIndex = 0; currentMenuParent = itemMenuObject.transform.GetChild(1).GetChild(0).GetChild(0); InitializeSubPartyMenu(); UpdateMenuContext(); ChangeSelectedText(currentMenuIndex, 0); } // We selected our target to use the item on else if (currentSubMenuState == SubMenuStates.SUB1) { // We peek into our stack to get the item we selected InventoryItem currItem = playerInventory.GetItemAtIndex(prevIndexMenus.Peek()); if (currItem.SpecifiedItem.itemType == ItemType.HEALTH) { if (playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).CurrentHealthPoints < playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).ReturnModdedStat("MaxHP")) { // We healed the player by the item amount playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).CurrentHealthPoints += currItem.SpecifiedItem.itemAmount; playerInventory.RemoveItemFromInventory(currItem, 1); UpdateMenuContext(); Debug.Log("Used " + currItem.SpecifiedItem.itemName); } else { itemMenuObject.transform.GetChild(2).GetComponentInChildren <TextMeshProUGUI>().text = "This character's HP is already full!"; } } else if (currItem.SpecifiedItem.itemType == ItemType.SP) { if (playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).CurrentHealthPoints < playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).ReturnModdedStat("MaxSP")) { // We healthed the player by the item amount playerInventory.GetInventoryCharacterAtIndex(currentMenuIndex).CurrentSkillPoints += currItem.SpecifiedItem.itemAmount; playerInventory.RemoveItemFromInventory(currItem, 1); UpdateMenuContext(); Debug.Log("Used " + currItem.SpecifiedItem.itemName); } else { itemMenuObject.transform.GetChild(2).GetComponentInChildren <TextMeshProUGUI>().text = "This character's SP is already full!"; } } // If we run out of this current item, we automatically return to the initial menu of selectng an item if (currItem.Quantity <= 0) { ReturnToPreviousOption(); UpdateMenuContext(); } } } }