14 changed files with 163 additions and 8 deletions
@ -0,0 +1,13 @@ |
|||||
|
using System.Collections; |
||||
|
using System.Collections.Generic; |
||||
|
using UnityEngine; |
||||
|
|
||||
|
public class UpgradeModelComponent : ModelComponent |
||||
|
{ |
||||
|
[SerializeField] private ShopObject shop; |
||||
|
protected override void CreateModel() |
||||
|
{ |
||||
|
Debug.Assert(shop != null,"Shop model initial object never assigned!",this); |
||||
|
model = new UpgradeModel(shop); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: c0435c4334f16f74d9eb1c7fbd973641 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: -10 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
@ -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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: 32a48e31df172e24b8d2aa672369a274 |
||||
|
MonoImporter: |
||||
|
externalObjects: {} |
||||
|
serializedVersion: 2 |
||||
|
defaultReferences: [] |
||||
|
executionOrder: 0 |
||||
|
icon: {instanceID: 0} |
||||
|
userData: |
||||
|
assetBundleName: |
||||
|
assetBundleVariant: |
||||
Loading…
Reference in new issue