mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-29 12:52:07 +01:00
d
This commit is contained in:
@@ -52,6 +52,7 @@ public class Field : Building
|
|||||||
fieldController.GetComponent<FieldController>().SetField(this);
|
fieldController.GetComponent<FieldController>().SetField(this);
|
||||||
|
|
||||||
TimeManager.OnDayChanged += DayInterval;
|
TimeManager.OnDayChanged += DayInterval;
|
||||||
|
TimeManager.OnMonthChanged += MonthInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnPlace()
|
public override void OnPlace()
|
||||||
@@ -90,12 +91,18 @@ public class Field : Building
|
|||||||
state = FieldState.DEAD;
|
state = FieldState.DEAD;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
daysSincePlanted++;
|
// SetSprite(crop.Sprites[daysSincePlanted]);
|
||||||
if (daysSincePlanted >= crop.daysToGrow)
|
}
|
||||||
{
|
}
|
||||||
state = FieldState.HARVESTABLE;
|
}
|
||||||
}
|
|
||||||
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;
|
daysSincePlanted = 0;
|
||||||
state = FieldState.GROWING;
|
state = FieldState.GROWING;
|
||||||
crop = newCrop;
|
crop = newCrop;
|
||||||
SetSprite(crop.sprites[0]);
|
SetSprite(crop.Sprites[0]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -122,7 +129,7 @@ public class Field : Building
|
|||||||
{
|
{
|
||||||
if (state == FieldState.HARVESTABLE)
|
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;
|
state = FieldState.EMPTY;
|
||||||
SetSprite(null);
|
SetSprite(null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,29 +41,25 @@ public class Inventory<TItem> where TItem : Item
|
|||||||
{
|
{
|
||||||
int remainingCount = count;
|
int remainingCount = count;
|
||||||
|
|
||||||
// check if the item is stackable
|
// look for an existing stack of the same item in the inventory
|
||||||
if (item.stackable)
|
for (int i = 0; i < items.Length; i++)
|
||||||
{
|
{
|
||||||
|
InventoryItem<TItem> invItem = items[i];
|
||||||
// look for an existing stack of the same item in the inventory
|
if (invItem != null && invItem.item == item && invItem.count < maxStackSize)
|
||||||
for (int i = 0; i < items.Length; i++)
|
|
||||||
{
|
{
|
||||||
InventoryItem<TItem> invItem = items[i];
|
// add as many items as possible to the stack
|
||||||
if (invItem != null && invItem.item == item && invItem.count < maxStackSize)
|
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
|
return 0;
|
||||||
if (remainingCount == 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,35 @@ using System.Collections.Generic;
|
|||||||
[CreateAssetMenu(fileName = "Crop", menuName = "Harvestdale/Items/Crop", order = 0)]
|
[CreateAssetMenu(fileName = "Crop", menuName = "Harvestdale/Items/Crop", order = 0)]
|
||||||
public class Crop : Item
|
public class Crop : Item
|
||||||
{
|
{
|
||||||
public int daysToGrow;
|
[SerializeField]
|
||||||
public List<Sprite> sprites = new List<Sprite>();
|
private List<Sprite> sprites = new List<Sprite>();
|
||||||
public Harvest harvest;
|
|
||||||
|
[SerializeField]
|
||||||
|
private Harvest harvestItem;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private Season seasonToPlant;
|
||||||
|
|
||||||
|
[SerializeField]
|
||||||
|
private Season seasonToHarvest;
|
||||||
|
|
||||||
|
public List<Sprite> Sprites
|
||||||
|
{
|
||||||
|
get { return sprites; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Harvest HarvestItem
|
||||||
|
{
|
||||||
|
get { return harvestItem; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Season SeasonToPlant
|
||||||
|
{
|
||||||
|
get { return seasonToPlant; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Season SeasonToHarvest
|
||||||
|
{
|
||||||
|
get { return seasonToHarvest; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
[CreateAssetMenu(fileName = "Harvest", menuName = "Harvestdale/Items/Harvest", order = 0)]
|
[CreateAssetMenu(fileName = "Harvest", menuName = "Harvestdale/Items/Harvest", order = 0)]
|
||||||
public class Harvest : Item
|
public class Harvest : Item
|
||||||
{
|
{
|
||||||
|
[SerializeField]
|
||||||
|
private int price;
|
||||||
|
|
||||||
|
public int Price
|
||||||
|
{
|
||||||
|
get { return price; }
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -3,21 +3,28 @@ using UnityEngine;
|
|||||||
[CreateAssetMenu(fileName = "Item", menuName = "Harvestdale/Items/Item", order = 0)]
|
[CreateAssetMenu(fileName = "Item", menuName = "Harvestdale/Items/Item", order = 0)]
|
||||||
public class Item : ScriptableObject
|
public class Item : ScriptableObject
|
||||||
{
|
{
|
||||||
public string uuid;
|
[SerializeField]
|
||||||
public string itemName;
|
private string uuid;
|
||||||
|
|
||||||
public Sprite sprite;
|
[SerializeField]
|
||||||
|
private string itemName;
|
||||||
|
|
||||||
[Tooltip("Tools will set this to false on Awake()")]
|
[SerializeField]
|
||||||
public bool stackable = true;
|
private Sprite icon;
|
||||||
public int maxStackSize = 100;
|
|
||||||
|
|
||||||
|
|
||||||
private void OnEnable()
|
public string UUID
|
||||||
{
|
{
|
||||||
if (!stackable)
|
get { return uuid; }
|
||||||
{
|
}
|
||||||
maxStackSize = 1;
|
|
||||||
}
|
public string ItemName
|
||||||
|
{
|
||||||
|
get { return itemName; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sprite Icon
|
||||||
|
{
|
||||||
|
get { return icon; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,14 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
public enum Season
|
||||||
|
{
|
||||||
|
SPRING = 1,
|
||||||
|
SUMMER = 2,
|
||||||
|
AUTUMN = 3,
|
||||||
|
WINTER = 4
|
||||||
|
}
|
||||||
|
|
||||||
public class TimeManager : MonoBehaviour
|
public class TimeManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static Action OnMinuteChanged;
|
public static Action OnMinuteChanged;
|
||||||
@@ -16,6 +24,8 @@ public class TimeManager : MonoBehaviour
|
|||||||
public static int Month { get; private set; }
|
public static int Month { get; private set; }
|
||||||
public static int Year { get; private set; }
|
public static int Year { get; private set; }
|
||||||
|
|
||||||
|
public static Season CurrentSeason => (Season)Month;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Range(.05f, 10f)]
|
[Range(.05f, 10f)]
|
||||||
private float minuteToRealTime = .05f;
|
private float minuteToRealTime = .05f;
|
||||||
|
|||||||
Reference in New Issue
Block a user