Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- SCRIPT_NAME = "travel";
- SCRIPT_DESC = "alloweds to travel on mud path";
- PATH_TO_MAP = "/path/to/map/files/"; // Edit this path so it points to the folder with your map files
- // The map files can be downloaded from http://www.bat.org/maps/raw/laenor.txt rothikgen.txt furnachia.txt lucentium.txt desolathya.txt
- CMD_BEFOR = "set look_on_move off"; // This command is send to the server befor traveling
- CMD_AFTER = "set look_on_move on"; // and this one at the end of the traveling
- STOP = 40; // if you don't append a max distance to the travel cmd it will use this one
- // note that the travel command for mud paths doesn't cares how much ep you have
- String cont;
- int pos_x;
- int pos_y;
- boolean next = false;
- String travel_cmd = "";
- char [][] contm;
- char [][] deso;
- char [][] furn;
- char [][] luc;
- char [][] roth;
- char [][] laenor;
- void bootup(){
- deso = new char [530][];
- load("desolathya.txt",deso);
- furn = new char [480][];
- load("furnachia.txt",furn);
- luc = new char [500][];
- load("lucentium.txt",luc);
- roth = new char [480][];
- load("rothikgen.txt",roth);
- laenor = new char [781][];
- load("laenor.txt",laenor);
- 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);
- }
- public void update()
- {
- cont = vars.get(1);
- if(cont.equals("Laenor"))
- contm = laenor;
- else if(cont.equals("Lucentium"))
- contm = luc;
- else if(cont.equals("Desolathya"))
- contm = deso;
- else if(cont.equals("Rothikgen"))
- contm = roth;
- else if(cont.equals("Furnachia"))
- contm = furn;
- pos_x = Integer.parseInt(vars.get(2)) -1;
- pos_y = Integer.parseInt(vars.get(3)) -1;
- if(next)
- {
- next = false;
- travel();
- }
- }
- public String processCommand(){
- if (command.startsWith("travel ")){
- travel_cmd = command;
- next = true;
- return "whereami";
- }
- return command;
- }
- private void travel()
- {
- char p = contm[pos_y][pos_x];
- if(p != ',')
- {
- clientGUI.doCommand("@" + travel_cmd);
- return;
- }
- String [] d = travel_cmd.split(" ");
- if(d.length < 2) return;
- old_dir = d[1];
- int stop = STOP;
- if(d.length == 3)
- stop = Integer.parseInt(d[2]);
- if(contm[pos_y + adjustY(old_dir)][pos_x + adjustX(old_dir)] == ',')
- {
- clientGUI.doCommand(CMD_BEFOR);
- clientGUI.doCommand(old_dir);
- pos_y += adjustY(old_dir);
- pos_x += adjustX(old_dir);
- old_dir = reverse(old_dir);
- for(int w = 0; w < (stop-1);++w)
- {
- System.out.println("pos_y:" + pos_y + "pos_x:" + pos_x);
- int c = 0;
- String new_dir = "";
- String [] dirs = { "nw","n","ne","w","e","sw","s","se" };
- for ( String di : dirs)
- {
- if(test(di,old_dir) && contm[pos_y + adjustY(di)][pos_x + adjustX(di)] == ',')
- {
- c++;
- new_dir = di;
- }
- }
- if(c != 1)
- {
- clientGUI.doCommand(CMD_AFTER);
- return; // reached end of the path or a fork
- }
- clientGUI.doCommand(new_dir);
- pos_y += adjustY(new_dir);
- pos_x += adjustX(new_dir);
- old_dir = reverse(new_dir);
- }
- clientGUI.doCommand(CMD_AFTER);
- }
- }
- private boolean test(String dir, String old_dir)
- {
- return (Math.abs(adjustX(dir) - adjustX(old_dir)) + Math.abs(adjustY(dir) -adjustY(old_dir)) >1);
- }
- private int adjustX(String a)
- {
- if(a.equals("w") || a.equals("nw") || a.equals("sw"))
- return -1;
- if(a.equals("e") || a.equals("ne") || a.equals("se"))
- return 1;
- return 0;
- }
- private int adjustY(String a)
- {
- if(a.equals("n") || a.equals("nw") || a.equals("ne"))
- return -1;
- if(a.equals("s") || a.equals("sw") || a.equals("se"))
- return 1;
- return 0;
- }
- private String reverse(String a)
- {
- if(a.equals("nw"))
- return "se";
- if(a.equals("n"))
- return "s";
- if(a.equals("ne"))
- return "sw";
- if(a.equals("w"))
- return "e";
- if(a.equals("e"))
- return "w";
- if(a.equals("sw"))
- return "ne";
- if(a.equals("se"))
- return "nw";
- if(a.equals("s"))
- return "n";
- return "";
- }
- //y x
- private void load(String name,char [][] a)
- {
- File f = new File(PATH_TO_MAP + name);
- BufferedReader br = new BufferedReader(new FileReader(f));
- String l;
- for(int y = 0; y < a.length; ++y)
- {
- l = br.readLine();
- a[y] = l.toCharArray();
- }
- br.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment