122 lines
3.0 KiB
C#
122 lines
3.0 KiB
C#
using System;
|
|
using BlueWater.Items;
|
|
using BlueWater.Players;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public abstract class Barrel : InteractionFurniture
|
|
{
|
|
[SerializeField]
|
|
protected SpineController SpineController;
|
|
|
|
[SerializeField]
|
|
private string Idx;
|
|
|
|
[SerializeField]
|
|
protected LiquidData LiquidData;
|
|
|
|
[SerializeField]
|
|
protected float VisualMaxFill = 4000f;
|
|
|
|
[field: SerializeField]
|
|
public int CurrentAmount { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public bool IsStatue { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public bool IsActivated { get; private set; }
|
|
|
|
[field: SerializeField]
|
|
public bool IsAutoSupply { get; private set; }
|
|
|
|
protected float SupplyElapsedTime;
|
|
|
|
public static Action<Barrel> OnBarrelInteracted;
|
|
public static Action OnBarrelCancelInteracted;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
SpineController = GetComponent<SpineController>();
|
|
LiquidData = ItemManager.Instance.LiquidDataSo.GetDataByIdx(Idx);
|
|
|
|
EventManager.OnAddBarrels += AddCurrentAmount;
|
|
EventManager.OnAutoSupplyBarrels += AutoSupply;
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
SetCurrentAmount(0);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnAddBarrels -= AddCurrentAmount;
|
|
EventManager.OnAutoSupplyBarrels -= AutoSupply;
|
|
}
|
|
|
|
public abstract override void Interaction();
|
|
public abstract bool CanMakingCocktailCrew(int amount);
|
|
public abstract bool CanMold();
|
|
public abstract void Mold();
|
|
|
|
public bool CanConsume(int amount)
|
|
{
|
|
return CurrentAmount - amount > 0;
|
|
}
|
|
|
|
public virtual void Consume(int amount)
|
|
{
|
|
if (CurrentAmount == int.MaxValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var consumeAmount = CurrentAmount - amount;
|
|
SetCurrentAmount(consumeAmount);
|
|
}
|
|
|
|
public bool TryConsume(int amount)
|
|
{
|
|
if (!CanConsume(amount)) return false;
|
|
|
|
Consume(amount);
|
|
return true;
|
|
}
|
|
|
|
public LiquidData GetLiquidData() => LiquidData;
|
|
|
|
public virtual void SetCurrentAmount(int amount)
|
|
{
|
|
if (CurrentAmount == int.MaxValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
CurrentAmount = amount;
|
|
}
|
|
|
|
public virtual void Activate()
|
|
{
|
|
IsActivated = true;
|
|
SetCurrentAmount(LiquidData.GetMaxAmount());
|
|
}
|
|
|
|
public void AutoSupply()
|
|
{
|
|
IsAutoSupply = true;
|
|
}
|
|
|
|
public virtual void AddCurrentAmount(int addedValue)
|
|
{
|
|
if (!IsActivated) return;
|
|
|
|
SetCurrentAmount(CurrentAmount + addedValue);
|
|
}
|
|
}
|
|
} |