private void BuyItem(IShopItemModel shopItemModel) { int itemLevel = inventory.GetItemLevel(shopItemModel); playerCurrency.Spend(CurrencyType.Gold, shopItemModel.GetGoldCost(itemLevel)); Debug.Log("Item " + shopItemModel.GetID() + " was bought"); }
public void PresentItem(IShopItemModel shopItemModel) { gameObject.SetActive(true); itemImage.sprite = shopItemModel.GetItemSprite(); var itemStatModel = shopItemModel.GetItemStats(); int itemLevel = inventory.GetItemLevel(shopItemModel); for (int i = 0; i < stats.Length; i++) { if (i < itemStatModel.Length) { stats[i].enabled = true; stats[i].PresentStat(shopItemModel, itemStatModel[i], itemLevel); } else { stats[i].enabled = false; } } var cost = shopItemModel.GetGoldCost(itemLevel); costAmountText.text = "Upgrade " + cost.ToString(); /// Move costAmountCoin depending on size of gold cost Debug.Log("Move costAmountCoin depending on size of gold cost"); upgradeButton.onClick.RemoveAllListeners(); upgradeButton.interactable = playerCurrency.CanAfford(CurrencyType.Gold, cost); if (upgradeButton.interactable) { upgradeButton.onClick.AddListener(delegate { BuyItem(shopItemModel); }); } }
internal void ShowItem(PlayerItemInventory inventory, PlayerItem playerItem, IShopItemModel itemModel) { this.inventory = inventory; item = playerItem; SetIsPicked(playerItem.isActiveItem); gameObject.SetActive(true); image.sprite = itemModel.GetItemSprite(); levelText.text = playerItem.itemLevel.ToString(); }
/// <summary> /// Returns item level /// </summary> /// <param name="shopItemModel"></param> /// <returns>Returns 0 if item is not unlocked</returns> internal int GetItemLevel(IShopItemModel shopItemModel) { if (items.ContainsKey(shopItemModel.GetID())) { return(items[shopItemModel.GetID()].itemLevel); } else { return(0); } }
internal void PresentStat(IShopItemModel itemModel, IShopItemStatModel shopItemStatModel, int itemLevel) { statText.text = shopItemStatModel.GetName(); statType.sprite = shopItemStatModel.GetStatSprite(); int currentAttributeLevel = itemModel.GetAttributeLevel(shopItemStatModel, itemLevel); int upgradeAttributeLevel = itemModel.GetAttributeLevel(shopItemStatModel, itemLevel + 1); for (int i = 0; i < statValues.Length; i++) { if (i < currentAttributeLevel) { ShowAsUnlockedAttribute(statValues[i]); } else if (i < upgradeAttributeLevel) { ShowAsUpgradeAttribute(statValues[i]); } else { ShowAsLockedAttribute(statValues[i]); } } }