Files
Cielonos/Assets/Scripts/MainGame/Items/Base/ConsumableBase.cs

60 lines
1.3 KiB
C#
Raw Normal View History

2026-01-03 18:19:39 -05:00
using UnityEngine;
2026-05-23 08:27:50 -04:00
namespace Cielonos.MainGame.Inventory
2026-01-03 18:19:39 -05:00
{
public abstract partial class ConsumableBase : ItemBase
{
public int stackAmount;
public int maximumStack = 99999;
}
public partial class ConsumableBase
{
2026-05-10 11:47:55 -04:00
public void Modify(int amount)
{
if (amount > 0)
{
Add(amount);
}
else if (amount < 0)
{
Use(amount);
}
}
public void Add(int amount)
2026-01-03 18:19:39 -05:00
{
stackAmount += amount;
if (stackAmount > maximumStack)
{
stackAmount = maximumStack;
}
}
public bool Use(int amount)
{
if (functionSm?.mainFunction != null)
{
if (!functionSm.mainFunction.IsAvailable())
{
return false;
}
}
if (stackAmount < amount)
{
amount = stackAmount;
}
stackAmount -= amount;
if (stackAmount <= 0)
{
2026-05-10 11:47:55 -04:00
player.inventorySc.backpackSm.DiscardItem(this);
2026-01-03 18:19:39 -05:00
}
functionSm?.mainFunction?.Execute();
return true;
}
}
}