128 lines
3.8 KiB
C#
128 lines
3.8 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Npcs.Crews;
|
|
using BlueWater.Npcs.Crews.Cleaner;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class Vomiting : InteractionFurniture, ICrewInteraction
|
|
{
|
|
[SerializeField]
|
|
private float _interactionHoldingTime = 3f;
|
|
|
|
private Sprite vomitingImage;
|
|
private Coroutine _findCleanerCrewInstance;
|
|
private bool _isPlayerInteracting;
|
|
private bool _isCrewInteracting;
|
|
|
|
public event Action OnInteractionCompleted;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
|
|
Initialize();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent<IDamageable>();
|
|
damageable?.TakeDamage(1);
|
|
Destroy();
|
|
}
|
|
|
|
var holdingGauge = 0f;
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
holdingGauge = Mathf.Clamp(HoldingElapsedTime / _interactionHoldingTime, 0f, 1f);
|
|
}
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(holdingGauge);
|
|
}
|
|
|
|
if (HoldingElapsedTime > _interactionHoldingTime)
|
|
{
|
|
if (_isCrewInteracting)
|
|
{
|
|
OnInteractionCompleted?.Invoke();
|
|
OnInteractionCompleted = null;
|
|
}
|
|
|
|
Destroy();
|
|
}
|
|
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime;
|
|
}
|
|
if (_isCrewInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime;
|
|
}
|
|
|
|
if (!_isPlayerInteracting && !_isCrewInteracting)
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= Time.deltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
InteractionMessage = "치우기";
|
|
vomitingImage = VisualLook.GetComponent<SpriteRenderer>().sprite;
|
|
InteractionCanvas.BalloonUi.OrderItem(vomitingImage, 0, TycoonManager.Instance.TycoonStageController.StageDataSo.VomitingWaitTime);
|
|
var crewController = TycoonManager.Instance.CrewController;
|
|
Utils.StartUniqueCoroutine(this, ref _findCleanerCrewInstance,
|
|
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.CleanerCrews, crew => crew.OnMission(this)));
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = true;
|
|
_isPlayerInteracting = true;
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
_isPlayerInteracting = false;
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail();
|
|
}
|
|
|
|
private void Destroy()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false;
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void InteractionCrew(Crew crew)
|
|
{
|
|
_isCrewInteracting = true;
|
|
((CleanerCrew)crew).SetIsCleaningFloor(true);
|
|
}
|
|
|
|
public void CancelInteractionCrew()
|
|
{
|
|
_isCrewInteracting = false;
|
|
}
|
|
|
|
public bool CanInteractionCrew(Crew crew = null)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
} |