Guest User

Untitled

a guest
Mar 22nd, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. import java.lang.Math;
  2.  
  3. SCRIPT_NAME = "travel";
  4. SCRIPT_DESC = "alloweds to travel on mud path";
  5. PATH_TO_MAP = "/path/to/map/files/"; // Edit this path so it points to the folder with your map files
  6. // The map files can be downloaded from http://www.bat.org/maps/raw/laenor.txt rothikgen.txt furnachia.txt lucentium.txt desolathya.txt
  7. CMD_BEFOR = "set look_on_move off"; // This command is send to the server befor traveling
  8. CMD_AFTER = "set look_on_move on"; // and this one at the end of the traveling
  9. STOP = 40; // if you don't append a max distance to the travel cmd it will use this one
  10. // note that the travel command for mud paths doesn't cares how much ep you have
  11.  
  12. String cont;
  13. int pos_x;
  14. int pos_y;
  15. boolean next = false;
  16. String travel_cmd = "";
  17. char [][] contm;
  18. char [][] deso;
  19. char [][] furn;
  20. char [][] luc;
  21. char [][] roth;
  22. char [][] laenor;
  23. void bootup(){
  24. deso = new char [530][];
  25. load("desolathya.txt",deso);
  26. furn = new char [480][];
  27. load("furnachia.txt",furn);
  28. luc = new char [500][];
  29. load("lucentium.txt",luc);
  30. roth = new char [480][];
  31. load("rothikgen.txt",roth);
  32. laenor = new char [781][];
  33. load("laenor.txt",laenor);
  34. triggerManager.newTrigger("whereami_travel","^You are in.* on the continent of ([A-Za-z]+)[.] [(]Coordinates: ([0-9]+)x, ([0-9]+)y;","$" + SCRIPT_NAME + ".update",false,false,false,null,Font.PLAIN);
  35. }
  36. public void update()
  37. {
  38. cont = vars.get(1);
  39. if(cont.equals("Laenor"))
  40. contm = laenor;
  41. else if(cont.equals("Lucentium"))
  42. contm = luc;
  43. else if(cont.equals("Desolathya"))
  44. contm = deso;
  45. else if(cont.equals("Rothikgen"))
  46. contm = roth;
  47. else if(cont.equals("Furnachia"))
  48. contm = furn;
  49. pos_x = Integer.parseInt(vars.get(2)) -1;
  50. pos_y = Integer.parseInt(vars.get(3)) -1;
  51. if(next)
  52. {
  53. next = false;
  54. travel();
  55. }
  56. }
  57. public String processCommand(){
  58. if (command.startsWith("travel ")){
  59. travel_cmd = command;
  60. next = true;
  61. return "whereami";
  62. }
  63. return command;
  64. }
  65. private void travel()
  66. {
  67. char p = contm[pos_y][pos_x];
  68. if(p != ',')
  69. {
  70. clientGUI.doCommand("@" + travel_cmd);
  71. return;
  72. }
  73. String [] d = travel_cmd.split(" ");
  74. if(d.length < 2) return;
  75. old_dir = d[1];
  76. int stop = STOP;
  77. if(d.length == 3)
  78. stop = Integer.parseInt(d[2]);
  79.  
  80. if(contm[pos_y + adjustY(old_dir)][pos_x + adjustX(old_dir)] == ',')
  81. {
  82. clientGUI.doCommand(CMD_BEFOR);
  83. clientGUI.doCommand(old_dir);
  84. pos_y += adjustY(old_dir);
  85. pos_x += adjustX(old_dir);
  86. old_dir = reverse(old_dir);
  87. for(int w = 0; w < (stop-1);++w)
  88. {
  89. System.out.println("pos_y:" + pos_y + "pos_x:" + pos_x);
  90.  
  91. int c = 0;
  92. String new_dir = "";
  93. String [] dirs = { "nw","n","ne","w","e","sw","s","se" };
  94. for ( String di : dirs)
  95. {
  96. if(test(di,old_dir) && contm[pos_y + adjustY(di)][pos_x + adjustX(di)] == ',')
  97. {
  98. c++;
  99. new_dir = di;
  100. }
  101. }
  102. if(c != 1)
  103. {
  104. clientGUI.doCommand(CMD_AFTER);
  105. return; // reached end of the path or a fork
  106. }
  107. clientGUI.doCommand(new_dir);
  108. pos_y += adjustY(new_dir);
  109. pos_x += adjustX(new_dir);
  110. old_dir = reverse(new_dir);
  111. }
  112. clientGUI.doCommand(CMD_AFTER);
  113. }
  114. }
  115. private boolean test(String dir, String old_dir)
  116. {
  117. return (Math.abs(adjustX(dir) - adjustX(old_dir)) + Math.abs(adjustY(dir) -adjustY(old_dir)) >1);
  118. }
  119. private int adjustX(String a)
  120. {
  121. if(a.equals("w") || a.equals("nw") || a.equals("sw"))
  122. return -1;
  123. if(a.equals("e") || a.equals("ne") || a.equals("se"))
  124. return 1;
  125. return 0;
  126. }
  127. private int adjustY(String a)
  128. {
  129. if(a.equals("n") || a.equals("nw") || a.equals("ne"))
  130. return -1;
  131. if(a.equals("s") || a.equals("sw") || a.equals("se"))
  132. return 1;
  133. return 0;
  134. }
  135. private String reverse(String a)
  136. {
  137. if(a.equals("nw"))
  138. return "se";
  139. if(a.equals("n"))
  140. return "s";
  141. if(a.equals("ne"))
  142. return "sw";
  143. if(a.equals("w"))
  144. return "e";
  145. if(a.equals("e"))
  146. return "w";
  147. if(a.equals("sw"))
  148. return "ne";
  149. if(a.equals("se"))
  150. return "nw";
  151. if(a.equals("s"))
  152. return "n";
  153. return "";
  154. }
  155. //y x
  156. private void load(String name,char [][] a)
  157. {
  158. File f = new File(PATH_TO_MAP + name);
  159. BufferedReader br = new BufferedReader(new FileReader(f));
  160. String l;
  161. for(int y = 0; y < a.length; ++y)
  162. {
  163. l = br.readLine();
  164. a[y] = l.toCharArray();
  165. }
  166. br.close();
  167. }
Advertisement
Add Comment
Please, Sign In to add comment