KitchenChaos/Assets/Scripts/DeliveryManager.cs

68 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using ScriptableObjects;
using UnityEngine;
using Random = UnityEngine.Random;
public class DeliveryManager : MonoBehaviour {
public static DeliveryManager Instance { get; private set; }
[SerializeField] private RecipeListSO recipeListSO;
private List<RecipeSO> waitingRecipeSOList;
private float spawnRecipeTimer;
private const float spawnRecipeTimerMax = 4f;
private const int waitingRecipesMax = 4;
private void Awake() {
Instance = this;
waitingRecipeSOList = new();
}
private void Update() {
spawnRecipeTimer -= Time.deltaTime;
if (spawnRecipeTimer <= 0f) {
spawnRecipeTimer = spawnRecipeTimerMax;
if (waitingRecipeSOList.Count < waitingRecipesMax) {
RecipeSO waitingRecipeSO = recipeListSO.recipeSOList[Random.Range(0, recipeListSO.recipeSOList.Count)];
Debug.Log(waitingRecipeSO.recipeName);
waitingRecipeSOList.Add(waitingRecipeSO);
}
}
}
public void DeliverRecipe(PlateKitchenObject plateKitchenObject) {
foreach (RecipeSO waitingRecipeSO in waitingRecipeSOList) {
if (waitingRecipeSO.kitchenObjectSOList.Count != plateKitchenObject.GetKitchenObjectSOList().Count) {
Debug.Log("Plate has the wrong number of ingredients!");
continue;
}
// Debug.Log("Has the same number of ingredients");
bool plateContentsMatchesRecipe = true;
foreach (KitchenObjectSO recipeKitchenObjectSO in waitingRecipeSO.kitchenObjectSOList) {
// Debug.Log("Cycling through all ingredients in the recipe");
bool ingredientFound = false;
foreach (KitchenObjectSO plateKitchenObjectSO in plateKitchenObject.GetKitchenObjectSOList()) {
// Debug.Log("Cycling through all ingredients on the plate");
if (plateKitchenObject != recipeKitchenObjectSO) {
Debug.Log($"Ingredient {plateKitchenObjectSO.objectName} DOES NOT match!");
continue;
}
Debug.Log($"Ingredient {plateKitchenObjectSO.objectName} matches");
ingredientFound = true;
break;
}
if (ingredientFound) continue;
Debug.Log($"This Recipe ingredient {recipeKitchenObjectSO.objectName} was not found on the plate!");
plateContentsMatchesRecipe = false;
}
if (!plateContentsMatchesRecipe) continue;
Debug.Log($"Player delievered a correct {waitingRecipeSO.recipeName}.");
waitingRecipeSOList.Remove(waitingRecipeSO);
return;
}
Debug.Log("Player did not deliver a correct recipe!");
}
}