aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/economy/heads.go
blob: 15c94569d2cb7dbcd205e489def364d35c8ac168 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
}