|
|
|
@ -0,0 +1,61 @@ |
|
|
|
using System; |
|
|
|
using System.Configuration; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The upgrade model differs a little from the other two. We do not care for a trade partner, only for ourselves.
|
|
|
|
/// On that note, we do use the price modifier to determine how expensive an upgrade is gonna be.
|
|
|
|
/// We do not upgrade by class, we merely improve the stats until it's no longer affordable. Self-balancing, right?
|
|
|
|
/// Still, upgrading a wooden sword to the point it's as good as a diamond sword (but 3x more expensive) technically does not make it more rare. Just impressive, really...
|
|
|
|
/// </summary>
|
|
|
|
public class UpgradeModel : ShopModel |
|
|
|
{ |
|
|
|
private float upgradeFactor; // How much would an upgrade improve stats?
|
|
|
|
public UpgradeModel(float pPriceModifier, int pItemCount, int pMoney) : base(pPriceModifier, pItemCount, pMoney) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Rather than modifying the whole class, we just reuse the existing stuff but don't make it create any items.
|
|
|
|
// This makes it less work to make proper functionality, without having to break any potential old functionality.
|
|
|
|
// Additionally, saves us work having to rip out the inventory's own ability to generate items.
|
|
|
|
// Edit: Nevermind, let's just allow setting the inventory in the constructor, for shared inventories between models!
|
|
|
|
public UpgradeModel(ShopObject pShopInitials, Inventory inventory = null) : this(pShopInitials.PriceModifier, 0, 0) |
|
|
|
{ |
|
|
|
if (inventory != null) this.inventory = inventory; |
|
|
|
upgradeFactor = pShopInitials.UpgradeFactor; |
|
|
|
} |
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
|
|
// ConfirmSelectedItem()
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//Currently it just removes the selected item from the shop's inventory, rewrite this function and don't forget the unit test.
|
|
|
|
|
|
|
|
public override void ConfirmSelectedItem() |
|
|
|
{ |
|
|
|
var item = GetSelectedItem(); |
|
|
|
inventory.ChangeBalance(-GetPriceForItem(item)); // Expensive upgrading!
|
|
|
|
// If no exception was thrown, we just assume we continue the upgrade!
|
|
|
|
item.Upgrade(upgradeFactor); |
|
|
|
triggerTransaction(); |
|
|
|
} |
|
|
|
|
|
|
|
public override void SetTradePartner(Inventory tradePartner) |
|
|
|
{ |
|
|
|
//this.tradePartner = tradePartner; No need!
|
|
|
|
} |
|
|
|
|
|
|
|
public override int GetPriceForItem(Item item) |
|
|
|
{ |
|
|
|
return (int) (item.GetUpgradeCosts(upgradeFactor) * priceModifier); |
|
|
|
} |
|
|
|
|
|
|
|
// This thing triggers transaction events for each upgrade!
|
|
|
|
private void triggerTransaction() |
|
|
|
{ |
|
|
|
foreach (var observer in observers) |
|
|
|
{ |
|
|
|
observer.OnTransaction(inventory.Money); |
|
|
|
} |
|
|
|
} |
|
|
|
} |