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; private float _playerElapsedTime; private float _crewElapsedTime; public event Action OnInteractionCompleted; protected override void OnEnable() { base.OnEnable(); Initialize(); } private void Update() { if (InteractionCanvas.BalloonUi.IsWaitTimeOver()) { var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent(); damageable?.TakeDamage(1); Destroy(); } if (_isPlayerInteracting) { if (_playerElapsedTime > _interactionHoldingTime) { Destroy(); } _playerElapsedTime += Time.deltaTime; } else { if (_playerElapsedTime > 0f) { _playerElapsedTime -= Time.deltaTime; } } var holdingGauge = 0f; if (_playerElapsedTime > 0f) { holdingGauge = Mathf.Clamp(_playerElapsedTime / _interactionHoldingTime, 0f, 1f); } if (IsShowing) { EventManager.InvokeHoldInteracting(holdingGauge); } if (_isCrewInteracting) { if (_crewElapsedTime > _interactionHoldingTime) { OnInteractionCompleted?.Invoke(); OnInteractionCompleted = null; Destroy(); } _crewElapsedTime += Time.deltaTime; } } 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() { 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() { return !_isPlayerInteracting; } } }