you can now sell Items with Right Mouse Click on an InventorySlot for the Item.SellPrice

and it gets put into the Shop for full price

renamed Item.cost to Item.price
This commit is contained in:
d-hain 2022-06-08 22:52:28 +02:00
parent 64b25a2029
commit ba9be3d96b
7 changed files with 50 additions and 13 deletions

View file

@ -1,11 +1,23 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
public class InventorySlot : ItemStorageSlot, IPointerClickHandler {
private Inventory _inventory;
private Shop _shop;
private PlayerController _playerController;
private void Start() {
_inventory = Inventory.instance;
_shop = Shop.instance;
_playerController = PlayerController.instance;
}
public class InventorySlot : ItemStorageSlot {
/**
* Gets called when the Inventory Slot is clicked
*/
public override void UseItem() {
if(Item){
if(Item) {
if(Item.GetType() == typeof(UsableItem)) {
((UsableItem)Item).Select();
Debug.Log("using " + Item.displayName);
@ -14,4 +26,25 @@ public class InventorySlot : ItemStorageSlot {
}
}
}
/**
* Sells the Item for the Item Sell Price and puts it in the Shop if the selling was a mistake
*/
private void SellItem() {
if(Item){
_playerController.ChangeMoney(Item.SellPrice);
_shop.AddItem(Item, 1);
_inventory.RemoveItem(Item, 1); // TODO: somehow sell more than 1 Item
}
}
/**
* Gets called when the Inventory Slot gets clicked on
*/
public void OnPointerClick(PointerEventData eventData) {
// When clicked on with right Mouse Button sell the Item
if(eventData.button == PointerEventData.InputButton.Right) {
SellItem();
}
}
}