-
Notifications
You must be signed in to change notification settings - Fork 0
/
traits.go
108 lines (92 loc) · 2.32 KB
/
traits.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
package aifiver
import "log"
// Trait represents a character trait that influences behavior and decisions.
type Trait struct {
Type TraitType
Opposite *Trait
Name string
Description string
IsExpressedBy func(*Personality) bool
*Stats // Contains all modifiers.
}
// NewTrait returns a new trait.
func NewTrait(name string, t TraitType, cond func(p *Personality) bool) *Trait {
return &Trait{
Name: name,
Type: t,
Stats: NewStats(),
IsExpressedBy: cond,
}
}
// Log logs the trait.
func (t *Trait) Log() {
log.Println(t.Name)
}
// MarkOppositeTraits defines two traits as their polar opposite.
func MarkOppositeTraits(a, b *Trait) {
a.Opposite = b
b.Opposite = a
}
// mergeTraitSets returns a combined set of traits.
// TODO: Filter out opposites that can not co-exist.
func mergeTraitSets(a, b []*Trait) []*Trait {
seenTrait := make(map[*Trait]bool)
var result []*Trait
for _, t := range a {
if seenTrait[t] {
continue
}
seenTrait[t] = true
result = append(result, t)
}
for _, t := range b {
if seenTrait[t] {
continue
}
seenTrait[t] = true
result = append(result, t)
}
return result
}
// TraitType defining how a trait can be aquired
type TraitType int
// Various trait types.
const (
TTypePersonality TraitType = iota
TTypeEducation
TTypeCongenital
TTypeCongenitalLeveled
TTypePhysical
TTypeLifestyle
TTypeLifestyleLeveled
TTypeCommander
TTypeInfamous
TTypeCopingMechanism
TTypeChildhood
TTypeHealth
TTypeDiseases
TTypeDynasty
TTypeDescendant
TTypeDecision
TTypeOther
)
// Traiter is an index used for assigning traits to personalities.
type Traiter struct {
Traits []*Trait
}
// NewTraiter returns a new Traiter index.
func NewTraiter() *Traiter {
return &Traiter{}
}
// NewPersonality returns a new, pretty boring personality.
func (tt *Traiter) NewPersonality() *Personality {
return NewPersonality(tt)
}
// NewPersonalityFromPreset returns a new personality based on the given preset.
func (tt *Traiter) NewPersonalityFromPreset(ps map[Facet]int) *Personality {
return NewPersonalityFromPreset(tt, ps)
}
// AddTrait registers the given trait.
func (tt *Traiter) AddTrait(t *Trait) {
tt.Traits = append(tt.Traits, t)
}