-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhero.go
More file actions
48 lines (41 loc) · 981 Bytes
/
hero.go
File metadata and controls
48 lines (41 loc) · 981 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"encoding/json"
)
type Hero struct {
Name string
Level int
Feats []FeatName
Ancestry []AncestryName
Profession []ProfessionName
}
func (hero *Hero) getStats() map[StatName]int {
result := ZeroStats()
for _, ancestryName := range hero.Ancestry {
ancestry := getAncestryByCode(ancestryName)
for statName, statValue := range ancestry.StatChange {
result[statName] += statValue
}
}
for _, professionName := range hero.Profession {
profession := getProfessonByCode(professionName)
for statName, statValue := range profession.StatChange {
result[statName] += statValue
}
}
for _, featName := range hero.Feats {
feat := Feats[featName]
for statName, statValue := range feat.StatChange {
result[statName] += statValue
}
}
return result
}
func (hero Hero) String() string {
result, err := json.MarshalIndent(hero, "", " ")
if err == nil {
return string(result)
} else {
return err.Error()
}
}