From d26c1fe607a88161e86db4dcc4679af3b4009a29 Mon Sep 17 00:00:00 2001 From: Janis Meister Date: Mon, 6 Mar 2023 15:52:26 +0100 Subject: [PATCH] d --- Assets/Scripts/Field/Field.cs | 23 ++++++++++++++-------- Assets/Scripts/Inventory.cs | 32 ++++++++++++++----------------- Assets/Scripts/Items/Crop.cs | 34 ++++++++++++++++++++++++++++++--- Assets/Scripts/Items/Harvest.cs | 11 ++++++++--- Assets/Scripts/Items/Item.cs | 29 +++++++++++++++++----------- Assets/Scripts/TimeManager.cs | 10 ++++++++++ 6 files changed, 96 insertions(+), 43 deletions(-) diff --git a/Assets/Scripts/Field/Field.cs b/Assets/Scripts/Field/Field.cs index b41ba56..0843bb3 100644 --- a/Assets/Scripts/Field/Field.cs +++ b/Assets/Scripts/Field/Field.cs @@ -52,6 +52,7 @@ public class Field : Building fieldController.GetComponent().SetField(this); TimeManager.OnDayChanged += DayInterval; + TimeManager.OnMonthChanged += MonthInterval; } public override void OnPlace() @@ -90,12 +91,18 @@ public class Field : Building state = FieldState.DEAD; else { - daysSincePlanted++; - if (daysSincePlanted >= crop.daysToGrow) - { - state = FieldState.HARVESTABLE; - } - SetSprite(crop.sprites[daysSincePlanted]); + // SetSprite(crop.Sprites[daysSincePlanted]); + } + } + } + + private void MonthInterval() + { + if (state == FieldState.GROWING) + { + if (crop.SeasonToHarvest == TimeManager.CurrentSeason) + { + state = FieldState.HARVESTABLE; } } } @@ -109,7 +116,7 @@ public class Field : Building daysSincePlanted = 0; state = FieldState.GROWING; crop = newCrop; - SetSprite(crop.sprites[0]); + SetSprite(crop.Sprites[0]); } else { @@ -122,7 +129,7 @@ public class Field : Building { if (state == FieldState.HARVESTABLE) { - FarmManager.Instance.HarvestInventory.Add(crop.harvest, size.x * size.y); + FarmManager.Instance.HarvestInventory.Add(crop.HarvestItem, size.x * size.y); state = FieldState.EMPTY; SetSprite(null); } diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs index e5d2c28..3df24e0 100644 --- a/Assets/Scripts/Inventory.cs +++ b/Assets/Scripts/Inventory.cs @@ -41,29 +41,25 @@ public class Inventory where TItem : Item { int remainingCount = count; - // check if the item is stackable - if (item.stackable) + // look for an existing stack of the same item in the inventory + for (int i = 0; i < items.Length; i++) { - - // look for an existing stack of the same item in the inventory - for (int i = 0; i < items.Length; i++) + InventoryItem invItem = items[i]; + if (invItem != null && invItem.item == item && invItem.count < maxStackSize) { - InventoryItem invItem = items[i]; - if (invItem != null && invItem.item == item && invItem.count < maxStackSize) + // add as many items as possible to the stack + int space = maxStackSize - invItem.count; + int toAdd = Mathf.Min(space, remainingCount); + invItem.count += toAdd; + remainingCount -= toAdd; + + // exit the loop if all items have been added + if (remainingCount == 0) { - // add as many items as possible to the stack - int space = maxStackSize - invItem.count; - int toAdd = Mathf.Min(space, remainingCount); - invItem.count += toAdd; - remainingCount -= toAdd; - // exit the loop if all items have been added - if (remainingCount == 0) - { - - return 0; - } + return 0; } + } } diff --git a/Assets/Scripts/Items/Crop.cs b/Assets/Scripts/Items/Crop.cs index 862c4da..e94692d 100644 --- a/Assets/Scripts/Items/Crop.cs +++ b/Assets/Scripts/Items/Crop.cs @@ -6,7 +6,35 @@ using System.Collections.Generic; [CreateAssetMenu(fileName = "Crop", menuName = "Harvestdale/Items/Crop", order = 0)] public class Crop : Item { - public int daysToGrow; - public List sprites = new List(); - public Harvest harvest; + [SerializeField] + private List sprites = new List(); + + [SerializeField] + private Harvest harvestItem; + + [SerializeField] + private Season seasonToPlant; + + [SerializeField] + private Season seasonToHarvest; + + public List Sprites + { + get { return sprites; } + } + + public Harvest HarvestItem + { + get { return harvestItem; } + } + + public Season SeasonToPlant + { + get { return seasonToPlant; } + } + + public Season SeasonToHarvest + { + get { return seasonToHarvest; } + } } \ No newline at end of file diff --git a/Assets/Scripts/Items/Harvest.cs b/Assets/Scripts/Items/Harvest.cs index 2207d0e..2551b4c 100644 --- a/Assets/Scripts/Items/Harvest.cs +++ b/Assets/Scripts/Items/Harvest.cs @@ -1,9 +1,14 @@ using UnityEngine; -using System; -using System.Collections; -using System.Collections.Generic; [CreateAssetMenu(fileName = "Harvest", menuName = "Harvestdale/Items/Harvest", order = 0)] public class Harvest : Item { + [SerializeField] + private int price; + + public int Price + { + get { return price; } + } + } \ No newline at end of file diff --git a/Assets/Scripts/Items/Item.cs b/Assets/Scripts/Items/Item.cs index 49cf86c..58b5fed 100644 --- a/Assets/Scripts/Items/Item.cs +++ b/Assets/Scripts/Items/Item.cs @@ -3,21 +3,28 @@ using UnityEngine; [CreateAssetMenu(fileName = "Item", menuName = "Harvestdale/Items/Item", order = 0)] public class Item : ScriptableObject { - public string uuid; - public string itemName; + [SerializeField] + private string uuid; - public Sprite sprite; + [SerializeField] + private string itemName; - [Tooltip("Tools will set this to false on Awake()")] - public bool stackable = true; - public int maxStackSize = 100; + [SerializeField] + private Sprite icon; - private void OnEnable() + public string UUID { - if (!stackable) - { - maxStackSize = 1; - } + get { return uuid; } + } + + public string ItemName + { + get { return itemName; } + } + + public Sprite Icon + { + get { return icon; } } } \ No newline at end of file diff --git a/Assets/Scripts/TimeManager.cs b/Assets/Scripts/TimeManager.cs index 2317556..cd67765 100644 --- a/Assets/Scripts/TimeManager.cs +++ b/Assets/Scripts/TimeManager.cs @@ -1,6 +1,14 @@ using UnityEngine; using System; +public enum Season +{ + SPRING = 1, + SUMMER = 2, + AUTUMN = 3, + WINTER = 4 +} + public class TimeManager : MonoBehaviour { public static Action OnMinuteChanged; @@ -16,6 +24,8 @@ public class TimeManager : MonoBehaviour public static int Month { get; private set; } public static int Year { get; private set; } + public static Season CurrentSeason => (Season)Month; + [SerializeField] [Range(.05f, 10f)] private float minuteToRealTime = .05f;