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) { ygopro.ctos_follow_before(
var room = ROOM_all[client.rid]; "CHAT",
if (room.rolls == undefined) false,
{ async function (buffer, info, client, server, datas) {
room.rolls = new Object(); var room = ROOM_all[client.rid];
} if (room.rolls == undefined) {
room.rolls = new Object();
}
var msg = _.trim(info.msg); var msg = _.trim(info.msg);
if (msg.substring(0, 5) == "/dice") if (msg.substring(0, 5) == "/dice") {
{ var diceresult = Math.floor(Math.random() * 6) + 1;
var diceresult = Math.floor(Math.random()*6) + 1; var dicemessage = client.name + "投掷1d6并掷出了" + diceresult + "";
var dicemessage = client.name + "投掷1d6并掷出了" + diceresult + ""; ygopro.stoc_send_chat_to_room(
ygopro.stoc_send_chat_to_room(room, dicemessage, ygopro.constants.COLORS.PINK); room,
return; dicemessage,
ygopro.constants.COLORS.PINK
);
return;
} }
if (msg.substring(0, 5) == "/coin") if (msg.substring(0, 5) == "/coin") {
{ var coinresult = Math.floor(Math.random() * 2) == 1 ? "正面" : "反面";
var coinresult = Math.floor(Math.random()*2) == 1 ? "正面" : "反面"; var coinmessage = client.name + "投掷硬币并掷出了" + coinresult;
var coinmessage = client.name + "投掷硬币并掷出了" + coinresult; ygopro.stoc_send_chat_to_room(
ygopro.stoc_send_chat_to_room(room, coinmessage, ygopro.constants.COLORS.BLUE); room,
return; coinmessage,
ygopro.constants.COLORS.BLUE
);
return;
} }
if (msg.substring(0, 5) != "/roll") { if (msg.substring(0, 5) != "/roll") {
return; return;
} }
var regex = /[0-9]*d[0-9]+/; var regex = /[0-9]*d[0-9]+/;
var found = regex.exec(msg); var regex2 = /[0-9]*d[0-9]+[\+][0-9]+/;
var dicenum = 1; var regex2m = /[0-9]*d[0-9]+[\-][0-9]+/;
var dicemax = 100; var found2 = regex2.exec(msg);
if (found) var found2m = regex2m.exec(msg);
{ var dicenum = 1;
found = found.toString(); var dicemax = 100;
var split = found.split('d'); var diceadd = 0;
dicenum = split[0]; if (found2) {
dicemax = split[1]; found2 = found2.toString();
} var split = found2.split("+");
if (dicenum > 100) diceadd = split[1];
dicenum = 100; msg = split[0];
if (dicenum < 1) }
dicenum = 1; if (found2m) {
if (dicemax > 60000) found2m = found2m.toString();
dicemax = 60000; var split = found2.split("-");
if (dicemax < 1) diceadd = -split[1];
dicemax = 1; msg = split[0];
var result = 0; }
for (var i=0;i<dicenum;i++) var found = regex.exec(msg);
{ if (found) {
result += Math.floor(Math.random()*dicemax) + 1; found = found.toString();
} var split = found.split("d");
var name = client.name; dicenum = split[0];
var message = name + "投掷" + dicenum + "d" + dicemax + "并掷出了" + result + ""; dicemax = split[1];
log.warn(message); }
if (room.rolls[name] == undefined) if (dicenum > 100) dicenum = 100;
{ if (dicenum < 1) dicenum = 1;
if (dicenum == 1 || dicemax == 100) if (dicemax > 60000) dicemax = 60000;
{ if (dicemax < 1) dicemax = 1;
room.rolls[name] = result; if (diceadd > 1000000) diceadd = 1000000;
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.YELLOW); if (diceadd < -1000000) diceadd = -1000000;
} var result = 0;
else for (var i = 0; i < dicenum; i++) {
{ result += Math.floor(Math.random() * dicemax) + 1;
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.BABYBLUE); }
} result += diceadd;
} var name = client.name;
else var message =
{ name + "投掷" + dicenum + "d" + dicemax + "并掷出了" + result + "";
message = message + ";首次1d100投掷为" + room.rolls[name] + ""; log.warn(message);
ygopro.stoc_send_chat_to_room(room, message, ygopro.constants.COLORS.BABYBLUE); 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; 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