Animals can now be bought in AnimalShop
if bought they will be placed somewhere random on the map
This commit is contained in:
parent
acd602c85a
commit
441ffb900a
34 changed files with 2387 additions and 265 deletions
53
Assets/Scripts/Shop/ItemShop.cs
Normal file
53
Assets/Scripts/Shop/ItemShop.cs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Shop {
|
||||
|
||||
|
||||
public class ItemShop : ElementStorage<Item> {
|
||||
#region Singleton
|
||||
|
||||
public static ItemShop instance;
|
||||
|
||||
private void Awake() {
|
||||
if(instance != null) {
|
||||
Debug.LogWarning("More than one instance of ItemShop found");
|
||||
}
|
||||
|
||||
instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool itemWasBought;
|
||||
|
||||
private PlayerController _playerController;
|
||||
private Inventory _inventory;
|
||||
private Item _lastBoughtItem;
|
||||
private int _lastBoughtItemAmount;
|
||||
|
||||
/**
|
||||
* Calls ElementStorage.RemoveItem() and sets 2 Variables to remember the last bought item
|
||||
*/
|
||||
public override void RemoveElement(Item item, int amount) {
|
||||
base.RemoveElement(item, amount);
|
||||
if(itemWasBought) {
|
||||
_lastBoughtItem = item;
|
||||
_lastBoughtItemAmount = amount;
|
||||
}
|
||||
}
|
||||
|
||||
public void UndoLastPurchase() {
|
||||
if(itemWasBought) {
|
||||
_inventory = Inventory.instance;
|
||||
_playerController = PlayerController.instance;
|
||||
|
||||
if(_lastBoughtItem) {
|
||||
_playerController.ChangeMoney(_lastBoughtItem.price);
|
||||
_inventory.RemoveElement(_lastBoughtItem, _lastBoughtItemAmount);
|
||||
AddElement(_lastBoughtItem, _lastBoughtItemAmount);
|
||||
itemWasBought = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue