Commit 57d97b02 authored by JoyJ's avatar JoyJ

update diceroll & dc-random

parent d13087a5
ygopro.ctos_follow_before('CHAT', false, async function (buffer, info, client, server, datas) {
var room = ROOM_all[client.rid];
if (room.rolls == undefined)
{
room.rolls = new Object();
}
ygopro.ctos_follow_before(
"CHAT",
false,
async function (buffer, info, client, server, datas) {
var room = ROOM_all[client.rid];
if (room.rolls == undefined) {
room.rolls = new Object();
}
var msg = _.trim(info.msg);
if (msg.substring(0, 5) == "/dice")
{
var diceresult = Math.floor(Math.random()*6) + 1;
var dicemessage = client.name + "投掷1d6并掷出了" + diceresult + "";
ygopro.stoc_send_chat_to_room(room, dicemessage, ygopro.constants.COLORS.PINK);
return;
if (msg.substring(0, 5) == "/dice") {
var diceresult = Math.floor(Math.random() * 6) + 1;
var dicemessage = client.name + "投掷1d6并掷出了" + diceresult + "";
ygopro.stoc_send_chat_to_room(
room,
dicemessage,
ygopro.constants.COLORS.PINK
);
return;
}
if (msg.substring(0, 5) == "/coin")
{
var coinresult = Math.floor(Math.random()*2) == 1 ? "正面" : "反面";
var coinmessage = client.name + "投掷硬币并掷出了" + coinresult;
ygopro.stoc_send_chat_to_room(room, coinmessage, ygopro.constants.COLORS.BLUE);
return;
if (msg.substring(0, 5) == "/coin") {
var coinresult = Math.floor(Math.random() * 2) == 1 ? "正面" : "反面";
var coinmessage = client.name + "投掷硬币并掷出了" + coinresult;
ygopro.stoc_send_chat_to_room(
room,
coinmessage,
ygopro.constants.COLORS.BLUE
);
return;
}
if (msg.substring(0, 5) != "/roll") {
return;
return;
}
var regex = /[0-9]*d[0-9]+/;
var found = regex.exec(msg);
var dicenum = 1;
var dicemax = 100;
if (found)
{
found = found.toString();
var split = found.split('d');
dicenum = split[0];
dicemax = split[1];
}
if (dicenum > 100)
dicenum = 100;
if (dicenum < 1)
dicenum = 1;
if (dicemax > 60000)
dicemax = 60000;
if (dicemax < 1)
dicemax = 1;
var result = 0;
for (var i=0;i<dicenum;i++)
{
result += Math.floor(Math.random()*dicemax) + 1;
}
var name = client.name;
var message = name + "投掷" + dicenum + "d" + dicemax + "并掷出了" + result + "";
log.warn(message);
if (room.rolls[name] == undefined)
{
if (dicenum == 1 || dicemax == 100)
{
room.rolls[name] = result;
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.YELLOW);
}
else
{
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.BABYBLUE);
}
}
else
{
message = message + ";首次1d100投掷为" + room.rolls[name] + "";
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.BABYBLUE);
}
var regex2 = /[0-9]*d[0-9]+[\+][0-9]+/;
var regex2m = /[0-9]*d[0-9]+[\-][0-9]+/;
var found2 = regex2.exec(msg);
var found2m = regex2m.exec(msg);
var dicenum = 1;
var dicemax = 100;
var diceadd = 0;
if (found2) {
found2 = found2.toString();
var split = found2.split("+");
diceadd = split[1];
msg = split[0];
}
if (found2m) {
found2m = found2m.toString();
var split = found2.split("-");
diceadd = -split[1];
msg = split[0];
}
var found = regex.exec(msg);
if (found) {
found = found.toString();
var split = found.split("d");
dicenum = split[0];
dicemax = split[1];
}
if (dicenum > 100) dicenum = 100;
if (dicenum < 1) dicenum = 1;
if (dicemax > 60000) dicemax = 60000;
if (dicemax < 1) dicemax = 1;
if (diceadd > 1000000) diceadd = 1000000;
if (diceadd < -1000000) diceadd = -1000000;
var result = 0;
for (var i = 0; i < dicenum; i++) {
result += Math.floor(Math.random() * dicemax) + 1;
}
result += diceadd;
var name = client.name;
var message =
name + "投掷" + dicenum + "d" + dicemax + "并掷出了" + result + "";
log.warn(message);
if (room.rolls[client.ip] == undefined) {
if (dicenum == 1 && dicemax == 100 && diceadd == 0) {
room.rolls[client.ip] = result;
ygopro.stoc_send_chat_to_room(
room,
message,
ygopro.constants.COLORS.YELLOW
);
} else {
ygopro.stoc_send_chat_to_room(
room,
message,
ygopro.constants.COLORS.BABYBLUE
);
}
} else {
message = message + ";首次1d100投掷为" + room.rolls[client.ip] + "";
ygopro.stoc_send_chat_to_room(
room,
message,
ygopro.constants.COLORS.BABYBLUE
);
}
return true;
});
\ No newline at end of file
}
);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment