195 lines
6.2 KiB
C#
195 lines
6.2 KiB
C#
using BlueWater.Items;
|
|
using BlueWater.Players;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public static class TrashCanSpineAnimation
|
|
{
|
|
public const string ChangeRandomBox = "ChangeRandomBox";
|
|
public const string RandomBoxHolding = "RandomBoxHold";
|
|
public const string RandomBoxIdle = "RandomBoxIdle";
|
|
public const string RandomBoxSpit = "RandomBoxSpit";
|
|
public const string Open = "TrachcanOpen";
|
|
public const string Close = "TrashcanClose";
|
|
public const string Stop = "TrashcanCloseStop";
|
|
}
|
|
|
|
public class TrashCan : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
private SpineController _spineController;
|
|
|
|
[SerializeField]
|
|
private float _playerHoldingTime = 1f;
|
|
|
|
[SerializeField]
|
|
private bool _canRandomChange;
|
|
|
|
[SerializeField]
|
|
private bool _isChanged;
|
|
|
|
private bool _isPlayerInteracting;
|
|
private bool _canInteraction = true;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_spineController = GetComponent<SpineController>();
|
|
|
|
EventManager.OnChangedRandomBox += ChangeRandomBox;
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.Stop, false);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
_canInteraction = true;
|
|
}
|
|
}
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
if (_isChanged)
|
|
{
|
|
ChangeRandomCocktail();
|
|
}
|
|
else
|
|
{
|
|
DiscardItem();
|
|
}
|
|
}
|
|
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime / _playerHoldingTime;
|
|
}
|
|
else
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= Time.deltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnChangedRandomBox -= ChangeRandomBox;
|
|
}
|
|
|
|
public void ChangeRandomBox()
|
|
{
|
|
if (!_canRandomChange) return;
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.ChangeRandomBox, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, true);
|
|
_isChanged = true;
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
_isPlayerInteracting = true;
|
|
|
|
if (_isChanged)
|
|
{
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.RandomBoxHolding, true);
|
|
}
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
_isPlayerInteracting = false;
|
|
|
|
if (_isChanged)
|
|
{
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, false);
|
|
}
|
|
else
|
|
{
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.Stop, false);
|
|
}
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything() &&
|
|
((TycoonManager.Instance.TycoonStatus.CurrentPassiveCard == PassiveCard.RandomChange && _canInteraction) ||
|
|
TycoonManager.Instance.TycoonStatus.CurrentPassiveCard != PassiveCard.RandomChange);
|
|
}
|
|
|
|
public override void ShowInteractionUi()
|
|
{
|
|
if (TycoonManager.Instance.TycoonStatus.CurrentPassiveCard == PassiveCard.RandomChange)
|
|
{
|
|
UpdateLocalizedString("InteractionTrashCanChange");
|
|
}
|
|
else
|
|
{
|
|
UpdateLocalizedString("InteractionTrashCanDiscard");
|
|
}
|
|
|
|
_spineController.EnableCustomMaterial();
|
|
EventManager.InvokeShowInteractionUi(InteractionMessage);
|
|
IsShowing = true;
|
|
}
|
|
|
|
public override void HideInteractionUi()
|
|
{
|
|
_spineController.DisableCustomMaterial();
|
|
EventManager.InvokeHideInteractionUi();
|
|
IsShowing = false;
|
|
}
|
|
|
|
private void DiscardItem()
|
|
{
|
|
CocktailData discardCocktailData = null;
|
|
if (!CurrentTycoonPlayer.TycoonPickupHandler.IsUnfinishedCocktailPickedUp)
|
|
{
|
|
var discardCocktailDataIdx = CurrentTycoonPlayer.TycoonPickupHandler.GetCurrentPickupItem().Idx;
|
|
discardCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(discardCocktailDataIdx);
|
|
}
|
|
|
|
EventManager.InvokeCocktailDiscarded(discardCocktailData, true);
|
|
|
|
HoldingElapsedTime = 0f;
|
|
_isPlayerInteracting = false;
|
|
|
|
print("실행 전");
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.Open, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.Close, false);
|
|
print("실행 후");
|
|
}
|
|
|
|
private void ChangeRandomCocktail()
|
|
{
|
|
var randomCocktail = TycoonManager.Instance.TycoonIngredientController.GetRandomCocktailData();
|
|
EventManager.InvokeChangedRandomCocktail(randomCocktail);
|
|
InteractionCanvas.BalloonUi.OrderItem(DataManager.Instance.SpriteDataSo.Waiting, 0,
|
|
TycoonManager.Instance.TycoonStageController.StageDataSo.RandomChangeWaitTime);
|
|
|
|
HoldingElapsedTime = 0f;
|
|
_canInteraction = false;
|
|
_isPlayerInteracting = false;
|
|
|
|
_spineController.PlayAnimation(TrashCanSpineAnimation.RandomBoxSpit, false);
|
|
_spineController.AddAnimation(TrashCanSpineAnimation.RandomBoxIdle, true);
|
|
}
|
|
}
|
|
} |