CapersProject/Assets/02.Scripts/Prop/Tycoon/GarnishBarrel.cs

239 lines
7.9 KiB
C#
Raw Normal View History

2024-11-30 11:53:38 +00:00
using System;
2024-11-17 14:21:16 +00:00
using BlueWater.Utility;
using UnityEngine;
2024-12-02 11:43:08 +00:00
using UnityEngine.Serialization;
2024-11-17 14:21:16 +00:00
namespace BlueWater.Tycoons
{
public static class GarnishBarrelSpineAnimation
{
2024-11-26 08:22:26 +00:00
public const string InactiveIdle = "Idle";
2024-11-17 14:21:16 +00:00
public const string IdleLevel1 = "Idle0";
public const string IdleLevel2 = "Idle10";
public const string IdleLevel3 = "Idle50";
public const string IdleLevel4 = "Idle100";
public const string FillToLevel2 = "Fill0to10";
public const string FillToLevel3 = "Fill10to50";
public const string FillToLevel4 = "Fill50to100";
public const string UnFillToLevel1 = "Change10to0";
public const string UnFillToLevel2 = "Change50to10";
public const string UnFillToLevel3 = "Change100to50";
}
2024-11-30 11:53:38 +00:00
public enum GarnishType
{
None = 0,
Slime = 1,
LimeTree = 2
}
2024-11-17 14:21:16 +00:00
public class GarnishBarrel : Barrel
{
2024-12-02 11:43:08 +00:00
[SerializeField]
private SpriteRenderer _signImage;
2024-11-30 11:53:38 +00:00
[SerializeField]
private GarnishType _garnishType;
2024-11-17 14:21:16 +00:00
private int _currentLevel;
protected override void Start()
{
base.Start();
2024-12-02 11:43:08 +00:00
_signImage.sprite = IsActivated ? LiquidData.Sprite : DataManager.Instance.SpriteDataSo.BarrelLock;
2024-11-26 08:22:26 +00:00
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.InactiveIdle, true);
2024-11-17 14:21:16 +00:00
}
private void Update()
{
if (!IsAutoSupply) return;
if (SupplyElapsedTime >= 1f)
{
AddCurrentAmount(TycoonManager.Instance.TycoonStatus.BarrelAutoIncrease);
SupplyElapsedTime -= 1f;
}
SupplyElapsedTime += Time.deltaTime;
}
public override void Interaction()
{
OnBarrelInteracted?.Invoke(this);
2024-11-30 11:53:38 +00:00
if (_garnishType == GarnishType.Slime)
2024-11-17 14:21:16 +00:00
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = true;
}
2024-11-30 11:53:38 +00:00
else if (_garnishType == GarnishType.LimeTree)
2024-11-17 14:21:16 +00:00
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedLimeTreeGarnish = true;
}
}
public override void CancelInteraction()
{
OnBarrelCancelInteracted?.Invoke();
2024-11-30 11:53:38 +00:00
if (_garnishType == GarnishType.Slime)
2024-11-17 14:21:16 +00:00
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = false;
}
2024-11-30 11:53:38 +00:00
else if (_garnishType == GarnishType.LimeTree)
2024-11-17 14:21:16 +00:00
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedLimeTreeGarnish = false;
}
}
/// <summary>
/// 1. 플레이어가 빈 잔을 들고 있거나 완성되지 않은 잔을 들고 있을 때
/// </summary>
public override bool CanInteraction()
{
return IsActivated && !CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpItem && CanConsume(1);
}
public override void ShowInteractionUi()
{
InteractionMessage = $"{Utils.GetLocalizedString(LiquidData.Idx)} {Utils.GetLocalizedString("Pour")}";
SpineController.EnableCustomMaterial();
EventManager.InvokeShowInteractionUi(InteractionMessage);
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
IsShowing = true;
}
public override void HideInteractionUi()
{
SpineController.DisableCustomMaterial();
EventManager.InvokeHideInteractionUi();
IsShowing = false;
}
public override bool CanMold()
{
return false;
}
public override void Mold()
{
}
public override bool CanMakingCocktailCrew(int amount)
{
return IsActivated && CanConsume(amount);
}
public override void Activate()
{
base.Activate();
2024-12-02 11:43:08 +00:00
_signImage.sprite = IsActivated ? LiquidData.Sprite : DataManager.Instance.SpriteDataSo.BarrelLock;
2024-11-17 14:21:16 +00:00
2024-11-30 11:53:38 +00:00
_currentLevel = GetCurrentLevel();
IdleAnimation();
2024-11-17 14:21:16 +00:00
}
public override void Consume(int amount)
{
2024-11-30 11:53:38 +00:00
if (!IsActivated) return;
2024-11-17 14:21:16 +00:00
base.Consume(amount);
var newLevel = GetCurrentLevel();
if (_currentLevel != newLevel)
{
2024-11-30 11:53:38 +00:00
UnfillAnimation(newLevel);
_currentLevel = newLevel;
2024-11-17 14:21:16 +00:00
}
}
public override void AddCurrentAmount(int addedValue)
{
2024-11-26 08:22:26 +00:00
if (!IsActivated) return;
2024-11-17 14:21:16 +00:00
base.AddCurrentAmount(addedValue);
var newLevel = GetCurrentLevel();
if (_currentLevel != newLevel)
{
2024-11-30 11:53:38 +00:00
FillAnimation(newLevel);
_currentLevel = newLevel;
2024-11-17 14:21:16 +00:00
}
}
2024-11-30 11:53:38 +00:00
2024-11-17 14:21:16 +00:00
private int GetCurrentLevel()
{
2024-11-30 11:53:38 +00:00
if (CurrentAmount <= 0) return 0;
2024-12-19 14:27:01 +00:00
if (CurrentAmount >= MaxFill) return 4;
2024-11-30 11:53:38 +00:00
2024-12-19 14:27:01 +00:00
float range = MaxFill / 3f;
2024-11-30 11:53:38 +00:00
return (int)(CurrentAmount / range) + 1;
}
private void IdleAnimation()
{
switch (_currentLevel)
{
case 0:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel1, false);
break;
case 1:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel2, false);
break;
case 2:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel3, false);
break;
case 3:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel4, false);
break;
default:
throw new Exception("_currentLevel 존재하지 않는 값");
2024-11-17 14:21:16 +00:00
}
}
2024-11-30 11:53:38 +00:00
private void FillAnimation(int newLevel)
{
switch (newLevel)
{
case 2:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel2, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel2, true);
break;
case 3:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel3, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel3, true);
break;
case 4:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel4, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel4, true);
break;
default:
throw new Exception("_currentLevel 존재하지 않는 값");
2024-11-17 14:21:16 +00:00
}
}
2024-11-30 11:53:38 +00:00
private void UnfillAnimation(int newLevel)
{
switch (newLevel)
{
case 1:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel1, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel1, true);
break;
case 2:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel2, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel2, true);
break;
case 3:
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel3, false);
SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel3, true);
break;
default:
throw new Exception("_currentLevel 존재하지 않는 값");
2024-11-17 14:21:16 +00:00
}
}
}
}