evershade/Assets/Data/ScriptableObjects/World/CropInteractable.cs

126 lines
3.7 KiB
C#

using Types.Items;
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)
namespace Data.ScriptableObjects.World
{
[CreateAssetMenu(fileName = "CropInteractable", menuName = "Game Data/Farming/Crop Interactable")]
public class CropInteractable : Interactable
{
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;
// 1 = daily, 2 = every other day, 3 = every third day, etc. ?
public float waterRequirement;
// crop properties
public int yield;
// crop item
public CropItem CropItem;
public SeedItem SeedItem;
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 don need a tool
// return !validToolTypes.Contains(ToolItem.ToolType.None);
// }
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 it's 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
// harvest crop
Debug.Log(IsHarvestable() ? "Harvesting crop" : "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");
}
}
}