using BlueWater.Utility; using UnityEngine; namespace BlueWater.Tycoons { public static class GarnishBarrelSpineAnimation { 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 class GarnishBarrel : Barrel { private int _currentLevel; protected override void Start() { base.Start(); SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel1, 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 (LiquidData.Idx == "Garnish1") { GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = true; } else if (LiquidData.Idx == "Garnish2") { GameManager.Instance.CurrentTycoonPlayer.IsInteractedLimeTreeGarnish = true; } } public override void CancelInteraction() { OnBarrelCancelInteracted?.Invoke(); if (LiquidData.Idx == "Garnish1") { GameManager.Instance.CurrentTycoonPlayer.IsInteractedSlimeGarnish = false; } else if (LiquidData.Idx == "Garnish2") { GameManager.Instance.CurrentTycoonPlayer.IsInteractedLimeTreeGarnish = false; } } /// /// 1. 플레이어가 빈 잔을 들고 있거나 완성되지 않은 잔을 들고 있을 때 /// 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(); FillAnimation(); } public override void Consume(int amount) { base.Consume(amount); var newLevel = GetCurrentLevel(); if (_currentLevel != newLevel) { UnfillAnimation(); } } public override void AddCurrentAmount(int addedValue) { base.AddCurrentAmount(addedValue); var newLevel = GetCurrentLevel(); if (_currentLevel != newLevel) { FillAnimation(); } } private int GetCurrentLevel() { int max = (int)VisualMaxFill; if (CurrentAmount >= max) { return 4; } if (CurrentAmount >= max / 2) { return 3; } if (CurrentAmount > 0) { return 2; } return 1; } private void FillAnimation() { int max = (int)VisualMaxFill; if (CurrentAmount >= max) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel4, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel4, true); _currentLevel = 4; } else if (CurrentAmount >= max / 2) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel3, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel3, true); _currentLevel = 3; } else if (CurrentAmount > 0) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.FillToLevel2, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel2, true); _currentLevel = 2; } else { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel1, true); _currentLevel = 1; } } private void UnfillAnimation() { int max = (int)VisualMaxFill; if (CurrentAmount >= max) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.IdleLevel4, true); _currentLevel = 4; } else if (CurrentAmount >= max / 2) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel3, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel3, true); _currentLevel = 3; } else if (CurrentAmount > 0) { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel2, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel2, true); _currentLevel = 2; } else { SpineController.PlayAnimation(GarnishBarrelSpineAnimation.UnFillToLevel1, false); SpineController.AddAnimation(GarnishBarrelSpineAnimation.IdleLevel1, true); _currentLevel = 1; } } } }