Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.49 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package org.Runebot.methods;
  2.  
  3. import java.awt.Point;
  4. import java.util.ArrayList;
  5.  
  6. import org.Runebot.bot.Methods;
  7. import org.Runebot.wrappers.RSTile;
  8.  
  9. public class Walking {
  10.  
  11.         Methods me;
  12.  
  13.         public Walking(Methods m) {
  14.                 this.me = m;
  15.         }
  16.  
  17.         public RSTile[] generateStraightPath(RSTile target) {
  18.                 ArrayList<RSTile> path = new ArrayList<RSTile>();
  19.  
  20.                 RSTile myTile = this.me.character.getPos();
  21.                 int distance = myTile.distanceTo(target);
  22.                 if (distance <= 15
  23.                                 || !this.me.calculations.tileToMinimap(target).equals(
  24.                                                 new Point(-1, -1)))
  25.                         return new RSTile[] { target };
  26.                 int points = (int) Math.ceil((distance / 15) + 0.4999);
  27.                 int xDist = (target.x > myTile.x ? target.x - myTile.x : myTile.x
  28.                                 - target.x);
  29.                 int yDist = (target.y > myTile.y ? target.y - myTile.y : myTile.y
  30.                                 - target.y);
  31.                 int xStep = xDist / points;
  32.                 int yStep = yDist / points;
  33.  
  34.                 for (int i = 1; i <= points; i++) {
  35.                         int x = (target.x > myTile.x ? myTile.x + (xStep * i) : myTile.x
  36.                                         - (xStep * i));
  37.                         int y = (target.y > myTile.y ? myTile.y + (yStep * i) : myTile.y
  38.                                         - (yStep * i));
  39.                         path.add(new RSTile(x, y));
  40.                 }
  41.  
  42.                 return path.toArray(new RSTile[path.size()]);
  43.         }
  44.  
  45.         public RSTile[] randomizePath(RSTile[] path, int xDist, int yDist) {
  46.                 RSTile[] newPath = new RSTile[path.length];
  47.                 for (int i = 0; i < path.length; i++) {
  48.                         newPath[i] = new RSTile(path[i].x + this.me.random(-xDist, xDist),
  49.                                         path[i].y + this.me.random(-yDist, yDist));
  50.                 }
  51.                 return newPath;
  52.         }
  53.  
  54. }