OldBlueWater/BlueWater/Assets/02.Scripts/Tycoon/KitchenController.cs
2024-04-23 02:52:54 +09:00

127 lines
3.9 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using UnityEngine.UI;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
public class KitchenController : MonoBehaviour
{
public int Onion { get; set; } = 10;
public int Scallion { get; set; } = 10;
public int Tomato { get; set; } = 10;
public int Wood { get; set; } = 10;
private bool isCooking;
public Image cookingProcess;
public GameObject[] sotSteamEff;
private float fireTimeRemaining = 0;
private Dictionary<string, Dictionary<string, int>> recipes = new ()
{
{ "KingCrab", new Dictionary<string, int>() { { "Onion", 1 }, { "Scallion", 1 }, { "Tomato", 1 } } }
};
private void Update()
{
if (fireTimeRemaining > 0)
{
fireTimeRemaining -= Time.deltaTime;
if (isCooking && cookingProcess.fillAmount > 0)
{
cookingProcess.fillAmount -= Time.deltaTime / 3; // 요리 시간 감소
if (cookingProcess.fillAmount <= 0)
{
CompleteCooking();
}
}
}
}
public void StartFire()
{
if (Wood > 0)
{
Wood--;
fireTimeRemaining += 10.0f;
if (!isCooking && CheckIngredients("KingCrab"))
{
isCooking = true;
cookingProcess.fillAmount = 1.0f;
StartCookingEffects();
}
}
}
private bool CheckIngredients(string recipeName)
{
if (recipes.ContainsKey(recipeName))
{
var recipe = recipes[recipeName];
if (Onion >= recipe["Onion"] && Scallion >= recipe["Scallion"] && Tomato >= recipe["Tomato"])
{
Onion -= recipe["Onion"];
Scallion -= recipe["Scallion"];
Tomato -= recipe["Tomato"];
return true;
}
}
return false;
}
private void StartCookingEffects()
{
foreach (var steamEffect in sotSteamEff)
{
steamEffect.SetActive(true);
}
}
private IEnumerator SotUpEffOff()
{
yield return new WaitForSeconds(2f);
foreach (var steamEffect in sotSteamEff)
{
steamEffect.SetActive(false);
}
}
private void CompleteCooking()
{
isCooking = false;
StartCoroutine(SotUpEffOff());
// 요리 완료 후 추가 로직 (음식 제공 등)
}
public void TakeFood()
{
var player = GameManager.Inst.TycoonPlayer;
if (!isCooking && cookingProcess.fillAmount == 0) // 조리가 완료되고 음식이 준비되었는지 확인
{
player.FoodVisual.sprite = DataManager.Inst.kingCrabMeat;
player.FoodTransform.gameObject.SetActive(true);
player.FoodOnHand = GlobalValue.Food.KING_CRAB;
ResetCookingProcess();
}
else
{
Debug.Log("음식이 준비되지 않았거나 이미 가져갔습니다.");
}
}
private void ResetCookingProcess()
{
// 요리 관련 변수 초기화
cookingProcess.fillAmount = 0;
isCooking = false; // 조리 상태 비활성화
fireTimeRemaining = 0; // 불 타는 시간 초기화
// 이펙트 비활성화
StartCoroutine(SotUpEffOff());
}
}
}