157 lines
4.7 KiB
C#
157 lines
4.7 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Npcs.Crews;
|
|
using BlueWater.Npcs.Crews.Cleaner;
|
|
using BlueWater.Uis;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class Vomiting : InteractionFurniture, ICrewInteraction
|
|
{
|
|
[SerializeField]
|
|
private PayMoneyUi _payMoneyUiObject;
|
|
|
|
[SerializeField]
|
|
private Vector3 _offset = new(0f, 1.5f, 0f);
|
|
|
|
[SerializeField]
|
|
private float _playerHoldingTime = 3f;
|
|
|
|
[SerializeField]
|
|
private float _crewHoldingTime = 9f;
|
|
|
|
private LevelData _currentLevelData;
|
|
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<IDamageable>();
|
|
damageable?.TakeDamage(1);
|
|
Destroy();
|
|
}
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
if (_isPlayerInteracting)
|
|
{
|
|
var tip = (int)(_currentLevelData.Gold * TycoonManager.Instance.TycoonStatus.TipMultiplier);
|
|
if (tip > 0)
|
|
{
|
|
var payMoneyUi = Instantiate(_payMoneyUiObject, transform.position + _offset,
|
|
Quaternion.identity, TycoonUiManager.Instance.WorldCanvas.transform);
|
|
payMoneyUi.Initialize(tip);
|
|
}
|
|
}
|
|
|
|
Destroy();
|
|
}
|
|
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime / _playerHoldingTime;
|
|
}
|
|
if (_isCrewInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime / (_crewHoldingTime - TycoonManager.Instance.TycoonStatus.CleanerCleaningReduction);
|
|
}
|
|
|
|
if (!_isPlayerInteracting && !_isCrewInteracting)
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= Time.deltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnCleaningAll -= Destroy;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
InteractionCanvas.BalloonUi.OrderItem(DataManager.Instance.SpriteDataSo.Cleaning, 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)));
|
|
_currentLevelData = TycoonManager.Instance.GetCurrentLevelData();
|
|
}
|
|
|
|
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.IsPickedUpAnything();
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |