-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
game.go
101 lines (84 loc) · 2.67 KB
/
game.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
package gofakeit
import (
"fmt"
"strings"
)
// Gamertag will generate a random video game username
func Gamertag() string { return gamertag(GlobalFaker) }
// Gamertag will generate a random video game username
func (f *Faker) Gamertag() string { return gamertag(f) }
func gamertag(f *Faker) string {
str := ""
num := number(f, 1, 4)
switch num {
case 1:
str = fmt.Sprintf("%s%ser", title(nounConcrete(f)), title(verbAction(f)))
case 2:
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(animal(f)))
case 3:
str = fmt.Sprintf("%s%s", title(adjectiveDescriptive(f)), title(nounConcrete(f)))
case 4:
str = fmt.Sprintf("%s%s", title(fruit(f)), title(adjectiveDescriptive(f)))
}
// Randomly determine if we should add a number
if f.IntN(3) == 1 {
str += digitN(f, uint(number(f, 1, 3)))
}
// Remove any spaces
str = strings.Replace(str, " ", "", -1)
return str
}
// Dice will generate a random set of dice
func Dice(numDice uint, sides []uint) []uint { return dice(GlobalFaker, numDice, sides) }
// Dice will generate a random set of dice
func (f *Faker) Dice(numDice uint, sides []uint) []uint { return dice(f, numDice, sides) }
func dice(f *Faker, numDice uint, sides []uint) []uint {
dice := make([]uint, numDice)
// If we dont have any sides well set the sides to 6
if len(sides) == 0 {
sides = []uint{6}
}
for i := range dice {
// If sides[i] doesnt exist use the first side
if len(sides)-1 < i {
dice[i] = uint(number(f, 1, int(sides[0])))
} else {
dice[i] = uint(number(f, 1, int(sides[i])))
}
}
return dice
}
func addGameLookup() {
AddFuncLookup("gamertag", Info{
Display: "Gamertag",
Category: "game",
Description: "User-selected online username or alias used for identification in games",
Example: "footinterpret63",
Output: "string",
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
return gamertag(f), nil
},
})
AddFuncLookup("dice", Info{
Display: "Dice",
Category: "game",
Description: "Small, cube-shaped objects used in games of chance for random outcomes",
Example: "[5, 2, 3]",
Output: "[]uint",
Params: []Param{
{Field: "numdice", Display: "Number of Dice", Type: "uint", Default: "1", Description: "Number of dice to roll"},
{Field: "sides", Display: "Number of Sides", Type: "[]uint", Default: "[6]", Description: "Number of sides on each dice"},
},
Generate: func(f *Faker, m *MapParams, info *Info) (any, error) {
numDice, err := info.GetUint(m, "numdice")
if err != nil {
return nil, err
}
sides, err := info.GetUintArray(m, "sides")
if err != nil {
return nil, err
}
return dice(f, numDice, sides), nil
},
})
}