Calculating interactive tiles for an object
Basically this will return an array of locations that can be used to verify if you are at the object. This will fix using objects through walls if you check that you are standing in one of the returned locations.
Put this inside your RSObject class or GameObject class which ever your server uses.
Code:
public final int NORTH = 2;
public final int EAST = 8;
public final int SOUTH = 32;
public final int WEST = 128;
public Location[] getInteractiveLocations() {
ObjectDef def = ObjectDef.getObjectDef(getId());
int xSize = def.xLength();
int ySize = def.yLength();
int type = getType();
if (type == 10 || type == 11 || type == 22) {
if (getFace() == 1 || getFace() == 3) {
xSize = def.yLength();
ySize = def.xLength();
}
}
int indexSize = xSize * 2 + ySize * 2;
int index = 0;
Location[] perimeter = new Location[indexSize];
// west side
for (int i = 0; i < ySize; i++) {
Location w = new Location(getX() - 1, getY() + i, getZ());
if ((Region.getClipping(w) & EAST) == 0)
perimeter[index++] = w;
}
// north side
for (int i = 0; i < xSize; i++) {
Location n = new Location(getX() + i, getY() + ySize, getZ());
if ((Region.getClipping(n) & SOUTH) == 0)
perimeter[index++] = n;
}
// east side
for (int i = 0; i < ySize; i++) {
Location e = new Location(getX() + xSize, getY() + i, getZ());
if ((Region.getClipping(e) & WEST) == 0)
perimeter[index++] = e;
}
//south side
for (int i = 0; i < xSize; i++) {
Location s = new Location(getX() + i, getY() - 1, getZ());
if ((Region.getClipping(s) & NORTH) == 0)
perimeter[index++] = s;
}
Location[] validPositions = new Location[indexSize];
index = 0;
for (Location l : perimeter) {
if (l == null)
continue;
if (Region.getClipping(l) < 256) {
validPositions[index++] = l;
}
}
return validPositions;
}
Using this, May need to change RSObject to GameObject depends on your source.
Code:
public boolean withinDistance(Player player, RSObject object) {
Location[] interactiveLocations = object.getInteractiveLocations();
for(Location location : interactiveLocations) {
if (location == null)
continue;
if (location.equals(player.getLocation())) {
return true;
}
}
return false;
}
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]