-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter.go
466 lines (384 loc) · 9.78 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
package runequest
import (
"fmt"
"sort"
"strings"
)
// Character represents a generic RPG character
type Character struct {
Name string
Role string
// Type of Character - Player, NPC, Creature, etc.
Description string
Homeland *Homeland
Occupation *Occupation
Cult *Cult
ExtraCults []*ExtraCult
Age int
Clan string
Tribe string
Abilities map[string]*Ability
// Passions and Reputation
ElementalRunes map[string]*Ability
// Elemental Runes
PowerRunes map[string]*Ability
ConditionRunes map[string]*Ability
CoreRunes []*Ability
Statistics map[string]*Statistic
Attributes map[string]*Attribute
CurrentHP int
CurrentMP int
CurrentRP int
Movement []*Movement
DerivedMap []string
Skills map[string]*Skill
SkillMap []string
SkillCategories map[string]*SkillCategory
Advantages map[string]*Advantage
AdvantageMap []string
RuneSpells map[string]*Spell
SpiritMagic map[string]*Spell
Powers map[string]*Power
LocationForm string
HitLocations map[string]*HitLocation
HitLocationMap []string
MeleeAttacks map[string]*Attack
RangedAttacks map[string]*Attack
Equipment []string
BoundSpirits []*BoundSpirit
Income int
Lunars int
Ransom int
StandardofLiving string
InPlay bool
Updates []*Update
CreationSteps map[string]bool
History []*Event
Grandparent *FamilyMember
Parent *FamilyMember
Tags []string
Notes string
}
// CharacterRoles is an array of options for Character.Role
var CharacterRoles = []string{
"Player Character",
"Non-Player Character",
"Animal",
"Chaos",
"Creature",
"Demon",
"Elemental",
"Spirit",
}
// Update tracks live changes to Character
type Update struct {
Date string
Event string
Value int
}
// UpdateCharacter updates stats, runes and skills based on them
func (c *Character) UpdateCharacter() {
c.TotalStatistics()
c.DetermineSkillCategoryValues()
// This can be optimized
c.SetAttributes()
c.UpdateAttributes()
c.IDCoreRunes()
c.UpdateAttacks()
if len(c.HitLocations) == 0 {
hlForms := LocationForms[c.LocationForm]
c.HitLocationMap = SortLocations(hlForms)
c.HitLocations = hlForms
}
}
// TotalStatistics updates values for stats after being modified
func (c *Character) TotalStatistics() {
for _, s := range c.Statistics {
s.UpdateStatistic()
}
}
// CreationStatus tracks the completion of character creation
var CreationStatus = map[string]bool{
"Base Choices": false,
"Personal History": false,
"Rune Affinities": false,
"Roll Stats": false,
"Apply Homeland": false,
"Apply Occupation": false,
"Apply Cult": false,
"Personal Skills": false,
"Finishing Touches": false,
"Complete": false,
}
func (c Character) String() string {
text := fmt.Sprintf("\n--- %s ---\n", c.Name)
if len(c.CoreRunes) > 0 {
text += "Runes: "
for _, cr := range c.CoreRunes {
text += fmt.Sprintf("%s ", cr.Name)
}
text += "\n"
}
text += fmt.Sprintf("\nType: %s", c.Role)
if c.Role == "Player Character" {
text += fmt.Sprintf("\nHomeland: %s", c.Homeland.Name)
text += fmt.Sprintf("\nOccupation: %s", c.Occupation.Name)
text += fmt.Sprintf("\n%s of Cult: %s", c.Cult.Rank, c.Cult.Name)
text += fmt.Sprintf("\nStandard of Living: %s", c.StandardofLiving)
text += fmt.Sprintf("\nIncome: %d L", c.Income)
text += fmt.Sprintf("\nRansom: %d L", c.Ransom)
}
text += fmt.Sprintf("\n\nDescription:\n%s", c.Description)
if len(c.Statistics) > 0 {
text += "\n\nStats:\n"
for _, stat := range StatMap {
if c.Statistics[stat].Total > 0 {
text += fmt.Sprintf("%s (%d%%)\n", c.Statistics[stat],
c.Statistics[stat].Total*5)
}
}
}
if len(c.Attributes) > 0 {
text += "\nDerived Stats:\n"
for _, ds := range c.Attributes {
text += fmt.Sprintf("%s\n", ds)
}
}
if len(c.Movement) > 0 {
text += "\nMovement:\n"
for _, m := range c.Movement {
text += fmt.Sprintf("%s\n", m)
}
}
if len(c.Abilities) > 0 {
text += "\nPassions & Reputations:"
for _, ability := range c.Abilities {
text += fmt.Sprintf("\n%s", ability)
}
}
if c.Cult.Name != "" {
text += fmt.Sprintf("\n\n**Cults:\n%s - %s - Rune Points: %d", c.Cult.Name, c.Cult.Rank, c.Cult.NumRunePoints)
}
if len(c.ExtraCults) > 0 {
for _, ec := range c.ExtraCults {
text += fmt.Sprintf("\n%s - %s Rune Points: %d", ec.Name, ec.Rank, ec.RunePoints)
}
}
if len(c.ElementalRunes) > 0 {
text += "\n\nElemental Runes:"
for _, ability := range c.ElementalRunes {
if ability.Total != 0 {
text += fmt.Sprintf("\n%s", ability)
}
}
}
if len(c.PowerRunes) > 0 {
text += "\n\nPower Runes:"
for _, ability := range c.PowerRunes {
if ability.Total != 0 {
text += fmt.Sprintf("\n%s", ability)
}
}
}
if len(c.ConditionRunes) > 0 {
text += "\n\nCondition Runes:"
for _, ability := range c.ConditionRunes {
if ability.Total != 0 {
text += fmt.Sprintf("\n%s", ability)
}
}
}
if len(c.Skills) > 0 {
text += "\n\nSkills:"
if len(c.Skills) > 20 {
keys := make([]string, 0, len(c.Skills))
for k := range c.Skills {
keys = append(keys, k)
}
sort.Strings(keys)
for _, co := range CategoryOrder {
sc := c.SkillCategories[co]
text += fmt.Sprintf("\n**%s**\n", sc)
for _, skill := range keys {
if c.Skills[skill].Category == sc.Name {
text += fmt.Sprintf("%s\n", c.Skills[skill])
}
}
}
} else {
text += "\n"
for _, skill := range c.Skills {
text += fmt.Sprintf("%s\n", skill)
}
}
}
if len(c.SpiritMagic) > 0 {
text += "\nSpirit Magic:\n"
for _, sm := range c.SpiritMagic {
text += fmt.Sprintf("%s\n", sm)
}
}
if len(c.RuneSpells) > 0 {
text += "\nRune Spells:\n"
for _, rs := range c.RuneSpells {
text += fmt.Sprintf("%s\n", rs)
}
}
if len(c.Powers) > 0 {
text += "\nPowers:\n"
for _, p := range c.Powers {
text += fmt.Sprintf("%s: %s\n", p.Name, p.Description)
}
}
if len(c.BoundSpirits) > 0 {
text += "\nSpirits & Matrices:\n"
for _, bs := range c.BoundSpirits {
text += bs.String() + "\n"
}
}
if len(c.MeleeAttacks) > 0 {
text += "\nMelee Attacks:\n"
for _, m := range c.MeleeAttacks {
text += fmt.Sprintf("%s\n", m)
}
}
if len(c.RangedAttacks) > 0 {
text += "\nRanged Attacks:\n"
for _, r := range c.RangedAttacks {
text += fmt.Sprintf("%s\n", r)
}
}
if len(c.HitLocations) > 0 {
text += "\nHit Locations:\n"
for _, hlm := range c.HitLocationMap {
for k, v := range c.HitLocations {
if k == hlm {
text += fmt.Sprintf("%s", v)
}
}
}
}
if len(c.Equipment) > 0 {
text += "\nEquipment:\n"
for _, e := range c.Equipment {
text += fmt.Sprintf("%s\n", e)
}
}
return text
}
// StatBlock returns a summary text block
func (c Character) StatBlock() string {
text := fmt.Sprintf("\n** %s **\n\n", c.Name)
if len(c.CoreRunes) > 0 {
text += "Runes: "
for _, cr := range c.CoreRunes {
text += fmt.Sprintf("%s ", cr.Name)
}
}
if c.Role == "Player Character" {
text += fmt.Sprintf("\nHomeland: %s, ", c.Homeland.Name)
text += fmt.Sprintf("Occupation: %s, ", c.Occupation.Name)
text += fmt.Sprintf("%s of Cult: %s", c.Cult.Rank, c.Cult.Name)
}
if len(c.Statistics) > 0 {
text += "\n\n"
for _, stat := range StatMap {
if c.Statistics[stat].Total > 0 {
text += fmt.Sprintf("%s: %d, ", stat, c.Statistics[stat].Total)
}
}
}
text = strings.TrimSuffix(text, ",")
if len(c.Attributes) > 0 {
text += "\n\nDerived Stats: "
for k, ds := range c.Attributes {
if k == "DB" || k == "HP" || k == "MP" {
text += fmt.Sprintf("%s, ", ds)
}
}
}
text = strings.TrimSuffix(text, ",")
if len(c.Movement) > 0 {
text += "Movement- "
for _, m := range c.Movement {
text += fmt.Sprintf("%s, ", m)
}
}
hp := NumToArray(c.Attributes["HP"].Base)
text += fmt.Sprintf("\n\nHP: -1 0 %s", printIntArray(hp))
if len(c.Abilities) > 0 {
text += "\n\nPassions: "
text += strings.TrimSuffix(formatAbilityMap(c.Abilities), ",")
}
text = strings.TrimSuffix(text, ",")
if c.Cult.Name != "" {
text += fmt.Sprintf("\n\nCults: %s - %s - Rune Points: %d", c.Cult.Name, c.Cult.Rank, c.Cult.NumRunePoints)
}
if len(c.ExtraCults) > 0 {
for _, ec := range c.ExtraCults {
text += fmt.Sprintf("\n%s - %s Rune Points: %d", ec.Name, ec.Rank, ec.RunePoints)
}
}
text += "\n\nRunes: "
text += c.formatRunes()
text = strings.TrimSuffix(text, ",")
topSkills := sortedSkills(c.Skills)
ts := len(topSkills)
if ts > 14 {
ts = 14
}
if ts > 0 {
text += "\n\nSkills: "
text += formatSkillArray(topSkills[:ts])
}
if len(c.SpiritMagic) > 0 {
text += "\n\nSpirit Magic: "
text += formatSpellPointerArray(c.SpiritMagic)
}
if len(c.RuneSpells) > 0 {
text += "\n\nRune Spells: "
text += formatSpellPointerArray(c.RuneSpells)
}
if len(c.Powers) > 0 {
text += "\nPowers:\n"
for _, p := range c.Powers {
text += fmt.Sprintf("%s: %s\n", p.Name, p.Description)
}
}
if len(c.BoundSpirits) > 0 {
text += "\nSpirits & Matrices:\n"
for _, bs := range c.BoundSpirits {
text += bs.String() + "\n"
}
}
if len(c.MeleeAttacks) > 0 {
text += "\n\nAttacks:\n"
for _, m := range c.MeleeAttacks {
text += fmt.Sprintf("%s\n", m)
}
}
if len(c.RangedAttacks) > 0 {
for _, r := range c.RangedAttacks {
text += fmt.Sprintf("%s\n", r)
}
}
if len(c.HitLocations) > 0 {
text += "\nHit Locations:\n"
for _, hlm := range c.HitLocationMap {
for k, v := range c.HitLocations {
if k == hlm {
text += fmt.Sprintf("%s", v)
}
}
}
}
if len(c.Equipment) > 0 {
text += "\nEquipment:\n"
for _, e := range c.Equipment {
text += strings.TrimSuffix(fmt.Sprintf("%s, ", e), ",")
}
}
text = strings.TrimSuffix(text, ",")
return text
}
// Add DescribeCharacter here