<script type="text/javascript" src="scripts/sprintf.js"></script>\r
<script type="text/javascript" src="scripts/dateformat.js"></script>\r
<script type="text/javascript" src="scripts/commandparser.js"></script>\r
+<script type="text/javascript" src="scripts/dicecommand.js"></script>\r
<script type="text/javascript" src="scripts/chatclient.js"></script>\r
<!-- ここまでを必ず組み込むこと -->\r
<link rel="stylesheet" href="stylesheets/enter.css" type="text/css" />\r
word[1] = msg.name;\r
return word.join(" ");\r
}\r
- this.CommandList["/dice"] = function(msg,word)\r
- {\r
- if(word.length == 1)\r
- text = CastDice("6d1");\r
- else\r
- text = CastDice(word[1]);\r
- return text;\r
- }\r
this.CommandList["/send"] = function(msg,word)\r
{\r
if(word.length != 3)\r
\r
$PostCommandParser = new CommandParserWhenPost();\r
$GetCommandParser = new CommandParserWhenGet();\r
-\r
-function ParseDiceParam(number,option)\r
-{\r
- if(typeof(number) != "undefined")\r
- {\r
- var result = new Object();\r
- result.option = typeof(option) == "undefined" ? null : option;\r
- result.number = parseInt(number);\r
- return result;\r
- }\r
- return null;\r
-}\r
-\r
-function CastDice(text){\r
- var p = text.match(/(\d+)D(\d+)C*(\d+)?(\-|\+)?F*(\d+)?(\-|\+)?/i);\r
- var max = parseInt(p[1]);\r
- var dice_num = parseInt(p[2]);\r
- var critical = ParseDiceParam(p[3],p[4]);\r
- var fanble = ParseDiceParam(p[5],p[6]);\r
- var total = 0;\r
- var hasCritical = true;\r
- var hasFanble = true;\r
- var util = new Util();\r
-\r
- text = "[" + text + "] -> ";\r
- for(var i = 0; i < dice_num; i++)\r
- {\r
- var t = util.get_random_number(1,max);\r
- total += t;\r
- text += t + " + ";\r
-\r
- if(hasCritical && critical != null)\r
- {\r
- if(critical.option == "-" && t <= critical.number)\r
- hasCritical = true;\r
- else if(critical.option == "+" && t >= critical.number)\r
- hasCritical = true;\r
- else if(critical.option == null && t == critical.number)\r
- hasCritical = true;\r
- else\r
- hasCritical = false;\r
- }\r
-\r
- if(hasFanble && fanble != null)\r
- {\r
- if(fanble.option == "-" && t <= fanble.number)\r
- hasFanble = true;\r
- else if(fanble.option == "+" && t >= fanble.number)\r
- hasFanble = true;\r
- else if(fanble.option == null && t == fanble.number)\r
- hasFanble = true;\r
- else\r
- hasFanble = false;\r
- }\r
- }\r
-\r
- text = text.slice(0,text.length - 3); //\8dÅ\8cã\82É\95t\82" + "\82ð\8eæ\82è\8f\9c\82\r
- text += " = " + total;\r
-\r
- if(critical == null)\r
- hasCritical = false;\r
- if(fanble == null)\r
- hasFanble = false;\r
-\r
- if(hasCritical)\r
- text = sprintf($critical_message,text);\r
- else if(hasFanble)\r
- text = sprintf($fanble_message,text);\r
-\r
- return text;\r
-}\r
--- /dev/null
+$GetCommandParser.CommandList["/dice"] = function(msg,word)
+{
+ if(word.length == 1)
+ text = CastDice("6d1");
+ else
+ text = CastDice(word[1]);
+ return text;
+}
+
+function ParseDiceParam(number,option)
+{
+ if(typeof(number) != "undefined")
+ {
+ var result = new Object();
+ result.option = typeof(option) == "undefined" ? null : option;
+ result.number = parseInt(number);
+ return result;
+ }
+ return null;
+}
+
+function CastDice(text){
+ var p = text.match(/(\d+)D(\d+)C*(\d+)?(\-|\+)?F*(\d+)?(\-|\+)?/i);
+ var max = parseInt(p[1]);
+ var dice_num = parseInt(p[2]);
+ var critical = ParseDiceParam(p[3],p[4]);
+ var fanble = ParseDiceParam(p[5],p[6]);
+ var total = 0;
+ var hasCritical = true;
+ var hasFanble = true;
+ var util = new Util();
+
+ text = "[" + text + "] -> ";
+ for(var i = 0; i < dice_num; i++)
+ {
+ var t = util.get_random_number(1,max);
+ total += t;
+ text += t + " + ";
+
+ if(hasCritical && critical != null)
+ {
+ if(critical.option == "-" && t <= critical.number)
+ hasCritical = true;
+ else if(critical.option == "+" && t >= critical.number)
+ hasCritical = true;
+ else if(critical.option == null && t == critical.number)
+ hasCritical = true;
+ else
+ hasCritical = false;
+ }
+
+ if(hasFanble && fanble != null)
+ {
+ if(fanble.option == "-" && t <= fanble.number)
+ hasFanble = true;
+ else if(fanble.option == "+" && t >= fanble.number)
+ hasFanble = true;
+ else if(fanble.option == null && t == fanble.number)
+ hasFanble = true;
+ else
+ hasFanble = false;
+ }
+ }
+
+ text = text.slice(0,text.length - 3); //\8dÅ\8cã\82É\95t\82" + "\82ð\8eæ\82è\8f\9c\82
+ text += " = " + total;
+
+ if(critical == null)
+ hasCritical = false;
+ if(fanble == null)
+ hasFanble = false;
+
+ if(hasCritical)
+ text = sprintf($critical_message,text);
+ else if(hasFanble)
+ text = sprintf($fanble_message,text);
+
+ return text;
+}