CapersProject/Assets/02.Scripts/Prop/Tycoon/Cookware.cs
Nam Tae Gun 1458693a1b 타이쿤 업데이트 정리
+ 상호작용 오브젝트 외곽선 기능 추가
+ 손님 계산 기능 추가
+ 손님 계산 시 Ui 출력 및 파티클, 효과 추가
+ 대화 시스템 로직 수정
+ 테이블 수정
+ 캐릭터 스파인 교체
2024-07-20 20:32:54 +09:00

179 lines
6.2 KiB
C#

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;
// TODO : 추후에 다시 활성화 하는 기능 필요
[Title("실시간 데이터")]
[FormerlySerializedAs("_isOpened")]
[SerializeField]
protected bool IsOpened;
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();
}
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;
}
private void OpenTycoonSwitch()
{
if (CurrentDailyFoodUi.FoodData is not null and not { Idx : 0 })
{
_cookedFoodDatas = new Queue<FoodData>(CurrentDailyFoodUi.FoodData.Plate);
_currentFireWoodCount = CookwareDataSo.StartFireWoodQuantity;
if (FireShader)
{
FireShader.enabled = true;
}
}
IsOpened = true;
_currentCookGauge = 0;
CookGauge.text = "0/0";
FireWoodQuantity.text = "0/0";
FoodQuantity.text = "0/0";
}
}
}