you can now undo a purchase after buying an item from the shop

This commit is contained in:
d-hain 2022-06-08 21:47:00 +02:00
parent efc7a3deaf
commit 64b25a2029
12 changed files with 359 additions and 56 deletions

View file

@ -14,4 +14,36 @@ public class Shop : ItemStorage {
}
#endregion
public bool itemWasBought;
private PlayerController _playerController;
private Inventory _inventory;
private Item _lastBoughtItem;
private int _lastBoughtItemAmount;
/**
* Calls ItemStorage.RemoveItem() and sets 2 Variables to remember the last bought item
*/
public override void RemoveItem(Item item, int amount) {
base.RemoveItem(item, amount);
if(itemWasBought){
_lastBoughtItem = item;
_lastBoughtItemAmount = amount;
}
}
public void UndoLastPurchase() {
if(itemWasBought){
_inventory = Inventory.instance;
_playerController = PlayerController.instance;
if(_lastBoughtItem) {
_playerController.ChangeMoney(_lastBoughtItem.cost);
_inventory.RemoveItem(_lastBoughtItem, _lastBoughtItemAmount);
AddItem(_lastBoughtItem, _lastBoughtItemAmount);
itemWasBought = false;
}
}
}
}