北大侠客行MUD论坛

 找回密码
 注册
搜索
热搜: 新手 wiki 升级
查看: 8858|回复: 4

帖个js转换zmud格式alias的东东,方便mushclient初学者

[复制链接]
发表于 2009-1-7 11:31:16 | 显示全部楼层 |阅读模式
帖个js转换zmud格式alias的东东,方便mushclient初学者

  1. var pathArray = {"e" : "w", "east" : "west", "eu" : "wd", "eastup" : "westdown",
  2. "ed" : "wu", "eastdown" : "westup", "w" : "e", "west" : "east",
  3. "wu" : "ed", "westup" : "eastdown", "wd" : "eu", "westdown" : "eastup",
  4. "s" : "n", "south" : "north", "su" : "nd", "southup" : "northdown",
  5. "sd" : "nu", "southdown" : "northup", "n" : "s", "north" : "south",
  6. "nu" : "sd", "northup" : "southdown", "nd" : "su", "northdown" : "southup",
  7. "u" : "d", "up" : "down", "d" : "u", "down" : "up", "se" : "nw",
  8. "southeast" : "northwest", "sw" : "ne", "southwest" : "northeast",
  9. "ne" : "sw", "northeast" : "southwest", "nw" : "se", "northwest" : "southeast",
  10. "enter" : "out", "out" : "enter"};
  11. /**路径中默认可以识别的方向和行为**/
  12. var pa = {"n":"north","s":"south","e":"east","w":"west","u":"up","d":"down",
  13. "c":"close","o":"open","l":"look","k":"unlock"};
  14. /**显示消息**/
  15. function show(obj) {
  16. var shell = new ActiveXObject("WScript.Shell");
  17. shell.Popup(obj);
  18. }
  19. /**处理zMud格式的alias**/
  20. function alias(aliastr) {
  21. var a = aliastr.toLowerCase();
  22. var name = "", path = "";
  23. if (a.indexOf("#alias") != -1) {
  24.   name = a.substring(7,a.indexOf("{") - 1);
  25.   path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
  26. }
  27. var ary = path.split(";");
  28. var tp = "";
  29. for (i = 0; i < ary.length; i++) {
  30.   var regExp0 = /#(\d{1,})(\s*)(.*)/;
  31.   var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
  32.   var regExp1 = /#wa(\s*)(\d{1,})/;
  33.   if (regExp1.test(ary)) {
  34.   } else if (regExp0.test(ary)) {
  35.    var reg = regExp0.exec(ary);
  36.    var n = RegExp.$1;
  37.    var s = RegExp.$3;
  38.    tp += n + parseStr(s);
  39.   } else if (regExp2.test(ary)) {
  40.    var reg = regExp2.exec(ary);
  41.    var n = RegExp.$2;
  42.    var s = RegExp.$4;
  43.    tp += n + parseStr(s);
  44.   } else {
  45.    tp += parseStr(ary);
  46.   }
  47. }
  48. function parseStr(str) {
  49.   var tmp = "";
  50.   var t = pathArray[str];
  51.   if (t != undefined) {
  52.    if (pa[str] != undefined) {
  53.     tmp = str;
  54.    } else {
  55.     tmp = "(" + str + "/" + t + ")";
  56.    }
  57.   } else {
  58.    tmp = "(" + str + ")";
  59.   }
  60.   return tmp;
  61. }
  62. return tp;
  63. }
  64. eval(show(alias("#alias baituo {n;w;do 2 ask qian about 白驼山;give qian 1 gold;#2 sw;#wa 1000;do 5 d}")));
复制代码
欢迎大家指正!

