forked from engooyen/majel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
235 lines (219 loc) · 7.64 KB
/
Copy pathutils.js
File metadata and controls
235 lines (219 loc) · 7.64 KB
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
/**
* Copyright 2019 John H. Nguyen
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
let fs = require("fs")
let species = JSON.parse(
fs.readFileSync("./data/species.json", { encoding: "utf8" })
)
module.exports = {
/**
* this.shuffles elements of an array and returns the this.shuffled array.
* @param a The array to this.shuffle.
* @return The this.shuffled array.
*/
shuffle(a) {
let j, x, i
for (i = a.length - 1; i > 0; i--) {
j = Math.floor(Math.random() * (i + 1))
x = a[i]
a[i] = a[j]
a[j] = x
}
return a
},
/**
* Finds the attribute in a map and returns the modifier value. If the
* attribute doesn't exist, 0 is returned.
* @param name The name of the attribute.
* @param attributes The key value map of attributes to modifier value.
* @return The attribute modifier.
*/
findAttribute(name, attributes) {
return attributes[name] || 0
},
/**
* Generates a random support character.
* @return The generated support character as a string.
*/
generateSupportCharacter() {
species = this.shuffle(species)
let race = species[0]
let gender = this.shuffle(["Female", "Male"])[0]
let firstName = this.shuffle(race[gender])[0]
let lastName = this.shuffle(race["Family"])[0]
let attributePool = this.shuffle([10, 10, 9, 9, 8, 7])
let attributes = [
"Control (" +
(attributePool[0] +
this.findAttribute("Control", race.AttributeBonus)) +
")",
"Fitness (" +
(attributePool[1] +
this.findAttribute("Fitness", race.AttributeBonus)) +
")",
"Presence (" +
(attributePool[2] +
this.findAttribute("Presence", race.AttributeBonus)) +
")",
"Daring (" +
(attributePool[3] + this.findAttribute("Daring", race.AttributeBonus)) +
")",
"Insight (" +
(attributePool[4] +
this.findAttribute("Insight", race.AttributeBonus)) +
")",
"Reason (" +
(attributePool[5] + this.findAttribute("Reason", race.AttributeBonus)) +
")"
]
let disciplinePool = this.shuffle([4, 3, 2, 2, 1, 1])
let disciplines = [
"Command (" + disciplinePool[0] + ")",
"Conn (" + disciplinePool[1] + ")",
"Security (" + disciplinePool[2] + ")",
"Engineering (" + disciplinePool[3] + ")",
"Science (" + disciplinePool[4] + ")",
"Medicine (" + disciplinePool[5] + ")"
]
let talent = this.shuffle(race.Talents)[0]
return {
title: firstName + " " + lastName,
description: "Generated support character",
fields: [
{
name: "Race",
value: race.Name
},
{
name: "Gender",
value: gender
},
{
name: "Attributes",
value: attributes.join(", ")
},
{
name: "Disciplines",
value: disciplines.join(", ")
},
{
name: "Talent",
value: talent
}
]
}
},
/**
* Enumerates a dictionary and inserts a delimiter.
* @param d The dictionary to enumerate.
* @param delimiter The delimiter to insert between the key value pairs.
*/
enumerateDictionary(d, delimiter) {
let str = ""
for (let key in d) {
if (str) {
str += delimiter
}
str += "**" + key + "**: " + d[key]
}
return str
},
getPlayerSheets(bot, callback) {
let players = []
let channels = bot.channels.array()
for (let c in channels) {
let channel = channels[c]
if (channel.name.toLowerCase() === "player-sheets") {
channel.fetchMessages().then(messages => {
try {
let msgs = messages.array()
for (let m in msgs) {
let msg = msgs[m].content
let player = {}
let playerData = msg.split("\n")
let collectTalents = false
for (let i = 0; i < playerData.length; ++i) {
if (playerData[i].indexOf("Talents") > -1) {
collectTalents = true
player["Talents"] = {}
continue
}
let kvp = playerData[i].split(": ")
if (!collectTalents) {
if (kvp[0] === "Attributes") {
let attributes = kvp[1].split(" ")
player[kvp[0]] = {
Control: attributes[0],
Daring: attributes[1],
Fitness: attributes[2],
Insight: attributes[3],
Presence: attributes[4],
Reason: attributes[5]
}
} else if (kvp[0] === "Disciplines") {
let disciplines = kvp[1].split(" ")
player[kvp[0]] = {
Command: disciplines[0],
Conn: disciplines[1],
Security: disciplines[2],
Engineering: disciplines[3],
Science: disciplines[4],
Medicine: disciplines[5]
}
} else if (kvp[0] === "Systems") {
let systems = kvp[1].split(" ")
player[kvp[0]] = {
Engines: systems[0],
Computers: systems[1],
Weapons: systems[2],
Structure: systems[3],
Sensors: systems[4],
Communications: systems[5]
}
} else if (kvp[0] === "Departments") {
let departments = kvp[1].split(" ")
player[kvp[0]] = {
Command: departments[0],
Security: departments[1],
Science: departments[2],
Conn: departments[3],
Engineering: departments[4],
Medicine: departments[5]
}
} else {
player[kvp[0]] = kvp[1]
}
} else {
player["Talents"][kvp[0]] = kvp[1]
}
}
players.push(player)
}
} catch (error) {
console.warn(error)
}
})
callback(players)
return
}
}
console.warn("player-sheets channel not found on this server!")
}
}