CapersProject/Assets/02.Scripts/Prop/Tycoon/Barrel.cs

122 lines
3.0 KiB
C#
Raw Normal View History

2024-09-12 07:36:24 +00:00
using System;
2024-09-10 07:26:29 +00:00
using BlueWater.Items;
2024-11-12 12:07:23 +00:00
using BlueWater.Players;
2024-09-10 07:26:29 +00:00
using UnityEngine;
namespace BlueWater.Tycoons
{
2024-11-17 14:21:16 +00:00
public abstract class Barrel : InteractionFurniture
2024-09-10 07:26:29 +00:00
{
2024-11-12 12:07:23 +00:00
[SerializeField]
2024-11-17 14:21:16 +00:00
protected SpineController SpineController;
2024-09-23 02:00:21 +00:00
2024-09-10 07:26:29 +00:00
[SerializeField]
2024-11-17 14:21:16 +00:00
private string Idx;
2024-09-10 07:26:29 +00:00
[SerializeField]
2024-11-17 14:21:16 +00:00
protected LiquidData LiquidData;
[SerializeField]
protected float VisualMaxFill = 4000f;
2024-09-10 07:26:29 +00:00
2024-09-23 02:00:21 +00:00
[field: SerializeField]
public int CurrentAmount { get; private set; }
2024-11-12 12:07:23 +00:00
[field: SerializeField]
public bool IsStatue { get; private set; }
2024-10-27 09:44:22 +00:00
2024-11-05 12:27:46 +00:00
[field: SerializeField]
public bool IsActivated { get; private set; }
[field: SerializeField]
public bool IsAutoSupply { get; private set; }
2024-09-30 12:05:19 +00:00
2024-11-17 14:21:16 +00:00
protected float SupplyElapsedTime;
2024-09-23 02:00:21 +00:00
2024-11-17 14:21:16 +00:00
public static Action<Barrel> OnBarrelInteracted;
public static Action OnBarrelCancelInteracted;
2024-09-10 07:26:29 +00:00
protected override void Awake()
{
base.Awake();
2024-09-30 12:05:19 +00:00
2024-11-17 14:21:16 +00:00
SpineController = GetComponent<SpineController>();
LiquidData = ItemManager.Instance.LiquidDataSo.GetDataByIdx(Idx);
2024-10-28 05:09:06 +00:00
EventManager.OnAddBarrels += AddCurrentAmount;
2024-11-05 12:27:46 +00:00
EventManager.OnAutoSupplyBarrels += AutoSupply;
2024-09-10 07:26:29 +00:00
}
2024-11-17 14:21:16 +00:00
protected override void Start()
2024-11-05 12:27:46 +00:00
{
2024-11-17 14:21:16 +00:00
base.Start();
2024-11-05 12:27:46 +00:00
2024-11-17 14:21:16 +00:00
SetCurrentAmount(0);
2024-11-05 12:27:46 +00:00
}
2024-10-28 05:09:06 +00:00
private void OnDestroy()
{
EventManager.OnAddBarrels -= AddCurrentAmount;
2024-11-05 12:27:46 +00:00
EventManager.OnAutoSupplyBarrels -= AutoSupply;
2024-10-28 05:09:06 +00:00
}
2024-11-17 14:21:16 +00:00
public abstract override void Interaction();
public abstract bool CanMakingCocktailCrew(int amount);
public abstract bool CanMold();
public abstract void Mold();
2024-11-11 06:09:32 +00:00
2024-09-10 07:26:29 +00:00
public bool CanConsume(int amount)
{
2024-09-23 02:00:21 +00:00
return CurrentAmount - amount > 0;
2024-09-10 07:26:29 +00:00
}
2024-11-17 14:21:16 +00:00
public virtual void Consume(int amount)
2024-09-10 07:26:29 +00:00
{
2024-09-23 02:00:21 +00:00
if (CurrentAmount == int.MaxValue)
2024-09-10 07:26:29 +00:00
{
return;
}
2024-09-23 02:00:21 +00:00
var consumeAmount = CurrentAmount - amount;
2024-11-04 12:22:07 +00:00
SetCurrentAmount(consumeAmount);
2024-09-10 07:26:29 +00:00
}
public bool TryConsume(int amount)
{
if (!CanConsume(amount)) return false;
Consume(amount);
return true;
}
2024-11-17 14:21:16 +00:00
public LiquidData GetLiquidData() => LiquidData;
2024-09-23 02:00:21 +00:00
2024-11-17 14:21:16 +00:00
public virtual void SetCurrentAmount(int amount)
2024-09-23 02:00:21 +00:00
{
2024-09-30 12:05:19 +00:00
if (CurrentAmount == int.MaxValue)
2024-09-23 02:00:21 +00:00
{
return;
}
CurrentAmount = amount;
}
2024-09-30 12:05:19 +00:00
2024-11-17 14:21:16 +00:00
public virtual void Activate()
2024-09-30 12:05:19 +00:00
{
IsActivated = true;
2024-11-17 14:21:16 +00:00
SetCurrentAmount(LiquidData.GetMaxAmount());
2024-09-30 12:05:19 +00:00
}
2024-10-28 05:09:06 +00:00
2024-11-05 12:27:46 +00:00
public void AutoSupply()
{
IsAutoSupply = true;
}
2024-11-17 14:21:16 +00:00
public virtual void AddCurrentAmount(int addedValue)
2024-10-28 05:09:06 +00:00
{
2024-11-05 12:27:46 +00:00
if (!IsActivated) return;
2024-10-28 05:09:06 +00:00
2024-11-04 12:22:07 +00:00
SetCurrentAmount(CurrentAmount + addedValue);
2024-10-28 05:09:06 +00:00
}
2024-09-10 07:26:29 +00:00
}
}