-
Notifications
You must be signed in to change notification settings - Fork 2
/
wandering_dmg.go
188 lines (145 loc) · 3.88 KB
/
wandering_dmg.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
package main
import (
"log"
"strconv"
"strings"
"github.com/bwmarrin/discordgo"
)
var (
wanderingDmg wanderingData
)
func initWanderingDmg() {
var err error
log.Printf("loading wandering damage info")
err = loadInfo("wandering/wandering_dmg.json", &wanderingDmg)
if err != nil {
log.Printf("%s", err)
log.Fatalf("there was an issue reading the wandering file\n")
}
// log.Printf("%v", wanderingDmg)
log.Printf("wandering damage info loaded")
}
func rollWanderingDamage() (response string, discordEmbed discordgo.MessageEmbed, sendToDM bool) {
var outcome int
var damage int
var wander = true
var damageData wandering
for _, data := range wanderingDmg.Data {
if data.Type == "wandering_damage" {
damageData = data
}
}
if len(damageData.Table) == 0 {
log.Print("no loot to hand out")
return
}
for wander {
rolls := roll(damageData.Roll.Dice, damageData.Roll.Value)
log.Printf("These are the rolls '%d'", rolls)
outcome = total(rolls)
log.Printf("This is the outcome '%d'", outcome)
// this should never happen. If it does let me know...
if outcome == 0 {
log.Printf("If you ever log this line please open a github issue...")
return
}
for _, value := range damageData.Table {
if value.Outcome.Exact == outcome || between(value.Outcome.Range.Min, value.Outcome.Range.Max, outcome) {
response = response + "\n" + value.Result
if value.Limb {
log.Printf("rolling for limb loss")
response = response + rollWanderingDMGLimbLoss()
}
if value.Random {
log.Printf("rolling on the random damage table")
response = response + rollWangeringDmgRandom()
}
if value.Wander {
log.Printf("rolling on the wandering table again")
}
if !value.Wander {
wander = value.Wander
}
if value.Damage {
log.Printf("rolling for damage")
rolls = roll(value.Roll.Dice, value.Roll.Value)
damage = total(rolls)
response = strings.Replace(value.Result, "&damage&", strconv.Itoa(damage), -1)
}
}
}
}
discordEmbed = discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
Name: "Wandering Monster Bot",
},
Fields: []*discordgo.MessageEmbedField{
&discordgo.MessageEmbedField{
Name: "",
Value: "",
},
},
}
// log.Printf("response: %s", response)
return
}
func rollWanderingDMGLimbLoss() (result string) {
log.Printf("rolling for limb loss")
var outcome int
var limbData wandering
for _, data := range wanderingDmg.Data {
if data.Type == "limb_loss" {
limbData = data
}
}
if len(limbData.Table) == 0 {
return
}
rolls := roll(limbData.Roll.Dice, limbData.Roll.Value)
outcome = total(rolls)
for _, value := range limbData.Table {
if value.Outcome.Exact == 0 {
} else if value.Outcome.Exact == outcome || between(value.Outcome.Range.Min, value.Outcome.Range.Max, outcome) {
result = value.Result
}
}
return
}
func rollWangeringDmgRandom() (result string) {
log.Printf("rolling for random damages")
var outcome int
var reroll = true
var rerollData wandering
for _, data := range wanderingDmg.Data {
if data.Type == "random_damage" {
rerollData = data
}
}
if len(rerollData.Table) == 0 {
return
}
for reroll {
rolls := roll(rerollData.Roll.Dice, rerollData.Roll.Value)
outcome = total(rolls)
log.Printf("outcome is %d", outcome)
log.Printf("rolling for wandering damage random subtable")
for _, value := range rerollData.Table {
if value.Outcome.Exact == outcome || between(value.Outcome.Range.Min, value.Outcome.Range.Max, outcome) {
result = result + "\n" + value.Result
log.Printf("%t", value.Random)
if value.Limb {
log.Printf("rolling for limb loss")
result = result + rollWanderingDMGLimbLoss()
}
if value.Random == false {
reroll = false
} else {
reroll = value.Random
}
}
}
log.Printf("result %s", result)
log.Printf("reroll %t", reroll)
}
return
}