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

138 lines
4.0 KiB
C#
Raw Normal View History

2024-11-04 12:22:07 +00:00
using System;
2024-12-06 13:20:10 +00:00
using BlueWater.Audios;
2024-11-11 12:23:27 +00:00
using BlueWater.Players;
2024-11-07 09:13:54 +00:00
using BlueWater.Uis;
2024-11-04 12:22:07 +00:00
using UnityEngine;
namespace BlueWater.Tycoons
{
2024-12-06 13:20:10 +00:00
public static class PumpSpineAnimation
{
public const string Idle = "Idle";
2024-12-17 11:25:53 +00:00
public const string Stop = "IdleStop";
2024-12-06 13:20:10 +00:00
public const string Run = "Run";
}
2024-11-04 12:22:07 +00:00
[Serializable]
public class Pump : InteractionFurniture
{
2024-11-11 12:23:27 +00:00
[SerializeField]
private SpineController _spineController;
2024-11-04 12:22:07 +00:00
[SerializeField]
2024-11-11 09:51:12 +00:00
private float _playerHoldingTime = 1f;
2024-11-04 12:22:07 +00:00
[SerializeField]
private PumpingMessage _pumpingMessageObject;
[SerializeField]
private Vector3 _offset;
[SerializeField, Range(0, 1000)]
private int addedLiquid = 400;
2024-12-06 13:20:10 +00:00
[SerializeField]
private string _attackSfxName = "AttackWhip";
[SerializeField]
private string _playPumpSfxName = "PlayPump";
2024-11-04 12:22:07 +00:00
private bool _isPlayerInteracting;
2024-12-17 11:25:53 +00:00
private bool _isActivated;
2024-11-11 12:23:27 +00:00
protected override void Awake()
{
base.Awake();
2024-12-17 11:25:53 +00:00
EventManager.OnActivatePump += Activate;
2024-11-11 12:23:27 +00:00
_spineController = GetComponent<SpineController>();
}
protected override void Start()
{
base.Start();
2024-12-17 11:25:53 +00:00
_spineController.PlayAnimation(PumpSpineAnimation.Stop, false);
2024-11-11 12:23:27 +00:00
}
2024-11-04 12:22:07 +00:00
private void Update()
{
if (IsShowing)
{
2024-11-28 23:07:50 +00:00
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
2024-11-04 12:22:07 +00:00
}
2024-11-11 09:51:12 +00:00
if (HoldingElapsedTime > _playerHoldingTime)
2024-11-04 12:22:07 +00:00
{
2024-11-11 09:51:12 +00:00
HoldingElapsedTime -= _playerHoldingTime;
2024-11-04 12:22:07 +00:00
EventManager.InvokeAddBarrels(addedLiquid);
var pumpingMessage = Instantiate(_pumpingMessageObject, transform.position + _offset,
2024-11-07 09:13:54 +00:00
Quaternion.identity, TycoonUiManager.Instance.WorldCanvas.transform);
2024-11-04 12:22:07 +00:00
pumpingMessage.Initialize(addedLiquid);
}
2024-11-28 23:07:50 +00:00
float playerHoldingDeltaTime = Time.deltaTime / _playerHoldingTime;
2024-11-04 12:22:07 +00:00
if (_isPlayerInteracting)
{
2024-11-28 23:07:50 +00:00
HoldingElapsedTime += playerHoldingDeltaTime;
2024-11-04 12:22:07 +00:00
}
else
{
if (HoldingElapsedTime > 0f)
{
2024-11-28 23:07:50 +00:00
HoldingElapsedTime -= playerHoldingDeltaTime;
2024-11-04 12:22:07 +00:00
}
}
}
2024-12-17 11:25:53 +00:00
private void OnDestroy()
{
EventManager.OnActivatePump -= Activate;
}
2024-11-04 12:22:07 +00:00
public override void Interaction()
{
2024-12-06 13:20:10 +00:00
AudioManager.Instance.PlaySfx(_attackSfxName, true);
AudioManager.Instance.PlaySfx(_playPumpSfxName, true);
2024-11-17 04:29:57 +00:00
GameManager.Instance.CurrentTycoonPlayer.IsPumping = true;
2024-11-04 12:22:07 +00:00
_isPlayerInteracting = true;
2024-12-06 13:20:10 +00:00
_spineController.PlayAnimation(PumpSpineAnimation.Run, true);
2024-11-04 12:22:07 +00:00
}
public override void CancelInteraction()
{
2024-12-06 13:20:10 +00:00
AudioManager.Instance.StopSfx(_attackSfxName);
AudioManager.Instance.StopSfx(_playPumpSfxName);
2024-11-17 04:29:57 +00:00
GameManager.Instance.CurrentTycoonPlayer.IsPumping = false;
2024-11-04 12:22:07 +00:00
_isPlayerInteracting = false;
2024-12-06 13:20:10 +00:00
_spineController.PlayAnimation(PumpSpineAnimation.Idle, true);
2024-11-04 12:22:07 +00:00
}
public override bool CanInteraction()
{
2024-12-17 11:25:53 +00:00
return _isActivated && !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything();
2024-11-04 12:22:07 +00:00
}
2024-11-11 12:23:27 +00:00
public override void ShowInteractionUi()
{
_spineController.EnableCustomMaterial();
EventManager.InvokeShowInteractionUi(InteractionMessage);
IsShowing = true;
}
public override void HideInteractionUi()
{
_spineController.DisableCustomMaterial();
EventManager.InvokeHideInteractionUi();
IsShowing = false;
}
2024-12-17 11:25:53 +00:00
public void Activate()
{
_isActivated = true;
_spineController.PlayAnimation(PumpSpineAnimation.Idle, true);
}
2024-11-04 12:22:07 +00:00
}
}