using System.Collections.Generic; using BlueWater.Items; 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 _fireWoodCount; // TODO : 추후에 다시 활성화 하는 기능 필요 [SerializeField] private bool _isOpened; [SerializeField] private int _fireWoodIdx = 70001; private Queue _cookedFoodDatas; private FoodData _currentFoodData; private int _currentFireWoodCount; private float _currentCookGauge; private float _startTime = float.PositiveInfinity; protected override void OnEnable() { TycoonManager.Instance.OnTycoonOpenedEvent += OpenTycoonSwitch; base.OnEnable(); } private void Update() { if (!_isOpened) return; var level = _currentFireWoodCount / 5; var currentFireWoodLevel = _potDataSo.FireWoodLevel[level]; // 음식 게이지 관리 및 음식 생성 if (_currentFoodData.Plate < _cookedFoodDatas.Count) { _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}"; _fireWoodCount.text = $"{_currentFireWoodCount}/{_potDataSo.MaxFireWoodCount}"; } public override void Interaction() { if (CurrentTycoonPlayer.IsCarriedItem()) { var carriedItemData = CurrentTycoonPlayer.GetCurrentItemData(); if (carriedItemData.Idx == _fireWoodIdx) { CurrentTycoonPlayer.GiveItem(); _currentFireWoodCount++; } } else { CurrentTycoonPlayer.CarryItem(_currentFoodData.Idx, ItemQuality.None); _cookedFoodDatas.Dequeue(); } } public override bool CanInteraction() { var isCarriedItem = CurrentTycoonPlayer.IsCarriedItem(); var isFullFireWood = _currentFireWoodCount >= _potDataSo.MaxFireWoodCount; var isEmptyCookedFood = _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() { _isOpened = true; _currentCookGauge = 0; _currentFireWoodCount = 0; } public void CookFood(FoodData foodData) { _currentFoodData = foodData; _cookedFoodDatas = new Queue(_currentFoodData.Plate); } } }