Items adjusted prices
fixed some Tile sheeesh selling overflowing Items in Inventory (over 999)
This commit is contained in:
parent
79e86e343c
commit
cdd8ae7441
21 changed files with 106 additions and 84 deletions
|
|
@ -59,13 +59,13 @@ public class Crop {
|
|||
Debug.Log("Crop.Clicked UsableItem " + usableItem);
|
||||
if(usableItem != null) {
|
||||
ItemContainer ic = ItemContainer.Instance;
|
||||
if(ic.GetItemIdByName("Hoe") == usableItem.id) {
|
||||
if(ic.GetItemIdByName("Hoe") == usableItem.Id) {
|
||||
ApplyAction(Hoe);
|
||||
} else if(ic.GetItemIdByName("Scythe") == usableItem.id) {
|
||||
} else if(ic.GetItemIdByName("Scythe") == usableItem.Id) {
|
||||
ApplyAction(Scythe);
|
||||
} else if(ic.GetItemIdByName("Wheat Seeds") == usableItem.id) {
|
||||
} else if(ic.GetItemIdByName("Wheat Seeds") == usableItem.Id) {
|
||||
ApplyAction(Seeds);
|
||||
} else if(ic.GetItemIdByName("Watering Can") == usableItem.id) {
|
||||
} else if(ic.GetItemIdByName("Watering Can") == usableItem.Id) {
|
||||
ApplyAction(WateringCan);
|
||||
}
|
||||
}
|
||||
|
|
@ -111,6 +111,7 @@ public class Crop {
|
|||
}
|
||||
|
||||
private void AddCropToInventory() {
|
||||
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Wheat Seeds"), (int)(Random.Range(1,300)));
|
||||
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Wheat"), 1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Inventory : ItemStorage {
|
||||
|
|
@ -15,17 +16,28 @@ public class Inventory : ItemStorage {
|
|||
|
||||
#endregion
|
||||
|
||||
private const int _InventorySpace = 28;
|
||||
private const int InventorySpace = 28;
|
||||
private const int MaxItemStack = 999;
|
||||
|
||||
/**
|
||||
* Adds the specified amount of items to the Inventory
|
||||
*/
|
||||
public override void AddItem(Item item, int amount) {
|
||||
if(items.Count >= _InventorySpace) {
|
||||
if(items.Count >= InventorySpace) {
|
||||
Debug.Log("Not enough inventory space!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Sell overflowing Items
|
||||
if(items.ContainsKey(item) && items[item] + amount >= MaxItemStack) {
|
||||
SellItem(item, amount - (MaxItemStack - items[item]));
|
||||
amount = MaxItemStack - items[item];
|
||||
}
|
||||
base.AddItem(item, amount);
|
||||
}
|
||||
|
||||
public void SellItem(Item item, int amount) {
|
||||
PlayerController.instance.ChangeMoney(item.SellPrice);
|
||||
Shop.instance.AddItem(item, amount);
|
||||
RemoveItem(item, amount);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,8 @@ public class InventorySlot : ItemStorageSlot, IPointerClickHandler {
|
|||
* 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
|
||||
if(Item) {
|
||||
_inventory.SellItem(Item, 1); //TODO: wie machen mehr als 1 verkaufen?!
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ public class Item : ScriptableObject, IComparable<Item> {
|
|||
public Sprite defaultSprite;
|
||||
public int price;
|
||||
public int SellPrice => Convert.ToInt32(price * 0.8);
|
||||
ic int ID => _id;
|
||||
public int Id => _id;
|
||||
|
||||
public Item(string displayName, string description, int id) {
|
||||
this.displayName = displayName;
|
||||
|
|
|
|||
|
|
@ -48,6 +48,6 @@ public class ItemContainer : MonoBehaviour {
|
|||
}
|
||||
|
||||
public int GetItemIdByName(String name) {
|
||||
return GetItemByName(name).ID;
|
||||
return GetItemByName(name).Id;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ public class ItemStorageSlot : MonoBehaviour, IPointerEnterHandler, IPointerExit
|
|||
_item = null;
|
||||
icon.sprite = null;
|
||||
icon.enabled = false;
|
||||
amountText.text = "";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -2,43 +2,32 @@ using System;
|
|||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Tiles
|
||||
{
|
||||
public abstract class BaseTile
|
||||
{
|
||||
namespace Tiles {
|
||||
public abstract class BaseTile {
|
||||
private Sprite _sprite;
|
||||
public Sprite Sprite => _sprite;
|
||||
|
||||
protected GameObject _gameObject;
|
||||
|
||||
protected BaseTile(String pathToImageFile, GameObject gameObject)
|
||||
{
|
||||
this._gameObject = gameObject;
|
||||
this._sprite = GenerateSpriteFromFile(pathToImageFile);
|
||||
}
|
||||
|
||||
public void DayLightStep()
|
||||
protected BaseTile(String pathToImageFile, GameObject gameObject) {
|
||||
_gameObject = gameObject;
|
||||
_sprite = GenerateSpriteFromFile(pathToImageFile);
|
||||
HouseController.NewDayEvent.AddListener(DayLightStep);
|
||||
}
|
||||
|
||||
public virtual void DayLightStep()
|
||||
{
|
||||
|
||||
}
|
||||
public virtual void DayLightStep() { }
|
||||
|
||||
public virtual BaseTile Clicked(UsableItem usable)
|
||||
{
|
||||
public virtual BaseTile Clicked(UsableItem usable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public Sprite GenerateSpriteFromFile(String pathToImageFile)
|
||||
{
|
||||
static public Sprite GenerateSpriteFromFile(String pathToImageFile) {
|
||||
byte[] data = File.ReadAllBytes(pathToImageFile);
|
||||
Texture2D texture = new Texture2D(32, 32, TextureFormat.ARGB32, false);
|
||||
texture.LoadImage(data);
|
||||
Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 32);
|
||||
Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height),
|
||||
new Vector2(0.5f, 0.5f), 32);
|
||||
return sprite;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ namespace Tiles
|
|||
{
|
||||
public class GrassTile : BaseTile
|
||||
{
|
||||
public GrassTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png")
|
||||
public GrassTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png", gameObject)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -20,10 +20,10 @@ namespace Tiles
|
|||
if (usable != null)
|
||||
{
|
||||
base.Clicked(usable);
|
||||
if (usable.ID == ic.GetItemIdByName("Hoe")) {
|
||||
rv = new FarmlandTile();
|
||||
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new WaterTile();
|
||||
if (usable.Id == ic.GetItemIdByName("Hoe")) {
|
||||
rv = new FarmlandTile(_gameObject);
|
||||
} else if (usable.Id == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new WaterTile(_gameObject);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Tiles {
|
||||
public class WaterTile : BaseTile {
|
||||
public WaterTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_023.png") {
|
||||
public WaterTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_023.png", gameObject) {
|
||||
}
|
||||
|
||||
public override BaseTile Clicked(UsableItem usable) {
|
||||
|
|
@ -12,15 +12,15 @@ namespace Tiles {
|
|||
|
||||
ItemContainer ic = ItemContainer.Instance;
|
||||
|
||||
if (usable.ID == ic.GetItemIdByName("Fishing Rod")) {
|
||||
if (usable.Id == ic.GetItemIdByName("Fishing Rod")) {
|
||||
FishingController fc = FishingController.instance;
|
||||
if (!fc.Fishing) {
|
||||
fc.StartFishing();
|
||||
} else {
|
||||
fc.TryCatch();
|
||||
}
|
||||
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new GrassTile();
|
||||
} else if (usable.Id == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new GrassTile(_gameObject);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue