60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.Inventory
|
|
{
|
|
public abstract partial class ConsumableBase : ItemBase
|
|
{
|
|
public int stackAmount;
|
|
public int maximumStack = 99999;
|
|
}
|
|
|
|
public partial class ConsumableBase
|
|
{
|
|
public void Modify(int amount)
|
|
{
|
|
if (amount > 0)
|
|
{
|
|
Add(amount);
|
|
}
|
|
else if (amount < 0)
|
|
{
|
|
Use(amount);
|
|
}
|
|
}
|
|
|
|
public void Add(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.backpackSm.DiscardItem(this);
|
|
}
|
|
|
|
functionSm?.mainFunction?.Execute();
|
|
return true;
|
|
}
|
|
}
|
|
} |