You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
2.4 KiB
45 lines
2.4 KiB
using System;
|
|
using System.Configuration;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// This is a concrete, empty model for the sell state of the shop for you to implement. Technically this is the same as the buy model, as one inventory "buys" from the other.
|
|
/// Except the shop doesn't pay because we don't want it to run out of money!
|
|
/// </summary>
|
|
public class SellModel : ShopModel
|
|
{
|
|
private Inventory tradePartner;
|
|
public SellModel(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 SellModel(ShopObject pShopInitials, Inventory inventory = null) : this(pShopInitials.PriceModifier, 0, 0)
|
|
{
|
|
if (inventory != null) this.inventory = inventory;
|
|
}
|
|
|
|
//------------------------------------------------------------------------------------------------------------------------
|
|
// 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((int) (item.basePrice * priceModifier)); // We actually *add* the money to the player inventory...
|
|
OnRemove(item); // If there's a view subscribed, this will probably remove the item from it
|
|
inventory.RemoveItemByIndex(selectedItemIndex); // Before removing the item from the model's actual inventory
|
|
tradePartner?.AddItem(item); // Unlike the shop, we don't actually need a trade partner here. There might be shops that don't resell!
|
|
SelectItemByIndex(selectedItemIndex >= inventory.GetItemCount() ? --selectedItemIndex : selectedItemIndex);
|
|
}
|
|
|
|
public override void SetTradePartner(Inventory tradePartner)
|
|
{
|
|
this.tradePartner = tradePartner;
|
|
}
|
|
}
|
|
|