Add cutting progression AKA cutting multiple times
This commit is contained in:
parent
12d1640f38
commit
8194937cd8
6 changed files with 34 additions and 13 deletions
|
@ -7,6 +7,8 @@ public class CuttingCounter : BaseCounter
|
|||
|
||||
[SerializeField] private CuttingRecipeSO[] cuttingRecipeSOArray;
|
||||
|
||||
private int cuttingProgress;
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (!HasKitchenObject())
|
||||
|
@ -19,6 +21,7 @@ public class CuttingCounter : BaseCounter
|
|||
{
|
||||
// player is carrying an object that can be chopped
|
||||
player.GetKitchenObject().SetKitchenObjectParent(this);
|
||||
cuttingProgress = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -47,35 +50,49 @@ public class CuttingCounter : BaseCounter
|
|||
{
|
||||
// there is a KitchenObject AND it is able to be cut
|
||||
|
||||
KitchenObjectSO outputKitchenSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
cuttingProgress++;
|
||||
|
||||
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
GetKitchenObject().DestroySelf();
|
||||
if (cuttingProgress >= cuttingRecipeSO.cuttingProgressMax)
|
||||
{
|
||||
KitchenObjectSO outputKitchenSO = GetOutputForInput(GetKitchenObject().GetKitchenObjectSO());
|
||||
|
||||
KitchenObject.SpawnKitchenObject(outputKitchenSO, this);
|
||||
GetKitchenObject().DestroySelf();
|
||||
|
||||
KitchenObject.SpawnKitchenObject(outputKitchenSO, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool HasRecipeWithInput(KitchenObjectSO inputKitchenObjectSO)
|
||||
{
|
||||
foreach (CuttingRecipeSO cuttingRecipeSO in cuttingRecipeSOArray)
|
||||
{
|
||||
if (cuttingRecipeSO.input == inputKitchenObjectSO)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(inputKitchenObjectSO);
|
||||
return cuttingRecipeSO != null;
|
||||
}
|
||||
|
||||
private KitchenObjectSO GetOutputForInput(KitchenObjectSO inputKitchenObjectSO)
|
||||
{
|
||||
CuttingRecipeSO cuttingRecipeSO = GetCuttingRecipeSOWithInput(inputKitchenObjectSO);
|
||||
if (cuttingRecipeSO != null)
|
||||
{
|
||||
return cuttingRecipeSO.output;
|
||||
} else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private CuttingRecipeSO GetCuttingRecipeSOWithInput(KitchenObjectSO inputKitchenObjectSO)
|
||||
{
|
||||
foreach (CuttingRecipeSO cuttingRecipeSO in cuttingRecipeSOArray)
|
||||
{
|
||||
if (cuttingRecipeSO.input == inputKitchenObjectSO)
|
||||
{
|
||||
return cuttingRecipeSO.output;
|
||||
return cuttingRecipeSO;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,5 +8,6 @@ public class CuttingRecipeSO : ScriptableObject
|
|||
|
||||
public KitchenObjectSO input;
|
||||
public KitchenObjectSO output;
|
||||
public int cuttingProgressMax;
|
||||
|
||||
}
|
||||
|
|
Reference in a new issue