This repository has been archived by the owner on Jan 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadbrk.js
274 lines (253 loc) · 10.5 KB
/
loadbrk.js
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//loadbrk.js, created by bunnynabbit (aka SmartLion on Brick Hill) and pb2007 (Podnf)
// Settings \\
sets = ["blocky","brkcanyon","house","house2","tower"] // Files to be loaded by the auto selector (ignored if flat-file-db already exists)
ownerAdminId = 1 // user id goes here (you can find this by looking at the number at the end of the url of your profile page)
countdownDefault = 600 // autoload time in seconds (default is 600 seconds, so an autoload happens every 10 minutes)
guiEnable = true
flatfiledbEnabled = false // (npm i flat-file-db) Uses flat-file-db to save sets added from /add and ports existing data from the sets array. If database already exists then the above hardcoded array wont be used
consoleOutput = true // if false, there will be no messages in the server console
// Settings \\
countdown = countdownDefault
if (flatfiledbEnabled == true) {
flatfile = require('flat-file-db');
db = flatfile('/tmp/loadbrkdata.db'); // This will create a folder called tmp at current drive
let readydb = 2
db.on('open', function() {
readydb = 1
let twig = db.has("setdb")
if (twig == true) {
twig = db.get("setdb")
if (consoleOutput) console.log(`Loaded save with ${twig.length} sets`)
sets = twig
autoload()
} else {
if (consoleOutput) console.log(`WARN: Save data not found! Creating save data.`)
if (consoleOutput) console.log(`${sets.length} sets ported into database`)
db.put("setdb",sets)
autoload()
}
});
} else {
autoload() // choose a random map to load on server start
}
Game.command("load", async(p,i) => { //TODO: tidy up the code
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
countdown = countdownDefault // reset the countdown
world.bricks.forEach(async(brick) => {
await sleep(2000)
brick.destroy()
})
await sleep(2000)
if (consoleOutput) console.log("loading "+i)
Game.messageAll(`\\c6Loading ${i}.brk`)
let data = await Game.loadBrk(`./maps/${i}.brk`)
Game.setEnvironment(data.environment)
Game.players.forEach((player) => {
player.respawn()
})
world.bricks.forEach(async(brick) => {
if (brick.name == "sb1") { //Gives 10 points
spawnscorebubble(brick.position,1)
await sleep (4000)
brick.destroy()
} else if (brick.name == "sb2") { //Gives 50 points
spawnscorebubble(brick.position,2)
await sleep (4000)
brick.destroy()
} else if (brick.name == "sb3") { //Gives 100 points
spawnscorebubble(brick.position,3)
await sleep (4000)
brick.destroy()
}
})
if (consoleOutput) console.log("loaded "+i)
})
Game.command("add", (p,i) => {
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
sets.push(i)
Game.messageAll(`\\c6${i}.brk has been added!`)
if (flatfiledbEnabled == true) {
db.put("setdb",sets)
}
})
Game.command("pop", (p,i) => {
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
var i = sets.pop()
Game.messageAll(`\\c6${i}.brk has been removed!`)
if (flatfiledbEnabled == true) {
db.put("setdb",sets)
}
})
Game.command("remove", (p,i) => {
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
x = sets.indexOf(i)
if (x == -1) return p.message(`\\c6Unable to find ${i}`)
sets.splice(x,1);
Game.messageAll(`\\c6${i}.brk has been removed!`)
if (flatfiledbEnabled == true) {
db.put("setdb",sets)
}
})
Game.command("guitoggle", (p,i) => {
// TODO: make it so that this command doesn't require admin and only affects you (so gui is only disabled for you)
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
guiEnable = !guiEnable;
})
Game.command("skip", async(p,i) => {
if (p.userId !== ownerAdminId) {p.message("\\c6Error: You cannot execute that command as you are not admin!"); return;} else {p.message("\\c5Success! You are an admin, so that command is being executed.");}
countdown = countdownDefault
autoload()
})
Game.command("sets", (p,i) => {
let x = []
for (let name of sets) {
x.push(` ${name}`)
}
p.message(`\\c5Sets:\\c0${String(x)}`)
})
// TODO: make a voteskip command that doesnt require admin and casts a vote if this map should be skipped
// only act on the autoload if there is a majority of yes
async function autoload() {
do {
if (consoleOutput) console.log("Rolling die for a new map...")
i = sets[randynumber(0,sets.length - 1)]
currentMap = Game.mapName
newMap = i+'.brk'
if (consoleOutput) console.log("Rolled "+newMap+" as our new map.")
if (consoleOutput) console.log(currentMap+" is the current map.")
}
while (newMap == currentMap); // keep rolling until we get a different map than what we had previously
world.bricks.forEach(async(brick) => {
await sleep(2000)
brick.destroy()
})
await sleep(2000)
if (consoleOutput) console.log("autoloading "+i)
Game.messageAll(`\\c6Autoloading ${i}.brk`)
let data = await Game.loadBrk(`./maps/${i}.brk`)
Game.setEnvironment(data.environment)
Game.players.forEach((player) => {
player.respawn()
})
world.bricks.forEach(async(brick) => {
if (brick.name == "sb1") { //Gives 10 points
spawnscorebubble(brick.position,1)
await sleep (4000)
brick.destroy()
} else if (brick.name == "sb2") { //Gives 50 points
spawnscorebubble(brick.position,2)
await sleep (4000)
brick.destroy()
} else if (brick.name == "sb3") { //Gives 100 points
spawnscorebubble(brick.position,3)
await sleep (4000)
brick.destroy()
}
})
if (consoleOutput) console.log("autoloaded "+i)
}
function randynumber(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
function spawnscorebubble(pos,type){
if (type == 1) { // Normal bubble gives 10
var brick = new Brick(pos, new Vector3(1, 1, 1), "#00ff00")
Game.newBrick(brick)
} else if (type == 2) { // Medium bubble gives 50
var brick = new Brick(pos, new Vector3(1, 1, 1), "#ffff00")
Game.newBrick(brick)
} else if (type == 3) { // Huge bubble gives 100
var brick = new Brick(pos, new Vector3(1, 1, 1), "#ff0000")
Game.newBrick(brick)
}
brick.touching(debounce(p => {
if (type == 1) {
p.bubblescore += 10
p.bubblemut++
p.bubblecooldown = 3
//brick-streamstuuf line
p.centerPrint(`${p.bubblescore}`,3)
bubbleexplode(brick.position.x,brick.position.y,brick.position.z,"#00ff00",)
brick.destroy()
} else if (type == 2) {
p.bubblescore += 50
p.bubblemut++
p.bubblecooldown = 3
//brick-streamstuuf line
p.centerPrint(`${p.bubblescore}`,3)
bubbleexplode(brick.position.x,brick.position.y,brick.position.z,"#ffff00",)
brick.destroy()
} else if (type == 3) {
p.bubblescore += 100
p.bubblemut++
p.bubblecooldown = 3
//brick-streamstuuf line
p.centerPrint(`${p.bubblescore}`,3)
bubbleexplode(brick.position.x,brick.position.y,brick.position.z,"#ff0000",)
brick.destroy()
}
}, 800)) // this probably didn't have to be 2000 so i'm changing it back to 800
}
Game.on('playerJoin', (p) => {
p.bubblescore = 0
p.newbubblescore
p.bubblemut = 0
p.bubblecooldown = 0
p.mut = 0
p.setInterval(() => {
p.bubblecooldown--
if (p.bubblecooldown == 0) {
if (p.bubblemut > 4) {
p.mut = 1
p.mut += Math.floor(p.bubblemut / 5)
p.newbubblescore = Math.floor(p.bubblescore * p.mut)
p.centerPrint(`\\c5X${p.mut}! ${p.newbubblescore}+ (${p.bubblescore})`,2)
p.setScore(p.score += p.newbubblescore)
p.bubblescore = 0
p.bubblemut = 0
} else {
p.centerPrint(`\\c5${p.bubblescore}+`,2)
p.setScore(p.score += p.bubblescore)
p.bubblescore = 0
p.bubblemut = 0
}
}
},1000)
})
function bubbleexplode(px,py,pz,color) {
let brick = new Brick(new Vector3(px,py,pz+3),new Vector3(0.35,0.35,0.35),color)
Game.newBrick(brick)
var grav = 1
var time = 0
var sped = 1
var prot = randynumber(0,9999)
brick.setInterval(() => {
var rotx = brick.position.x += 1 * Math.sin(prot)
var roty = brick.position.y -+ 1 * Math.cos(prot)
var rotz = brick.position.z += grav
brick.setPosition(new Vector3(rotx,roty,rotz))
time++
if (time > 1) {
grav -= 0.1
sped -= 0.05
time++
var rotx = brick.position.x += sped * Math.sin(prot)
var roty = brick.position.y -+ sped * Math.cos(prot)
var rotz = brick.position.z += grav
if (time > 80 && !brick.destroyed)
brick.destroy()
}
}, 35)
}
setInterval(async() => {
countdown--
//if (consoleOutput) console.log("countdown: "+countdown)
if (guiEnable) {
Game.topPrintAll("[#FFDE0A]Current map: [#FFFFFF]"+Game.mapName,1000)
Game.bottomPrintAll("[#FFDE0A]Time until next map: [#FFFFFF]"+countdown+" seconds.",1000)
}
if (countdown < 1) {
countdown = countdownDefault
autoload()
}
},1000)