136 lines
3.5 KiB
C#
136 lines
3.5 KiB
C#
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
// This is a base class for all crops in the game. It is for the actual crop in the ground.
|
|
// It is not for the seeds that are planted or the harvested crops. (CropItem)
|
|
[CreateAssetMenu(fileName = "CropInteractable", menuName = "Game Data/Farming/Crop Interactable")]
|
|
public class CropInteractable : Interactable
|
|
{
|
|
// crop item
|
|
public CropItem cropItem;
|
|
public int currentGrowthStage;
|
|
|
|
// will need to change the sprite depending on the growth stage
|
|
public Sprite[] growthSprites;
|
|
public int growthStages;
|
|
|
|
public bool isWatered;
|
|
|
|
public bool lightRequirement;
|
|
|
|
public SeedItem seedItem;
|
|
|
|
// 1 = daily, 2 = every other day, 3 = every third day, etc. ?
|
|
public float waterRequirement;
|
|
|
|
// crop properties
|
|
public int yield;
|
|
|
|
public CropInteractable()
|
|
{
|
|
type = InteractableType.Crop;
|
|
}
|
|
|
|
public new void Awake()
|
|
{
|
|
id = GetInstanceID();
|
|
currentGrowthStage = 1;
|
|
isWatered = false;
|
|
type = InteractableType.Crop;
|
|
objectName = cropItem.itemName + " Crop";
|
|
}
|
|
|
|
public bool IsPlayerInInteractRange(Vector2 playerPosition, Vector2 itemPosition)
|
|
{
|
|
return Vector2.Distance(playerPosition, itemPosition) < interactRange;
|
|
}
|
|
|
|
public bool IsToolRequired()
|
|
{
|
|
// if there are not valid tools
|
|
if (validToolTypes == null || validToolTypes.Length == 0)
|
|
return false;
|
|
|
|
// also if one of the valid tool types is none then we dont need a tool
|
|
return !validToolTypes.Contains(ToolItem.ToolType.None);
|
|
}
|
|
|
|
public void OnEnter2D(Collider2D collider)
|
|
{
|
|
Debug.Log("Crop OnEnter2D");
|
|
}
|
|
|
|
public void OnExit2D(Collider2D collider)
|
|
{
|
|
Debug.Log("Crop OnExit2D");
|
|
}
|
|
|
|
public new void OnDayChange()
|
|
{
|
|
Debug.Log("Crop OnDayChange TRIGGERED");
|
|
|
|
Debug.Log("Crop: Name: " + cropItem.itemName + " Current growth stage: " + currentGrowthStage +
|
|
" Growth Stages: " +
|
|
growthStages);
|
|
// if (isWatered) {
|
|
// todo: add in water check for growth.
|
|
|
|
currentGrowthStage++;
|
|
if (currentGrowthStage >= growthStages)
|
|
currentGrowthStage = growthStages;
|
|
|
|
isWatered = false;
|
|
}
|
|
|
|
public new void OnInteract()
|
|
{
|
|
Debug.Log("Crop OnInteract");
|
|
if (IsHarvestable())
|
|
// harvest crop
|
|
Debug.Log("Harvesting crop");
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
Debug.Log("Crop Interact");
|
|
// 0. check if its ready to be harvested.
|
|
// 1. check to see if the player is in range to interact
|
|
// 2. check to see if this crop requires a tool and
|
|
// 2. check to see if the player has the correct tool equipped if required
|
|
|
|
// if the tool is a pickaxe - destroy the crop
|
|
// watering can - water the tile/crop
|
|
|
|
if (IsHarvestable())
|
|
// harvest crop
|
|
Debug.Log("Harvesting crop");
|
|
|
|
|
|
else
|
|
Debug.Log("Crop is not ready to harvest");
|
|
}
|
|
|
|
|
|
public bool IsHarvestable()
|
|
{
|
|
// if crop has no values
|
|
if (currentGrowthStage < growthStages)
|
|
{
|
|
Debug.Log("Crop is not ready to harvest");
|
|
return false;
|
|
}
|
|
|
|
Debug.Log("Crop is ready to harvest");
|
|
return true;
|
|
}
|
|
|
|
public void SetCropItem(CropItem item)
|
|
{
|
|
cropItem = item;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
Debug.Log("Crop Initialize");
|
|
}
|
|
} |