Skip to content

Items

namespace Griff.Scenes;
public static class Items

Items and resources, the one idea every genre shares: an item is a name (“Key”, “Gold”, “Dirt”, “Mana”) and how many, held by anything that holds items (see IHoldsItems). Lists of them read the same everywhere: “Coin 3, Map”, “150 Gold, 50 Wood” (the count before or after the name, 1 if it doesn’t say), separated by commas, semicolons or “+”. A cost is such a list: what a strategy unit takes to train, a card to play beside its mana, a pickup to buy in a shop. Something pays from (and collects into) the items on it or the entity it’s inside, else its team’s (an inventory or faction whose For Team is its team).

public static bool CanPay(Entity? entity, string? cost, string? team)

True if entity has everything cost asks for, e.g. “150 Gold, 50 Wood”.

public static int Count(Entity? entity, string item, string? team)

How many of item``entity has to pay with (see HolderOf).

public static string Describe(string? cost)

“150 Gold, 50 Wood”: the way a cost reads, or “Free” for nothing.

public static IHoldsItems? HolderOf(Entity? entity, string item, string? team)

What holds item for entity: something holding items on it or the entity it’s inside, else what holds team’s items (see ForTeam). Null if nothing does.

public static string? Lacking(Entity? entity, string? cost, string? team)

The first item of cost that entity hasn’t enough of, e.g. “Wood”; null if it can pay.

public static List<ValueTuple<string, int>> Parse(string? text)

The items in text in order, each a name and how many: “Coin 3, Map”, “150 Gold; 50 Wood”, “Rope + Hook”. Parts with a count of 0 or less are left out; the same item twice stays twice.

public static bool Pay(Entity? entity, string? cost, string? team)

Pays cost if entity can; returns whether it did. Nothing is taken if it can’t pay it all.

public static ValueTuple<string, int> ReadOne(string? text)

One item and how many: “Key 2”, “150 Gold” or “Map” (one). The name may have spaces (“Iron Ore 5”).

public static IReadOnlyList<ValueTuple<string, int>> Totals(string? text)

text read as Parse reads it, with each item once (counts added up): what a cost asks for. Kept once read, so reading the same text every frame makes no garbage.

public static string Write(string item, int count, bool countFirst = false)

One item written as a row of a list: “Key 2”, or “Key” for one; with countFirst, “2 Key” (“1 Key”).