48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Characters.Inventory
|
|
{
|
|
public abstract partial class ConsumableBase : ItemBase
|
|
{
|
|
public int stackAmount;
|
|
public int maximumStack = 99999;
|
|
}
|
|
|
|
public partial class ConsumableBase
|
|
{
|
|
public void AddStack(int amount)
|
|
{
|
|
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)
|
|
{
|
|
player.inventorySc.backpack.DiscardItem(this);
|
|
}
|
|
|
|
functionSm?.mainFunction?.Execute();
|
|
return true;
|
|
}
|
|
}
|
|
} |