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(); } protected override void Start() { base.Start(); EventManager.OnCleaningAll += Destroy; } private void Update() { if (InteractionCanvas.BalloonUi.IsWaitTimeOver()) { var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent(); 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) { Destroy(); } if (_isPlayerInteracting) { HoldingElapsedTime += Time.deltaTime; } if (_isCrewInteracting) { HoldingElapsedTime += Time.deltaTime; } if (!_isPlayerInteracting && !_isCrewInteracting) { if (HoldingElapsedTime > 0f) { HoldingElapsedTime -= Time.deltaTime; } } } private void OnDestroy() { EventManager.OnCleaningAll -= Destroy; } public void Initialize() { InteractionMessage = "치우기"; vomitingImage = VisualLook.GetComponent().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() { if (_isPlayerInteracting) { GameManager.Instance.CurrentTycoonPlayer.IsCleaningFloor = false; } if (_isCrewInteracting) { OnInteractionCompleted?.Invoke(); OnInteractionCompleted = null; } 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; } } }