[ 本帖最后由 tianheng 于 2009-1-7 04:17 PM 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1精华 +30 收起 理由
icer + 30

查看全部评分

北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
 楼主| 发表于 2009-1-7 11:32:28 | 显示全部楼层
测试用的alias是为了测试乱写的
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
 楼主| 发表于 2009-1-7 11:34:01 | 显示全部楼层
var regExp0 = /#(\d{1,})(\s*)(.*)/;
var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
感觉这两个可以合并为一个,但不知道怎么弄。
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
 楼主| 发表于 2009-1-7 16:15:28 | 显示全部楼层
呵呵,精华了。修改了下,可以批量转换文件中的#alias。调用方法为:/myaddalias("x:/pkuxkx_path.txt");

  1. var pathArray = {"e" : "w", "east" : "west", "eu" : "wd", "eastup" : "westdown",
  2. "ed" : "wu", "eastdown" : "westup", "w" : "e", "west" : "east",
  3. "wu" : "ed", "westup" : "eastdown", "wd" : "eu", "westdown" : "eastup",
  4. "s" : "n", "south" : "north", "su" : "nd", "southup" : "northdown",
  5. "sd" : "nu", "southdown" : "northup", "n" : "s", "north" : "south",
  6. "nu" : "sd", "northup" : "southdown", "nd" : "su", "northdown" : "southup",
  7. "u" : "d", "up" : "down", "d" : "u", "down" : "up", "se" : "nw",
  8. "southeast" : "northwest", "sw" : "ne", "southwest" : "northeast",
  9. "ne" : "sw", "northeast" : "southwest", "nw" : "se", "northwest" : "southeast",
  10. "enter" : "out", "out" : "enter"};
  11. /**路径中默认可以识别的方向和行为**/
  12. var pa = {"n":"north","s":"south","e":"east","w":"west","u":"up","d":"down",
  13. "c":"close","o":"open","l":"look","k":"unlock"};
  14. /**显示消息**/
  15. function show(obj) {
  16. var shell = new ActiveXObject("WScript.Shell");
  17. shell.Popup(obj);
  18. }
  19. /**处理zMud格式的alias**/
  20. function alias(aliastr) {
  21. var a = aliastr.toLowerCase();
  22. var name = "", path = "";
  23. if (a.indexOf("#alias") != -1) {
  24.   name = a.substring(7,a.indexOf("{") - 1);
  25.   path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
  26. }
  27. var ary = path.split(";");
  28. var tp = "";
  29. for (i = 0; i < ary.length; i++) {
  30.   var regExp0 = /#(\d{1,})(\s*)(.*)/;
  31.   var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
  32.   var regExp1 = /#wa(\s*)(\d{1,})/;
  33.   if (regExp1.test(ary)) {
  34.   } else if (regExp0.test(ary)) {
  35.    var reg = regExp0.exec(ary);
  36.    var n = RegExp.$1;
  37.    var s = RegExp.$3;
  38.    tp += n + parseStr(s);
  39.   } else if (regExp2.test(ary)) {
  40.    var reg = regExp2.exec(ary);
  41.    var n = RegExp.$2;
  42.    var s = RegExp.$4;
  43.    tp += n + parseStr(s);
  44.   } else {
  45.    tp += parseStr(ary);
  46.   }
  47. }
  48. function parseStr(str) {
  49.   var tmp = "";
  50.   var t = pathArray[str];
  51.   if (t != undefined) {
  52.    if (pa[str] != undefined) {
  53.     tmp = str;
  54.    } else {
  55.     tmp = "(" + str + "/" + t + ")";
  56.    }
  57.   } else {
  58.    tmp = "(" + str + ")";
  59.   }
  60.   return tmp;
  61. }
  62. return tp;
  63. }
  64. //eval(show(alias("#alias baituo {n;w;do 2 ask qian about 白驼山;give qian 1 gold;#2 sw;#wa 1000;do 5 d}")));
  65. /**处理zMud格式的alias**/
  66. function alias(aliastr) {
  67. var a = aliastr.toLowerCase();
  68. var name = "", path = "";
  69. if (a.indexOf("#alias") != -1) {
  70.   name = a.substring(7,a.indexOf("{") - 1);
  71.   path = a.substring(a.indexOf("{") + 1,a.indexOf("}"));
  72. }
  73. var ary = path.split(";");
  74. var tp = "";
  75. for (i = 0; i < ary.length; i++) {
  76.   var regExp0 = /#(\d{1,})(\s*)(.*)/;
  77.   var regExp2 = /do(\s*)(\d{1,})(\s*)(.*)/;
  78.   var regExp1 = /#wa(\s*)(\d{1,})/;
  79.   if (regExp1.test(ary)) {
  80.   } else if (regExp0.test(ary)) {
  81.    var reg = regExp0.exec(ary);
  82.    var n = RegExp.$1;
  83.    var s = RegExp.$3;
  84.    tp += n + parseStr(s);
  85.   } else if (regExp2.test(ary)) {
  86.    var reg = regExp2.exec(ary);
  87.    var n = RegExp.$2;
  88.    var s = RegExp.$4;
  89.    tp += n + parseStr(s);
  90.   } else {
  91.    tp += parseStr(ary);
  92.   }
  93. }
  94. function parseStr(str) {
  95.   var tmp = "";
  96.   var t = pathArray[str];
  97.   if (t != undefined) {
  98.    if (pa[str] != undefined) {
  99.     tmp = str;
  100.    } else {
  101.     tmp = "(" + str + "/" + t + ")";
  102.    }
  103.   } else {
  104.    tmp = "(" + str + ")";
  105.   }
  106.   return tmp;
  107. }
  108. note(name + " = " + tp);
  109. addalias(name, name, tp, 1|32|1024|2048, "");
  110. //return tp;
  111. }
  112. function myaddalias(file) {
  113. try {
  114.   var fso, rf, r;
  115.   var ForReading = 1, ForWriting = 2, ForAppending = 8;
  116.   fso = new ActiveXObject("Scripting.FileSystemObject");
  117.   rf = fso.OpenTextFile(file, ForReading);
  118.   while (!rf.AtEndOfStream) {
  119.    r = rf.ReadLine();
  120.    if (trim(r) != "") {
  121.     alias(r);
  122.    }
  123.   }
  124.   rf.close();
  125.   note("ok!");
  126. }
  127. catch (e) {
  128. }
  129. }
复制代码


附件更新过了!

[ 本帖最后由 tianheng 于 2009-1-7 04:18 PM 编辑 ]
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
发表于 2009-1-8 12:57:45 | 显示全部楼层
发一个mush版的插件,北侠常用路径的插件,和zmud的差不多,很像

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
北大侠客行Mud(pkuxkx.com),最好的中文Mud游戏!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|北大侠客行MUD ( 京ICP备16065414号-1 )

GMT+8, 2024-11-28 01:43 AM , Processed in 0.010120 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表