From 8194937cd82c0fa8d3a1461a809da0cff90583ee Mon Sep 17 00:00:00 2001 From: BuyMyMojo Date: Wed, 1 Mar 2023 03:35:53 +1100 Subject: [PATCH] Add cutting progression AKA cutting multiple times --- .erp | 2 +- .../Cabbage-CabbageSlices.asset | 1 + .../CheeseBlock-CheeseSlices.asset | 1 + .../CuttingRecipeSO/Tomato-TomatoSlices.asset | 1 + Assets/Scripts/CuttingCounter.cs | 41 +++++++++++++------ Assets/Scripts/CuttingRecipeSO.cs | 1 + 6 files changed, 34 insertions(+), 13 deletions(-) diff --git a/.erp b/.erp index efda13f..21b774f 100644 --- a/.erp +++ b/.erp @@ -5,7 +5,7 @@ false false true - 1677615563 + 1677622826 8006271043655199372 false \ No newline at end of file diff --git a/Assets/ScriptableObjects/CuttingRecipeSO/Cabbage-CabbageSlices.asset b/Assets/ScriptableObjects/CuttingRecipeSO/Cabbage-CabbageSlices.asset index 888270c..a4934e8 100644 --- a/Assets/ScriptableObjects/CuttingRecipeSO/Cabbage-CabbageSlices.asset +++ b/Assets/ScriptableObjects/CuttingRecipeSO/Cabbage-CabbageSlices.asset @@ -14,3 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: input: {fileID: 11400000, guid: 9f464a107a41876499037959baa3da5f, type: 2} output: {fileID: 11400000, guid: 109b320dd13683c4abc574781815cbbd, type: 2} + cuttingProgressMax: 5 diff --git a/Assets/ScriptableObjects/CuttingRecipeSO/CheeseBlock-CheeseSlices.asset b/Assets/ScriptableObjects/CuttingRecipeSO/CheeseBlock-CheeseSlices.asset index e1dce03..32a4b6b 100644 --- a/Assets/ScriptableObjects/CuttingRecipeSO/CheeseBlock-CheeseSlices.asset +++ b/Assets/ScriptableObjects/CuttingRecipeSO/CheeseBlock-CheeseSlices.asset @@ -14,3 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: input: {fileID: 11400000, guid: 9a7cd1ad975e4124e9873832ba4af356, type: 2} output: {fileID: 11400000, guid: adbde85b933684c4992834e8bb9d893b, type: 2} + cuttingProgressMax: 3 diff --git a/Assets/ScriptableObjects/CuttingRecipeSO/Tomato-TomatoSlices.asset b/Assets/ScriptableObjects/CuttingRecipeSO/Tomato-TomatoSlices.asset index f14c9f6..33f0763 100644 --- a/Assets/ScriptableObjects/CuttingRecipeSO/Tomato-TomatoSlices.asset +++ b/Assets/ScriptableObjects/CuttingRecipeSO/Tomato-TomatoSlices.asset @@ -14,3 +14,4 @@ MonoBehaviour: m_EditorClassIdentifier: input: {fileID: 11400000, guid: 38de64e72d766a34c82d1ef83d41c98d, type: 2} output: {fileID: 11400000, guid: f00d7c6ba063ee6448dd26fac2bf4ce4, type: 2} + cuttingProgressMax: 3 diff --git a/Assets/Scripts/CuttingCounter.cs b/Assets/Scripts/CuttingCounter.cs index 6bbff0b..baef90b 100644 --- a/Assets/Scripts/CuttingCounter.cs +++ b/Assets/Scripts/CuttingCounter.cs @@ -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; + } } diff --git a/Assets/Scripts/CuttingRecipeSO.cs b/Assets/Scripts/CuttingRecipeSO.cs index 62971a2..2a249b2 100644 --- a/Assets/Scripts/CuttingRecipeSO.cs +++ b/Assets/Scripts/CuttingRecipeSO.cs @@ -8,5 +8,6 @@ public class CuttingRecipeSO : ScriptableObject public KitchenObjectSO input; public KitchenObjectSO output; + public int cuttingProgressMax; }