This produces a visually perfect graphic at every single angle against any combination of entity sizes.
Note: This is a better visual than even Jagex did for OSRS. These graphic IDs are only in 500+(maybe in around 480+?); and if you're using an OSRS cache you need to pack them in as OSRS only has one graphic.
Thanks to Kris: The OSRS graphics ids are 478, 506, 1172, 1231
Code:
final Location el = entity.getCenterLocation();
final Location vl = victim.getCenterLocation();
int gfx;
Direction direction = Direction.getDirection(
entity.getCenterLocation(),
victim.getCenterLocation()
);
switch (direction) {
case SOUTH:
case SOUTH_EAST:
gfx = 282; // 478 for OSRS
direction = Direction.SOUTH;
break;
case NORTH:
case NORTH_WEST:
gfx = 283; // 506 for OSRS
direction = Direction.NORTH;
break;
case EAST:
case NORTH_EAST:
gfx = 284; // 1172 for OSRS
direction = Direction.EAST;
break;
default:
gfx = 285; // 1231 for OSRS
direction = Direction.WEST;
break;
}
Graphics.send(Graphics.create(gfx, 96, 20), // note: dragon halberd should have no (0) delay for the graphic!
entity.getCenterLocation().transform(direction)
);
You may need these functions if not using Arios:
Code:
public static Direction getDirection(int diffX, int diffY) {
if (diffX < 1) {
if (diffY < 1) {
return SOUTH_WEST;
} else if (diffY > 1) {
return NORTH_WEST;
}
return WEST;
} else if (diffX > 1) {
if (diffY < 1) {
return SOUTH_EAST;
} else if (diffY > 1) {
return NORTH_EAST;
}
return EAST;
}
if (diffY < 1) {
return SOUTH;
}
return NORTH;
}
public static Direction getDirection(Location location, Location l) {
return getDirection(l.getX() - location.getX(), l.getY() - location.getY());
}
Code:
public Location getCenterLocation() {
final int offset = size >> 1;
return location.transform(offset, offset, 0);
}
Code:
public Location transform(int diffX, int diffY, int z) {
return Location.create(x + diffX, y + diffY, this.z + z);
}