2020-03-11 20:42:36 +01:00
|
|
|
const MPPClient = require('mpp-client-xt');
|
2020-05-28 18:06:44 +02:00
|
|
|
const client = new MPPClient("wss://ts.terrium.net:8443", undefined);
|
2020-03-17 15:39:38 +01:00
|
|
|
const fs = require('fs');
|
2020-03-11 20:42:36 +01:00
|
|
|
|
|
|
|
client.start();
|
|
|
|
|
|
|
|
client.on("hi", () => {
|
2020-03-11 21:18:17 +01:00
|
|
|
setTimeout(function() {
|
2020-03-25 01:40:01 +01:00
|
|
|
client.sendArray([{m:'userset', set:{name:"hri's dvdbot [dvd!help]"}}]);
|
2020-03-11 21:18:17 +01:00
|
|
|
})
|
|
|
|
|
2020-05-28 18:06:44 +02:00
|
|
|
client.setChannel("lobby");
|
2018-03-13 21:25:39 +01:00
|
|
|
});
|
|
|
|
|
2020-03-11 20:42:36 +01:00
|
|
|
function chat(string) {
|
|
|
|
client.sendArray([{m:'a', message:string}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var ctoggle = true;
|
|
|
|
|
2020-03-11 20:54:22 +01:00
|
|
|
var cursormode = "dvd";
|
|
|
|
|
2020-03-11 21:18:17 +01:00
|
|
|
|
2020-03-11 20:42:36 +01:00
|
|
|
client.on("a", (msg) => {
|
|
|
|
let args = msg.a.split(' ');
|
|
|
|
let cmd = args[0].toLowerCase();
|
|
|
|
let argcat = msg.a.substring(cmd.length).trim();
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case "dvd!help":
|
2020-03-21 22:00:52 +01:00
|
|
|
chat("cmds: dvd!help // dvd!cursor // dvd!stats // dvd!about");
|
2020-03-11 20:54:22 +01:00
|
|
|
break;
|
|
|
|
case "dvd!cursor":
|
|
|
|
if (!argcat || argcat == "") {
|
2020-03-16 03:06:24 +01:00
|
|
|
chat("Modes: on // off");
|
2020-03-11 20:54:22 +01:00
|
|
|
} else {
|
|
|
|
switch (argcat) {
|
|
|
|
case "on":
|
|
|
|
ctoggle = true;
|
2020-03-16 03:18:22 +01:00
|
|
|
pos = {x: (Math.random() * 100) - 50, y: (Math.random() * 100) - 50};
|
2020-03-11 21:06:20 +01:00
|
|
|
vel = {x: 2/5, y: 2/7};
|
2020-03-11 20:54:22 +01:00
|
|
|
cursormode = "dvd";
|
|
|
|
break;
|
|
|
|
case "off":
|
|
|
|
ctoggle = false;
|
|
|
|
cursormode = "none";
|
2020-03-11 21:06:20 +01:00
|
|
|
pos = {x: -500, y: -500};
|
|
|
|
break;
|
2020-03-16 03:30:19 +01:00
|
|
|
default:
|
|
|
|
chat("invalid :P");
|
|
|
|
break;
|
2020-03-11 20:54:22 +01:00
|
|
|
}
|
|
|
|
}
|
2020-03-11 20:42:36 +01:00
|
|
|
break;
|
2020-03-16 03:30:19 +01:00
|
|
|
case "dvd!stats":
|
2020-03-17 15:39:38 +01:00
|
|
|
chat("Edge hits: " + stats.edgehits + " | Corner hits: " + stats.cornerhits);
|
2020-03-16 03:30:19 +01:00
|
|
|
break;
|
2020-03-21 22:00:52 +01:00
|
|
|
case "dvd!about":
|
|
|
|
chat("Made by Hri7566 in his free time :)");
|
|
|
|
break;
|
2020-03-11 20:42:36 +01:00
|
|
|
}
|
2020-02-19 23:18:49 +01:00
|
|
|
});
|
|
|
|
|
2020-03-16 03:30:19 +01:00
|
|
|
var pos = {x: (Math.random() * 100) - 50, y: (Math.random() * 100) - 50};
|
2020-03-11 20:42:36 +01:00
|
|
|
var vel = {x: 2/5, y: 2/7};
|
2020-03-17 15:51:37 +01:00
|
|
|
var statsraw = fs.readFileSync('stats.json');
|
|
|
|
var stats = JSON.parse(statsraw);
|
|
|
|
console.log(stats);
|
2020-03-11 20:42:36 +01:00
|
|
|
|
|
|
|
var cursor = setInterval(function() {
|
2020-03-11 21:06:20 +01:00
|
|
|
client.sendArray([{m:'m', x: client.getOwnParticipant().x = pos.x + 50, y: client.getOwnParticipant().y = pos.y + 50}]);
|
2020-03-17 16:15:37 +01:00
|
|
|
}, 16);
|
2020-03-11 20:42:36 +01:00
|
|
|
|
|
|
|
var cursorupdate = setInterval(function() {
|
2020-03-11 20:54:22 +01:00
|
|
|
switch (cursormode) {
|
|
|
|
case "dvd":
|
|
|
|
pos.x += vel.x;
|
|
|
|
pos.y += vel.y;
|
|
|
|
if (pos.x >= 50) {
|
|
|
|
vel.x = -vel.x;
|
|
|
|
}
|
|
|
|
if (pos.y >= 50) {
|
|
|
|
vel.y = -vel.y;
|
|
|
|
}
|
|
|
|
if (pos.x <= -50) {
|
|
|
|
vel.x = -vel.x;
|
|
|
|
}
|
|
|
|
if (pos.y <= -50) {
|
|
|
|
vel.y = -vel.y;
|
|
|
|
}
|
2020-03-16 03:42:13 +01:00
|
|
|
if ((pos.x >= 50) && (pos.y >= 50)) {
|
2020-03-17 15:39:38 +01:00
|
|
|
stats.cornerhits += 1;
|
2020-03-16 03:42:13 +01:00
|
|
|
} else if ((pos.x >= 50) && (pos.y <= -50)) {
|
2020-03-17 15:39:38 +01:00
|
|
|
stats.cornerhits += 1;
|
2020-03-16 03:42:13 +01:00
|
|
|
} else if ((pos.x <= -50) && (pos.y <= -50)) {
|
2020-03-17 15:39:38 +01:00
|
|
|
stats.cornerhits += 1;
|
2020-03-16 03:42:13 +01:00
|
|
|
} else if ((pos.x <= -50) && (pos.y >= 50)) {
|
2020-03-17 15:39:38 +01:00
|
|
|
stats.cornerhits += 1;
|
2020-03-16 03:42:13 +01:00
|
|
|
} else if ((pos.x >= 50) || (pos.y >= 50) || (pos.y <= -50) || (pos.x <= -50)) {
|
2020-03-17 15:39:38 +01:00
|
|
|
stats.edgehits += 1;
|
2020-03-16 03:06:24 +01:00
|
|
|
}
|
2020-03-17 15:51:37 +01:00
|
|
|
let statsjson = JSON.stringify(stats);
|
|
|
|
fs.writeFile("stats.json", statsjson, 'utf8', function (err) {
|
2020-03-17 15:39:38 +01:00
|
|
|
if (err) {
|
|
|
|
console.log("stats.json couldn't be saved!");
|
|
|
|
return console.log(err);
|
|
|
|
}
|
|
|
|
});
|
2020-03-17 15:51:37 +01:00
|
|
|
break;
|
2020-03-11 20:54:22 +01:00
|
|
|
}
|
2020-03-11 21:18:17 +01:00
|
|
|
}, 25);
|