anybody?
|
Fixed issues please close
anybody?
@NathanTa please also provide source of StraightPathFinder.java so we can see what is causing the nullpointer.
No worries;
package com.xxx.rs2.entity.pathfinding;
import com.xxx.core.cache.map.Region;
import com.xxx.rs2.GameConstants;
import com.xxx.rs2.entity.Location;
/**
* function canShoot coords[] path = path from loc a to loc b coord prev for
* each next = coord in path if canMoveFrom(prev, next) and canMoveFrom(next,
* prev) projectile can pass so continue else if certain boolean in object on
* loc next projectile can pass so continue else projectile can not pass so
* return false return true
*/
public class StraightPathFinder {
private static boolean canAttackOver(int x, int y, int z, int pX, int pY) {
if (x == pX && y == pY) {
return true;
}
int dir = GameConstants.getDirection(x, y, pX, pY);
int dir2 = GameConstants.getDirection(pX, pY, x, y);
if (dir == -1 || dir2 == -1) {
System.out.println("NEGATIVE DIRECTION MELEE CLIP CHECK ERROR");
return false;
}
if (Region.getRegion(x, y).canMove(x, y, z, dir)) {
if (Region.getRegion(pX, pY) == null) {
}
}
return Region.getRegion(x, y).canMove(x, y, z, dir) && Region.getRegion(pX, pY).canMove(pX, pY, z, dir2);
}
public static boolean isInteractionPathClear(final int x0, final int y0, final int z, final int x1, final int y1) {
int deltaX = x1 - x0;
int deltaY = y1 - y0;
double error = 0;
final double deltaError = Math.abs((deltaY) / (deltaX == 0 ? ((double) deltaY) : ((double) deltaX)));
int x = x0;
int y = y0;
int pX = x;
int pY = y;
boolean incrX = x0 < x1;
boolean incrY = y0 < y1;
if (!RS317PathFinder.accessable(x0, y0, z, x1, y1)) {
return false;
}
while (true) {
if (x != x1) {
x += (incrX ? 1 : -1);
}
if (y != y1) {
error += deltaError;
if (error >= 0.5) {
y += (incrY ? 1 : -1);
error -= 1;
}
}
if (!canAttackOver(x, y, z, pX, pY)) {
return false;
}
if (incrX && incrY && x >= x1 && y >= y1) {
break;
} else if (!incrX && !incrY && x <= x1 && y <= y1) {
break;
} else if (!incrX && incrY && x <= x1 && y >= y1) {
break;
} else if (incrX && !incrY && x >= x1 && y <= y1) {
break;
}
pX = x;
pY = y;
}
return true;
}
public static boolean isInteractionPathClear(Location a, Location b) {
return isInteractionPathClear(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY());
}
public static boolean isProjectilePathClear(final int x0, final int y0, final int z, final int x1, final int y1) {
int deltaX = x1 - x0;
int deltaY = y1 - y0;
double error = 0;
final double deltaError = Math.abs((deltaY) / (deltaX == 0 ? ((double) deltaY) : ((double) deltaX)));
int x = x0;
int y = y0;
int pX = x;
int pY = y;
boolean incrX = x0 < x1;
boolean incrY = y0 < y1;
while (true) {
if (x != x1) {
x += (incrX ? 1 : -1);
}
if (y != y1) {
error += deltaError;
if (error >= 0.5) {
y += (incrY ? 1 : -1);
error -= 1;
}
}
if (!shootable(x, y, z, pX, pY)) {
return false;
}
if (incrX && incrY && x >= x1 && y >= y1) {
break;
} else if (!incrX && !incrY && x <= x1 && y <= y1) {
break;
} else if (!incrX && incrY && x <= x1 && y >= y1) {
break;
} else if (incrX && !incrY && x >= x1 && y <= y1) {
break;
}
pX = x;
pY = y;
}
return true;
}
public static boolean isProjectilePathClear(Location a, Location b) {
return isProjectilePathClear(a.getX(), a.getY(), a.getZ(), b.getX(), b.getY());
}
private static boolean shootable(int x, int y, int z, int pX, int pY) {
if (x == pX && y == pY) {
return true;
}
int dir = GameConstants.getDirection(x, y, pX, pY);
int dir2 = GameConstants.getDirection(pX, pY, x, y);
if (dir == -1 || dir2 == -1) {
System.out.println("NEGATIVE DIRECTION PROJECTILE ERROR");
return false;
}
if (Region.getRegion(x, y) == null || Region.getRegion(pX, pY) == null) {
return false;
}
if (Region.getRegion(x, y).canMove(x, y, z, dir) && Region.getRegion(pX, pY).canMove(pX, pY, z, dir2)) {
return true;
} else {
return Region.getRegion(x, y).canShoot(x, y, z, dir) && Region.getRegion(x, y).canShoot(pX, pY, z, dir2);
}
}
}
UPDATE:
So i got curious about another map that i added that i was gonna work on at some point but it turns out it causes the same issue so i do think its an issue with the server reading the region, completely new area for me so any advice would be appreciated other then that i'm gonna go spend a few hours researching this shit
Your missing the mapdata for these areas by the looks
You can check this by
Code:Region region = Region.getRegion(x, y); if (region == null) { System.out.println("region at x: "+ x +" y: "+ y +" does not exist"); return false; }
The part throwing the null is
because it wasn't checked if the region existed first before checking if it could move or "canMove".Code:if (Region.getRegion(x, y).canMove(x, y, z, dir)) { if (Region.getRegion(pX, pY) == null) { } } return Region.getRegion(x, y).canMove(x, y, z, dir) && Region.getRegion(pX, pY).canMove(pX, pY, z, dir2); }
you can prevent errors by replacing it with
Code:Region region = Region.getRegion(x, y); if (region == null) { System.out.println("region at x: "+ x +" y: "+ y +" does not exist"); return false; } return region.canMove(x, y, z, dir) && region.canMove(pX, pY, z, dir2); }
By map data so you mean the. Gz files that go in the cache?
I'll give what you said a try though, I'll let you know how it goes haha thanks
Right so yeah you was right it logged:
region at x: 2275 y: 10035 does not exist
stopped the crashing though haha, however when i get close to an npc it just vanishes i'm assuming that't to do with the map data, i did get my mapindex and the other 2 files and then dumped the maps from the cache and put them all into data/maps in server ran the map update but it caused region errors haha
Bump this is one of my last things i need to figure out so its kinda important!!
bump
Bump
so seriously nobody has any idea about this....
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |