-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.go
43 lines (36 loc) · 899 Bytes
/
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
package main
import (
"fmt"
"math/rand"
)
type Character struct {
Event string `json:"event"`
Name string `json:"name"`
Race string `json:"race"`
Ability string `json:"ability"`
}
func generateRandomCharacter(event string) (Character, error) {
basePath := fmt.Sprintf("./assets/%s/", event)
names, err := readFromFile(basePath + "names.txt")
if err != nil {
return Character{}, err
}
races, err := readFromFile(basePath + "race.txt")
if err != nil {
return Character{}, err
}
abilities, err := readFromFile(basePath + "ability.txt")
if err != nil {
return Character{}, err
}
name := names[rand.Intn(len(names))] + " " + names[rand.Intn(len(names))]
race := races[rand.Intn(len(races))]
ability := abilities[rand.Intn(len(abilities))]
character := Character{
Event: event,
Name: name,
Race: race,
Ability: ability,
}
return character, nil
}