public void DietySelected(MenuButton pressed) { // Find the diety with the name stored in button text, make the sacrifice to them Diety[] dieties = WorldManager.instance.GetDieties(); int selectedIdx = -1; for (int i = 0; i < dieties.Length; i++) { if (dieties[i].dietyName == pressed.text) { selectedIdx = i; break; } } // Found the diety, can make a sacrifice to them if (selectedIdx >= 0) { Inventory inventory = UI_base.GetOwner().GetInventory(); if (inventory == null) { Debug.Log("ERROR! UI_DietyMenu::DietySelected() Failed to find player inventory!"); return; } // Only make the actuall sacrifice if the item was actually found and removed from the inventory if (inventory.RemoveCraftingItem(itemName)) { dieties[selectedIdx].SacrificeMade(itemName); } } CloseMenu(); }
public override void OpenMenu() { base.OpenMenu(); // Build the options based on what the player currently has in their inventory options.Clear(); Player player = UI_base.GetOwner(); Inventory inv = player.GetInventory(); if (inv == null) { Debug.Log("ERROR! UI_SacrificeMenu::OpenMenu() Failed to find player inventory!"); return; } // Create an option button for each craftin item foreach (string item in inv.CraftingItems()) { int numOfItem = inv.GetNumOfCraftingItem(item); MenuButton btn = new MenuButton(item, SacrificeSelected); string itemEffect = WorldManager.instance.GetCraftingItemByName(item).effectText; btn.info = "x " + numOfItem + " : " + itemEffect; options.Add(btn); } }
public void TradeSelected(MenuButton pressed) { Inventory inventory = UI_base.GetOwner().GetInventory(); if (inventory == null) { Debug.Log("ERROR! UI_TradeMenu::TradeSelected() Failed to find player inventory!"); return; } string itemName = pressed.text; // get the trade option that was selected NPC.TradeOption tradeOption; if (trader.GetTradeOptionForItem(itemName, out tradeOption)) { // check that the inventory actually contains enough of the crafting item before removing them if (inventory.GetNumOfCraftingItem(itemName) >= tradeOption.numDesired) { inventory.RemoveCraftingItem(itemName, tradeOption.numDesired); // Give player the item UI_base.GetOwner().WearableItemAquired(tradeOption.returnItem); // only in this case, of a successful trade, does the menu close CloseMenu(); } } }