Add Delivery Manager logic and random recipe request generation
This commit is contained in:
parent
7e1cbafa47
commit
8c5f4f2acf
21 changed files with 360 additions and 13 deletions
|
@ -11,6 +11,8 @@ public class DeliveryCounter : BaseCounter
|
|||
if (player.GetKitchenObject().TryGetPlate(out PlateKitchenObject plateKitchenObject))
|
||||
{
|
||||
// only takes plate objects
|
||||
DeliveryManager.Instance.DeliverRecipe(plateKitchenObject);
|
||||
|
||||
player.GetKitchenObject().DestroySelf();
|
||||
}
|
||||
}
|
||||
|
|
95
Assets/Scripts/DeliveryManager.cs
Normal file
95
Assets/Scripts/DeliveryManager.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeliveryManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static DeliveryManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private RecipeListSO recipeListSO;
|
||||
|
||||
private List<RecipeSO> waitingRecipeSOList;
|
||||
private float spawnRecipeTimer;
|
||||
private float spawnRecipeTimerMax = 4f;
|
||||
private int waitingRecipesMax = 4;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
waitingRecipeSOList = new List<RecipeSO>();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
for (int i=0; i < waitingRecipeSOList.Count; ++i)
|
||||
{
|
||||
RecipeSO waitingRecipeSO = waitingRecipeSOList[i];
|
||||
|
||||
if (waitingRecipeSO.kitchenObjectSoList.Count == plateKitchenObject.GetKitchenObjectSOList().Count)
|
||||
{
|
||||
// Has equal ingreedients on plate
|
||||
|
||||
bool plateContentsMatchesRecipe = true;
|
||||
|
||||
foreach (KitchenObjectSO recipeKitchenObjectSO in waitingRecipeSO.kitchenObjectSoList)
|
||||
{
|
||||
// Cycle through all ingreedients within recipe
|
||||
|
||||
bool ingreedientFound = false;
|
||||
|
||||
foreach (KitchenObjectSO plateKitchenObjectSO in plateKitchenObject.GetKitchenObjectSOList())
|
||||
{
|
||||
// Cycle through all ingreedients within plate
|
||||
if (plateKitchenObjectSO == recipeKitchenObjectSO)
|
||||
{
|
||||
// Ingreedient matches!
|
||||
ingreedientFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ingreedientFound)
|
||||
{
|
||||
// This Recipe ingreedient was not on plate
|
||||
plateContentsMatchesRecipe = false;
|
||||
}
|
||||
|
||||
if (plateContentsMatchesRecipe)
|
||||
{
|
||||
// Player delivered correct recipe
|
||||
Debug.Log("Player delivered a recipe from the waiting list!");
|
||||
|
||||
waitingRecipeSOList.RemoveAt(i);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No matches found!
|
||||
// Player brought the wrong recipe!
|
||||
Debug.Log("Player brought the wrong recipe!");
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/DeliveryManager.cs.meta
Normal file
11
Assets/Scripts/DeliveryManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1debfee2f418c744e8ab7d25885ef70a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
10
Assets/Scripts/ScriptableObjects/RecipeListSO.cs
Normal file
10
Assets/Scripts/ScriptableObjects/RecipeListSO.cs
Normal file
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
// Commented out for saftey. There should only be one master list of valid recipes.
|
||||
// [CreateAssetMenu()]
|
||||
public class RecipeListSO : ScriptableObject
|
||||
{
|
||||
public List<RecipeSO> recipeSOList;
|
||||
}
|
11
Assets/Scripts/ScriptableObjects/RecipeListSO.cs.meta
Normal file
11
Assets/Scripts/ScriptableObjects/RecipeListSO.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 46220a004a45c204795d21699178fcd2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
12
Assets/Scripts/ScriptableObjects/RecipeSO.cs
Normal file
12
Assets/Scripts/ScriptableObjects/RecipeSO.cs
Normal file
|
@ -0,0 +1,12 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class RecipeSO : ScriptableObject
|
||||
{
|
||||
|
||||
public List<KitchenObjectSO> kitchenObjectSoList;
|
||||
public string recipeName;
|
||||
|
||||
}
|
11
Assets/Scripts/ScriptableObjects/RecipeSO.cs.meta
Normal file
11
Assets/Scripts/ScriptableObjects/RecipeSO.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cd1640ffe24e9eb469a834432b0eaf46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in a new issue