-
Notifications
You must be signed in to change notification settings - Fork 0
/
chars.go
132 lines (123 loc) · 2.37 KB
/
chars.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package main
import (
"fmt"
"math/rand"
"strings"
)
type char struct {
name string
age int
st int
dx int
en int
in int
ed int
ss int
careers []career
skills []skill
homeworld planet
events []lifeEvent
}
var characteristicMods map[int]int = map[int]int{
0: -2,
1: -2,
2: -1,
3: -1,
4: -1,
5: -1,
6: 0,
7: 0,
8: 0,
9: 1,
10: 1,
11: 1,
12: 2,
13: 2,
14: 2,
15: 3,
16: 3,
17: 3,
18: 4,
19: 4,
20: 4,
}
type skill struct {
name string
level int
}
func newChar(r *rand.Rand) char {
return char{
name: fullName(r),
age: 18,
st: dn(r, 2),
dx: dn(r, 2),
en: dn(r, 2),
in: dn(r, 2),
ed: dn(r, 2),
ss: dn(r, 2),
careers: []career{},
homeworld: newPlanet(r, nil, nil),
events: []lifeEvent{
birthEvent{},
majorityEvent{},
},
skills: []skill{},
}
}
func charCareer(r *rand.Rand, c *char) {
service := randCareer(r, allCareers())
c.careers = append(c.careers, service)
if !enlist(r, service, *c) {
c.events = append(c.events, failedToJoinServiceEvent{
service: service,
age: c.age,
})
if d(r) < 4 {
c.events = append(c.events, draftedEvent{
service: drifter,
age: c.age,
})
c.careers = append(c.careers, drifter)
} else {
service := randCareer(r, draftCareers)
c.events = append(c.events, draftedEvent{
service: service,
age: c.age,
})
c.careers = append(c.careers, service)
}
return
}
c.events = append(c.events, joinedServiceEvent{
service: service,
age: c.age,
})
}
func skillsList(skills []skill) string {
ret := []string{}
for _, s := range skills {
ret = append(ret, fmt.Sprintf("%s-%d", s.name, s.level))
}
return strings.Join(ret, ", ")
}
func (c char) String() string {
ret := []string{}
ret = append(ret, fmt.Sprintf("%s %X%X%X%X%X%X, from %s (%s), %d y.o., %s. %s",
c.name, c.st, c.dx, c.en, c.in, c.ed, c.ss,
c.homeworld.name, c.homeworld.uwp(),
c.age, c.careers[0].name,
skillsList(c.skills)))
for _, e := range c.events {
ret = append(ret, fmt.Sprintf("%3d - %s", e.Age(), e.Name()))
}
return strings.Join(ret, "\n") + "\n"
}
func chars(r *rand.Rand) string {
ret := []string{}
for i := 0; i < 10; i++ {
ch := newChar(r)
charCareer(r, &ch)
ret = append(ret, ch.String())
}
return strings.Join(ret, "\n")
}