public void AddShopTradeNode(Item item, Item trade, int cost) { ShopBuyNode node = Instantiate(prefab, container.transform); node.SetTradeNode(item, trade, cost); tradeNodes.Add(node); }
public void SelectNode(ShopTradeNode node) { switch (buysellMode) { case ShopScreenMode.Buy: ShopBuyNode buyNode = (ShopBuyNode)node; if (currentPlayer.GetCurrency(buyNode.GetCurrency(), buyNode.GetCost())) { currentPlayer.Inventory.AddItemToInventory(ItemDatabase.NewItem(buyNode.GetOffer())); crystalCounter.SetCounter(currentPlayer.GetCurrencyCount(buyNode.GetCurrency())); } break; case ShopScreenMode.Sell: ShopSellNode sellNode = (ShopSellNode)node; int index = shopSellNodes.IndexOf(sellNode); InventorySlot slot = currentPlayer.Inventory.FindSlotForItem(sellNode.GetItemForSale()); if (slot != null) { Item sold = slot.GetOneItem(); if (sold != null) { for (int i = sellNode.GetValue(); i > 0; i--) { currentPlayer.Inventory.AddItemToInventory(ItemDatabase.NewItem(sellNode.GetCurrency())); } crystalCounter.SetCounter(currentPlayer.GetCurrencyCount(sellNode.GetCurrency())); currentNPC.npcWares.Add(sold); LoadInventories(); if (index == 0) { GamepadInputManager.instance.gamepadInputs[currentPlayer.mPlayerIndex].GetEventSystem().SetSelectedGameObject(sellButton); } else if (index == shopSellNodes.Count) { GamepadInputManager.instance.gamepadInputs[currentPlayer.mPlayerIndex].GetEventSystem().SetSelectedGameObject(shopSellNodes[index - 1].button.gameObject); } else { GamepadInputManager.instance.gamepadInputs[currentPlayer.mPlayerIndex].GetEventSystem().SetSelectedGameObject(shopSellNodes[index].button.gameObject); } } } break; } }
public void LoadInventories() { foreach (ShopBuyNode node in shopBuyNodes) { Destroy(node.gameObject); } shopBuyNodes.Clear(); if (currentNPC != null) { foreach (Item item in currentNPC.npcWares) { ShopBuyNode temp = Instantiate(buyPrefab, buyNodeContainer.transform); temp.SetTradeNode(ItemDatabase.NewItem(item), Resources.Load <Item>("Prototypes/Items/Elements/Blueium") as Item, item.GetValue()); shopBuyNodes.Add(temp); } } foreach (ShopSellNode node in shopSellNodes) { Destroy(node.gameObject); } shopSellNodes.Clear(); if (currentPlayer != null) { foreach (InventorySlot slot in currentPlayer.Inventory.slots) { if (!slot.IsEmpty() && slot.item.GetValue() > 0) { if (slot.item is Equipment equipment && equipment.isEquipped) { continue; } ShopSellNode temp = Instantiate(sellPrefab, sellNodeContainer.transform); temp.SetSellNode(slot.item, Resources.Load <Item>("Prototypes/Items/Elements/Blueium") as Item, slot.item.GetSellValue()); shopSellNodes.Add(temp); } } } }
public void NodeSelected(ShopBuyNode node) { }