Add cutting progression AKA cutting multiple times

This commit is contained in:
BuyMyMojo 2023-03-01 03:35:53 +11:00
parent 12d1640f38
commit 8194937cd8
6 changed files with 34 additions and 13 deletions

2
.erp
View file

@ -5,7 +5,7 @@
<resetOnSceneChange>false</resetOnSceneChange>
<debugMode>false</debugMode>
<EditorClosed>true</EditorClosed>
<LastTimestamp>1677615563</LastTimestamp>
<LastTimestamp>1677622826</LastTimestamp>
<LastSessionID>8006271043655199372</LastSessionID>
<Errored>false</Errored>
</ERPSettings>

View file

@ -14,3 +14,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
input: {fileID: 11400000, guid: 9f464a107a41876499037959baa3da5f, type: 2}
output: {fileID: 11400000, guid: 109b320dd13683c4abc574781815cbbd, type: 2}
cuttingProgressMax: 5

View file

@ -14,3 +14,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
input: {fileID: 11400000, guid: 9a7cd1ad975e4124e9873832ba4af356, type: 2}
output: {fileID: 11400000, guid: adbde85b933684c4992834e8bb9d893b, type: 2}
cuttingProgressMax: 3

View file

@ -14,3 +14,4 @@ MonoBehaviour:
m_EditorClassIdentifier:
input: {fileID: 11400000, guid: 38de64e72d766a34c82d1ef83d41c98d, type: 2}
output: {fileID: 11400000, guid: f00d7c6ba063ee6448dd26fac2bf4ce4, type: 2}
cuttingProgressMax: 3

View file

@ -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;
}
}

View file

@ -8,5 +8,6 @@ public class CuttingRecipeSO : ScriptableObject
public KitchenObjectSO input;
public KitchenObjectSO output;
public int cuttingProgressMax;
}