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

121 lines
3.8 KiB
C#
Raw Normal View History

2024-10-06 23:41:09 +00:00
using System;
using BlueWater.Interfaces;
2024-10-14 11:13:08 +00:00
using BlueWater.Npcs.Crews;
2024-10-22 12:41:31 +00:00
using BlueWater.Npcs.Crews.Cleaner;
2024-10-14 11:13:08 +00:00
using BlueWater.Utility;
2024-10-06 23:41:09 +00:00
using UnityEngine;
namespace BlueWater.Tycoons
{
[Serializable]
2024-10-14 11:13:08 +00:00
public class Vomiting : InteractionFurniture, ICrewInteraction
2024-10-06 23:41:09 +00:00
{
2024-10-14 11:13:08 +00:00
[SerializeField]
private float _interactionHoldingTime = 3f;
2024-10-06 23:41:09 +00:00
private Sprite vomitingImage;
2024-10-14 11:13:08 +00:00
private Coroutine _findCleanerCrewInstance;
private bool _isPlayerInteracting;
private bool _isCrewInteracting;
private float _playerElapsedTime;
private float _crewElapsedTime;
public event Action OnInteractionCompleted;
2024-10-06 23:41:09 +00:00
protected override void OnEnable()
{
base.OnEnable();
Initialize();
}
private void Update()
{
2024-10-14 11:13:08 +00:00
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
2024-10-06 23:41:09 +00:00
{
2024-10-14 11:13:08 +00:00
var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent<IDamageable>();
damageable?.TakeDamage(1);
Destroy();
}
if (_isPlayerInteracting)
{
var clamp = Mathf.Clamp(_playerElapsedTime / _interactionHoldingTime, 0f, 1f);
EventManager.OnInteracting?.Invoke(clamp);
if (_playerElapsedTime > _interactionHoldingTime)
2024-10-06 23:41:09 +00:00
{
Destroy();
}
2024-10-14 11:13:08 +00:00
_playerElapsedTime += Time.deltaTime;
}
if (_isCrewInteracting)
{
if (_crewElapsedTime > _interactionHoldingTime)
2024-10-06 23:41:09 +00:00
{
2024-10-14 11:13:08 +00:00
OnInteractionCompleted?.Invoke();
2024-10-22 12:41:31 +00:00
OnInteractionCompleted = null;
2024-10-06 23:41:09 +00:00
Destroy();
}
2024-10-14 11:13:08 +00:00
_crewElapsedTime += Time.deltaTime;
2024-10-06 23:41:09 +00:00
}
}
public void Initialize()
{
InteractionMessage = "치우기";
vomitingImage = VisualLook.GetComponent<SpriteRenderer>().sprite;
InteractionCanvas.BalloonUi.OrderItem(vomitingImage, 0, TycoonManager.Instance.TycoonStageController.StageDataSo.VomitingWaitTime);
2024-10-15 18:01:16 +00:00
var crewController = TycoonManager.Instance.CrewController;
Utils.StartUniqueCoroutine(this, ref _findCleanerCrewInstance,
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.CleanerCrews, crew => crew.OnMission(this)));
2024-10-06 23:41:09 +00:00
}
public override void Interaction()
{
2024-10-14 11:13:08 +00:00
_playerElapsedTime = 0f;
EventManager.OnInteracting?.Invoke(_playerElapsedTime);
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = true;
_isPlayerInteracting = true;
2024-10-06 23:41:09 +00:00
}
public override void CancelInteraction()
{
2024-10-14 11:13:08 +00:00
_playerElapsedTime = 0f;
EventManager.OnInteracting?.Invoke(_playerElapsedTime);
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
_isPlayerInteracting = false;
2024-10-06 23:41:09 +00:00
}
public override bool CanInteraction()
{
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail();
}
private void Destroy()
{
2024-10-14 11:13:08 +00:00
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
2024-10-06 23:41:09 +00:00
Destroy(gameObject);
}
2024-10-14 11:13:08 +00:00
public void InteractionCrew(Crew crew)
{
_crewElapsedTime = 0f;
_isCrewInteracting = true;
2024-10-22 12:41:31 +00:00
((CleanerCrew)crew).SetIsCleaningFloor(true);
2024-10-14 11:13:08 +00:00
}
public void CancelInteractionCrew()
{
_crewElapsedTime = 0f;
_isCrewInteracting = false;
}
public bool CanInteractionCrew()
{
return !_isPlayerInteracting;
}
2024-10-06 23:41:09 +00:00
}
}