Coin

Concrete Currency record representing the standard Townskeep monetary unit with gold, silver, and copper denominations. Provides implicit conversions, tuple decomposition, and indexer access.

Definition

Namespace: Paragon.Townskeep Assembly: Townskeep.dll

[Serializable]
public record Coin : Currency

Inheritance: Currency → Coin

Remarks

Coin decomposes a single int value into three denominations:

Denomination
Value
Decomposition

Gold

10,000

Value / 10000

Silver

100

(Value / 100) % 100

Copper

1

Value % 100

Implicit conversions allow ergonomic construction from int, (int, int, int) tuples, and back. Negative denomination values in the (gold, silver, copper) constructor are clamped to 0 via Mathf.Max.

Quick Lookup

Goal
How

Create from denominations

new Coin(2, 50, 75)

Create from raw value

new Coin(25075)

Implicit from int

Coin c = 25075;

Implicit from tuple

Coin c = (2, 50, 75);

Decompose to tuple

(int g, int s, int c) = coin;

Get denomination by index

coin[0] (gold), coin[1] (silver), coin[2] (copper)

Display formatted

coin.ToString()"2g - 50s - 75c"

Compute raw from parts

Coin.GetValue(2, 50, 75)25075

Properties

Gold

Gold denomination (each gold = 10,000 base value).

Silver

Silver denomination (each silver = 100 base value, max 99 per gold).

Copper

Copper denomination (each copper = 1 base value, max 99 per silver).

Methods

Constructors

GetValue (static)

Converts gold/silver/copper to a raw integer. Clamps negative denominations to 0.

Parameter
Type
Description

gold

int

Gold count (clamped to >= 0)

silver

int

Silver count (clamped to >= 0)

copper

int

Copper count (clamped to >= 0)

Returns: gold * 10000 + silver * 100 + copper

ToString

Returns the formatted denomination string.

Returns: "Xg - Ys - Zc" (e.g., "2g - 50s - 75c")

Operators

implicit operator Coin(int)

Creates a Coin from a raw integer value.

implicit operator Coin((int, int, int))

Creates a Coin from a (gold, silver, copper) tuple.

implicit operator (int, int, int)(Coin)

Decomposes a Coin into a (gold, silver, copper) tuple.

Indexers

this[int]

Accesses a denomination by index: 0 = Gold, 1 = Silver, 2 = Copper.

Index
Denomination

0

Gold

1

Silver

2

Copper

Throws: IndexOutOfRangeException for index outside 0-2.

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation

Examples

Price Comparison

Iterating Denominations

See Also

Last updated