137 lines
4.5 KiB
C#
137 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using BlueWater.Items;
|
|
using BlueWater.Uis;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public class Pot : InteractionFurniture
|
|
{
|
|
[SerializeField, Required]
|
|
private PotDataSo _potDataSo;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _cookGauge;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _fireWoodQuantity;
|
|
|
|
[SerializeField, Required]
|
|
private TMP_Text _foodQuantity;
|
|
|
|
// TODO : 추후에 다시 활성화 하는 기능 필요
|
|
[SerializeField]
|
|
private bool _isOpened;
|
|
|
|
[SerializeField]
|
|
private int _fireWoodIdx = 70001;
|
|
|
|
[Title("실시간 데이터")]
|
|
[SerializeField]
|
|
private TycoonItemSlotUi _currentDailyFoodUi;
|
|
|
|
private Queue<FoodData> _cookedFoodDatas = new();
|
|
private int _currentFireWoodCount;
|
|
private float _currentCookGauge;
|
|
private float _startTime = float.PositiveInfinity;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
TycoonManager.Instance.OnTycoonOpenedEvent += OpenTycoonSwitch;
|
|
base.OnEnable();
|
|
|
|
_currentDailyFoodUi = TycoonUiManager.Instance.TycoonManagementUi.CookMenuUi.DailyFoodMenuUi.InitializePot(this);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!_isOpened) return;
|
|
|
|
var level = _currentFireWoodCount / 5;
|
|
var currentFireWoodLevel = _potDataSo.FireWoodLevel[level];
|
|
|
|
// 음식 게이지 관리 및 음식 생성
|
|
var currentFoodData = _currentDailyFoodUi.FoodData;
|
|
if (currentFoodData != null && currentFoodData.Idx != 0 && _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 ?? 0}";
|
|
_fireWoodQuantity.text = $"{_currentFireWoodCount}/{_potDataSo.MaxFireWoodCount}";
|
|
_foodQuantity.text = $"{_cookedFoodDatas.Count}/{currentFoodData?.Plate ?? 0}";
|
|
}
|
|
|
|
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, ItemQuality.None);
|
|
}
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
var isCarriedItem = CurrentTycoonPlayer.IsCarriedItem();
|
|
var isFullFireWood = _currentFireWoodCount >= _potDataSo.MaxFireWoodCount;
|
|
var isEmptyCookedFood = _currentDailyFoodUi.FoodData == null || _cookedFoodDatas.Count <= 0;
|
|
|
|
return _isOpened && ((isCarriedItem && !isFullFireWood) || !isCarriedItem && !isEmptyCookedFood);
|
|
}
|
|
|
|
public override void ShowInteractionUi()
|
|
{
|
|
if (!InteractionUi) return;
|
|
|
|
InteractionUi.gameObject.SetActive(true);
|
|
}
|
|
|
|
public override void HideInteractionUi()
|
|
{
|
|
if (!InteractionUi) return;
|
|
|
|
InteractionUi.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void OpenTycoonSwitch()
|
|
{
|
|
_cookedFoodDatas = new Queue<FoodData>(_currentDailyFoodUi.FoodData.Plate);
|
|
_isOpened = true;
|
|
_currentCookGauge = 0;
|
|
_currentFireWoodCount = _potDataSo.StartFireWoodCount;
|
|
}
|
|
}
|
|
} |