OSDN Git Service

ダイス関連を別ファイルにした
authorkonekoneko <jbh03215@gmail.com>
Tue, 16 Oct 2012 09:13:12 +0000 (18:13 +0900)
committerkonekoneko <jbh03215@gmail.com>
Tue, 16 Oct 2012 09:13:12 +0000 (18:13 +0900)
public/chat.ejs
public/scripts/commandparser.js
public/scripts/dicecommand.js [new file with mode: 0644]

index a7e3ead..8797920 100644 (file)
@@ -10,6 +10,7 @@
 <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
index 024e49b..6faa8e2 100644 (file)
@@ -98,14 +98,6 @@ function CommandParserWhenPost()
                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
@@ -138,74 +130,3 @@ CommandParserWhenPost.prototype = new CommandParser;
 \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
diff --git a/public/scripts/dicecommand.js b/public/scripts/dicecommand.js
new file mode 100644 (file)
index 0000000..9aaa5a0
--- /dev/null
@@ -0,0 +1,79 @@
+$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;
+}