Add inventory count conditions and item removal actions

This commit is contained in:
cthangover committed 2026-10-27 01:07:31 +01:00
1 parent 10fbfe614c
commit 1604bd283e
8 files changed
+156

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
namespace Cthangover.Mods.Items
{
using Cthangover.Core.Actions;
/// <summary>Consumes a positive stack from a scenario. Gate deliveries with item('id') >= count before running it.</summary>
public class ItemRemoveAction : IScenarioAction
{
/// <summary>Scenario id.</summary>
public string Name => "item.remove";
/// <summary>Refuses an invalid or insufficient stack without changing inventory.</summary>
public void Run(IActionContext ctx)
{
var id = ctx.GetParam("id")?.Trim();
var text = ctx.GetParam("count");
var count = 1;
if (string.IsNullOrWhiteSpace(id) || (!string.IsNullOrWhiteSpace(text) && !int.TryParse(text, out count)) || count <= 0)
{
ctx.LogWarning("INVENTORY", "item.remove: expected an item id and a positive count");
return;
}
if (ctx.Inventory?.Remove(id, count) != true)
ctx.LogWarning("INVENTORY", $"item.remove: insufficient '{id}' (need {count})");
}
}
}