Cutting recipe logic

This commit is contained in:
BuyMyMojo 2023-03-01 02:34:47 +11:00
parent ccaed6e70d
commit 12d1640f38
5 changed files with 47 additions and 13 deletions

View file

@ -5,7 +5,7 @@ using UnityEngine;
public class CuttingCounter : BaseCounter
{
[SerializeField] private KitchenObjectSO cutKitchenObjectSO;
[SerializeField] private CuttingRecipeSO[] cuttingRecipeSOArray;
public override void Interact(Player player)
{
@ -15,7 +15,11 @@ public class CuttingCounter : BaseCounter
if (player.HasKitchenObject())
{
// player has object
player.GetKitchenObject().SetKitchenObjectParent(this);
if (HasRecipeWithInput(player.GetKitchenObject().GetKitchenObjectSO()))
{
// player is carrying an object that can be chopped
player.GetKitchenObject().SetKitchenObjectParent(this);
}
}
else
{
@ -39,12 +43,39 @@ public class CuttingCounter : BaseCounter
public override void InteractAlternate(Player player)
{
if (HasKitchenObject())
if (HasKitchenObject() && HasRecipeWithInput(GetKitchenObject().GetKitchenObjectSO()))
{
// there is a KitchenObject here
// there is a KitchenObject AND it is able to be cut
KitchenObjectSO outputKitchenSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());
GetKitchenObject().DestroySelf();
KitchenObject.SpawnKitchenObject(cutKitchenObjectSO, this);
KitchenObject.SpawnKitchenObject(outputKitchenSO, this);
}
}
private bool HasRecipeWithInput(KitchenObjectSO inputKitchenObjectSO)
{
foreach (CuttingRecipeSO cuttingRecipeSO in cuttingRecipeSOArray)
{
if (cuttingRecipeSO.input == inputKitchenObjectSO)
{
return true;
}
}
return false;
}
private KitchenObjectSO GetOutputForInput(KitchenObjectSO inputKitchenObjectSO)
{
foreach (CuttingRecipeSO cuttingRecipeSO in cuttingRecipeSOArray)
{
if (cuttingRecipeSO.input == inputKitchenObjectSO)
{
return cuttingRecipeSO.output;
}
}
return null;
}
}