/
spells.go
97 lines (87 loc) · 1.79 KB
/
spells.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
package game
import (
"math/rand"
"github.com/Ariemeth/go-quest/internal/comparison"
)
var (
spellList = []string{
"Slime Finger",
"Rabbit Punch",
"Hastiness",
"Good Move",
"Sadness",
"Seasick",
"Gyp",
"Shoelaces",
"Innoculate",
"Cone of Annoyance",
"Magnetic Orb",
"Invisible Hands",
"Revolting Cloud",
"Aqueous Humor",
"Spectral Miasma",
"Clever Fellow",
"Lockjaw",
"History Lesson",
"Hydrophobia",
"Big Sister",
"Cone of Paste",
"Mulligan",
"Nestor's Bright Idea",
"Holy Batpole",
"Tumor (Benign)",
"Braingate",
"Nonplus",
"Animate Nightstand",
"Eye of the Troglodyte",
"Curse Name",
"Dropsy",
"Vitreous Humor",
"Roger's Grand Illusion",
"Covet",
"Astral Miasma",
"Spectral Oyster",
"Acrid Hands",
"Angioplasty",
"Grognor's Big Day Off",
"Tumor (Malignant)",
"Animate Tunic",
"Ursine Armor",
"Holy Roller",
"Tonsilectomy",
"Curse Family",
"Infinite Confusion",
}
)
// Spellbook are the list of spells that make up the player's spellbook.
type Spellbook struct {
spells map[string]uint64
}
// NewSpellbook creates and initializes a Spellbook.
func NewSpellbook() Spellbook {
return Spellbook{spells: make(map[string]uint64)}
}
// IncreaseRandomSpell will
func (s *Spellbook) IncreaseRandomSpell(wisdom uint32, level uint64) {
max := uint64(wisdom) + level
var maxSpellIndex int
if max > uint64(len(spellList)) {
maxSpellIndex = len(spellList) - 1
} else {
maxSpellIndex = comparison.MinInt2(int(max), len(spellList)-1)
}
si := randomLowIndex(maxSpellIndex)
if si > len(spellList)-1 {
si = len(spellList) - 1
}
spell := spellList[si]
s.spells[spell] = s.spells[spell] + 1
}
func randomLowIndex(max int) int {
if max < 0 {
max = 0
}
a := rand.Intn(max)
b := rand.Intn(max)
return comparison.MinInt2(a, b)
}