2024-07-22 00:42:29 +00:00
|
|
|
using System;
|
2024-07-20 11:32:54 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using BlueWater.Items;
|
|
|
|
using BlueWater.Uis;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
|
|
namespace BlueWater.Tycoons
|
|
|
|
{
|
|
|
|
public class Cookware : InteractionFurniture
|
|
|
|
{
|
|
|
|
[FormerlySerializedAs("_cookGauge")]
|
|
|
|
[SerializeField, Required, BoxGroup("컴포넌트")]
|
|
|
|
protected TMP_Text CookGauge;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_fireWoodQuantity")]
|
|
|
|
[SerializeField, Required, BoxGroup("컴포넌트")]
|
|
|
|
protected TMP_Text FireWoodQuantity;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_foodQuantity")]
|
|
|
|
[SerializeField, Required, BoxGroup("컴포넌트")]
|
|
|
|
protected TMP_Text FoodQuantity;
|
|
|
|
|
|
|
|
[SerializeField, BoxGroup("컴포넌트")]
|
|
|
|
protected SpriteRenderer FireShader;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_currentDailyFoodUi")]
|
|
|
|
[SerializeField, BoxGroup("컴포넌트")]
|
|
|
|
protected TycoonItemSlotUi CurrentDailyFoodUi;
|
|
|
|
|
|
|
|
[SerializeField, Required, BoxGroup("데이터")]
|
|
|
|
protected CookwareDataSo CookwareDataSo;
|
|
|
|
|
|
|
|
[FormerlySerializedAs("_fireWoodIdx")]
|
|
|
|
[SerializeField, BoxGroup("데이터")]
|
|
|
|
protected int FireWoodIdx = 70001;
|
|
|
|
|
|
|
|
private Queue<FoodData> _cookedFoodDatas;
|
|
|
|
private int _currentFireWoodCount;
|
|
|
|
private float _currentCookGauge;
|
|
|
|
private float _startTime = float.PositiveInfinity;
|
|
|
|
private Vector3 _originFireShaderScale;
|
|
|
|
private int _previousFireWoodLevelIndex = -1;
|
|
|
|
|
|
|
|
protected override void OnEnable()
|
|
|
|
{
|
|
|
|
TycoonManager.Instance.OnTycoonOpenedEvent += OpenTycoonSwitch;
|
|
|
|
base.OnEnable();
|
|
|
|
}
|
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
CookGauge.enabled = false;
|
|
|
|
FireWoodQuantity.enabled = false;
|
|
|
|
FoodQuantity.enabled = false;
|
|
|
|
}
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
if (!IsOpened || CurrentDailyFoodUi.FoodData is null or { Idx : 0 }) return;
|
|
|
|
|
|
|
|
var level = _currentFireWoodCount / 5;
|
|
|
|
var currentFireWoodLevel = CookwareDataSo.FireWoodLevel[level];
|
|
|
|
|
|
|
|
if (FireShader && _previousFireWoodLevelIndex != level)
|
|
|
|
{
|
|
|
|
FireShader.transform.localScale = _originFireShaderScale * currentFireWoodLevel.FireScaleCoefficient;
|
|
|
|
_previousFireWoodLevelIndex = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 음식 게이지 관리 및 음식 생성
|
|
|
|
var currentFoodData = CurrentDailyFoodUi.FoodData;
|
|
|
|
if (_cookedFoodDatas.Count < currentFoodData.Plate)
|
|
|
|
{
|
|
|
|
_currentCookGauge += currentFireWoodLevel.CookGauge * Time.deltaTime;
|
|
|
|
if (_currentCookGauge >= currentFoodData.CookGauge)
|
|
|
|
{
|
|
|
|
_currentCookGauge = 0f;
|
|
|
|
_cookedFoodDatas.Enqueue(currentFoodData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 장작 관리
|
|
|
|
if (_currentFireWoodCount > 0)
|
|
|
|
{
|
|
|
|
if (float.IsPositiveInfinity(_startTime))
|
|
|
|
{
|
|
|
|
_startTime = Time.time;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Time.time >= _startTime + currentFireWoodLevel.BurnInterval)
|
|
|
|
{
|
|
|
|
_startTime = float.PositiveInfinity;
|
|
|
|
_currentFireWoodCount--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ui 표기
|
|
|
|
CookGauge.text = $"{(int)_currentCookGauge}/{currentFoodData.CookGauge}";
|
|
|
|
FireWoodQuantity.text = $"{_currentFireWoodCount}/{CookwareDataSo.MaxFireWoodQuantity}";
|
|
|
|
FoodQuantity.text = $"{_cookedFoodDatas?.Count ?? 0}/{currentFoodData.Plate}";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void InitializeComponents()
|
|
|
|
{
|
|
|
|
base.InitializeComponents();
|
|
|
|
|
|
|
|
if (FireShader)
|
|
|
|
{
|
|
|
|
_originFireShaderScale = FireShader.transform.localScale;
|
|
|
|
FireShader.enabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Interaction()
|
|
|
|
{
|
|
|
|
if (CurrentTycoonPlayer.IsCarriedItem())
|
|
|
|
{
|
|
|
|
var carriedItemData = CurrentTycoonPlayer.GetCurrentItemData();
|
|
|
|
if (carriedItemData.Idx == FireWoodIdx)
|
|
|
|
{
|
|
|
|
CurrentTycoonPlayer.GiveItem();
|
|
|
|
_currentFireWoodCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var foodData = _cookedFoodDatas.Dequeue();
|
|
|
|
CurrentTycoonPlayer.CarryItem(foodData.Idx, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool CanInteraction()
|
|
|
|
{
|
|
|
|
var isCarriedItem = CurrentTycoonPlayer.IsCarriedItem();
|
|
|
|
var isFullFireWood = _currentFireWoodCount >= CookwareDataSo.MaxFireWoodQuantity;
|
|
|
|
var isEmptyFoodData = CurrentDailyFoodUi is null or { FoodData : null };
|
|
|
|
var isEmptyFinishedFood = _cookedFoodDatas is null or { Count : <= 0 };
|
|
|
|
|
|
|
|
return IsOpened && !isEmptyFoodData && ((isCarriedItem && !isFullFireWood) || !isCarriedItem && !isEmptyFinishedFood);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void ShowInteractionUi()
|
|
|
|
{
|
|
|
|
if (!InteractionUi) return;
|
|
|
|
|
|
|
|
InteractionUi.gameObject.SetActive(true);
|
|
|
|
VisualLook.material = OutlineMaterial;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void HideInteractionUi()
|
|
|
|
{
|
|
|
|
if (!InteractionUi) return;
|
|
|
|
|
|
|
|
InteractionUi.gameObject.SetActive(false);
|
|
|
|
VisualLook.material = OriginalMaterial;
|
|
|
|
}
|
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
protected override void OpenTycoonSwitch()
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
|
|
|
if (CurrentDailyFoodUi.FoodData is not null and not { Idx : 0 })
|
|
|
|
{
|
2024-07-22 00:42:29 +00:00
|
|
|
CookGauge.enabled = true;
|
|
|
|
FireWoodQuantity.enabled = true;
|
|
|
|
FoodQuantity.enabled = true;
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
_cookedFoodDatas = new Queue<FoodData>(CurrentDailyFoodUi.FoodData.Plate);
|
|
|
|
_currentFireWoodCount = CookwareDataSo.StartFireWoodQuantity;
|
|
|
|
|
|
|
|
if (FireShader)
|
|
|
|
{
|
|
|
|
FireShader.enabled = true;
|
|
|
|
}
|
|
|
|
}
|
2024-07-22 00:42:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
CookGauge.enabled = false;
|
|
|
|
FireWoodQuantity.enabled = false;
|
|
|
|
FoodQuantity.enabled = false;
|
|
|
|
}
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
_currentCookGauge = 0;
|
2024-07-22 00:42:29 +00:00
|
|
|
base.OpenTycoonSwitch();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void ClosedTycoonSwitch()
|
|
|
|
{
|
|
|
|
CurrentDailyFoodUi.SetFoodData(null);
|
|
|
|
_cookedFoodDatas?.Clear();
|
|
|
|
|
|
|
|
if (FireShader)
|
|
|
|
{
|
|
|
|
FireShader.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CookGauge.enabled = false;
|
|
|
|
FireWoodQuantity.enabled = false;
|
|
|
|
FoodQuantity.enabled = false;
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-07-22 00:42:29 +00:00
|
|
|
base.ClosedTycoonSwitch();
|
2024-07-20 11:32:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|