From 51723cfd9a7d31643fa7c14cc2df9d8e9e2bd33d Mon Sep 17 00:00:00 2001 From: JP Appel Date: Fri, 13 Sep 2024 14:32:15 -0400 Subject: Add money and head handling functions Created types to manage the cannonical coinage of DnD. First pass at computing computing values for heads. --- economy/heads.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 economy/heads.go (limited to 'economy/heads.go') diff --git a/economy/heads.go b/economy/heads.go new file mode 100644 index 0000000..15c9456 --- /dev/null +++ b/economy/heads.go @@ -0,0 +1,37 @@ +package economy + +import ( + "maps" +) + +type Location uint +type CostFunc func(cr float32, mutiplier float32, modifier float32) Money + +const ( + Field Location = iota + Display + Storage +) + +type Head struct { + Location Location + Conditions struct { + Multipliers map[string]float32 + Modifiers map[string]float32 + } + CR float32 +} + +func (h Head) Value(cost CostFunc) Money { + var multiplier float32 = 1 + for val := range maps.Values(h.Conditions.Multipliers) { + multiplier *= val + } + + var modifier float32 = 0 + for val := range maps.Values(h.Conditions.Modifiers) { + modifier += val + } + + return cost(h.CR, multiplier, modifier) +} -- cgit v1.2.3