CapersProject/Assets/02.Scripts/Prop/Tycoon/GarnishBarrel.cs
2024-12-20 14:11:56 +09:00

246 lines
8.1 KiB
C#

using System;
using BlueWater.Utility;
using UnityEngine;
using UnityEngine.Serialization;
namespace BlueWater.Tycoons
{
public static class GarnishBarrelSpineAnimation
{
public const string InactiveIdle = "Idle";
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";
}
public enum GarnishType
{
None = 0,
Slime = 1,
LimeTree = 2
}
public class GarnishBarrel : Barrel
{
[SerializeField]
private SpriteRenderer _signImage;
[SerializeField]
private GarnishType _garnishType;
private int _currentLevel;
protected override void Start()
{
base.Start();
_signImage.sprite = IsActivated ? LiquidData.Sprite : DataManager.Instance.SpriteDataSo.BarrelLock;
SpineController.PlayAnimation(GarnishBarrelSpineAnimation.InactiveIdle, true);
}
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);
if (_garnishType == GarnishType.Slime)
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = true;
}
else if (_garnishType == GarnishType.LimeTree)
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedLimeTreeGarnish = true;
}
}
public override void CancelInteraction()
{
OnBarrelCancelInteracted?.Invoke();
if (_garnishType == GarnishType.Slime)
{
GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = false;
}
else if (_garnishType == GarnishType.LimeTree)
{
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();
_signImage.sprite = IsActivated ? LiquidData.Sprite : DataManager.Instance.SpriteDataSo.BarrelLock;
_currentLevel = GetCurrentLevel();
IdleAnimation();
}
public override void Consume(int amount)
{
if (!IsActivated) return;
base.Consume(amount);
var newLevel = GetCurrentLevel();
if (_currentLevel != newLevel)
{
UnfillAnimation(newLevel);
_currentLevel = newLevel;
}
}
public override void AddCurrentAmount(int addedValue)
{
if (!IsActivated) return;
base.AddCurrentAmount(addedValue);
var newLevel = GetCurrentLevel();
if (_currentLevel != newLevel)
{
FillAnimation(newLevel);
_currentLevel = newLevel;
}
}
private int GetCurrentLevel()
{
if (CurrentAmount <= 0) return 0;
if (CurrentAmount >= MaxFill) return 4;
int range = (int)(MaxFill / 3f);
int level = CurrentAmount / range;
return level switch
{
0 => 1,
1 => 2,
_ => 3
};
}
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 존재하지 않는 값");
}
}
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 존재하지 않는 값");
}
}
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 존재하지 않는 값");
}
}
}
}