This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
/
character.go
executable file
·92 lines (80 loc) · 2.21 KB
/
character.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package models
import (
"fmt"
"io/ioutil"
"strings"
yaml "gopkg.in/yaml.v2"
)
// Character represents a single player character
type Character struct {
PortraitURL string `yaml:"portrait_url"`
Name string `yaml:"name"`
Age int `yaml:"age"`
FakeID string `yaml:"fake_id"`
Race string `yaml:"race"`
Height float64 `yaml:"height"`
Weight float64 `yaml:"weight"`
Origin string `yaml:"origin"`
PreferedHand string `yaml:"prefered_hand"`
XPs int `yaml:"xps"`
SpentXPs int `yaml:"spent_xps"`
HitPoints int `yaml:"hit_points"`
Fatigue int `yaml:"fatigue"`
ForcePoints int `yaml:"force_points"`
BaseMovement int `yaml:"base_movement"`
Wealth Wealth `yaml:"wealth"`
Formations []Formation `yaml:"formations"`
Talents []Talent `yaml:"talents"`
Stats []Stat `yaml:"stats"`
Skills []Stat `yaml:"skills"`
Spells []Spell `yaml:"spells"`
Equipment Equipment `yaml:"equipment"`
Inventory []QuantifiedItem `yaml:"inventory"`
}
// Load loads a character with the given yaml file
func (c *Character) Load(fp string) error {
var err error
var cr []byte
if cr, err = ioutil.ReadFile(fp); err != nil {
return err
}
if err = yaml.Unmarshal(cr, c); err != nil {
return err
}
c.Enrich()
return nil
}
// Enrich will execute many operations to try and enrich the character will
// computable data
func (c *Character) Enrich() {
for i := range c.Stats {
c.Stats[i].MatchIcon()
}
for i := range c.Skills {
c.Skills[i].MatchIcon()
}
for i := range c.Equipment.Weapons {
c.Equipment.Weapons[i].MatchIcon()
}
for i := range c.Equipment.RangedWeapons {
c.Equipment.RangedWeapons[i].MatchIcon()
}
for i := range c.Spells {
c.Spells[i].Enrich()
}
}
// Stat can be a main stat or an extra stat (in which case, rank and base
// are not taken into account)
type Stat struct {
Name string `yaml:"name"`
Base int `yaml:"base"`
Rank string `yaml:"rank"`
Modifier int `yaml:"modifier"`
Icon string `yaml:"icon"`
}
// MatchIcon will assign a default icon if none is given
func (s *Stat) MatchIcon() {
if s.Icon == "" {
s.Icon = fmt.Sprintf("%s.svg", strings.ToLower(s.Name))
}
}