Replaced GeoData engine with newest version.

This commit is contained in:
MobiusDev
2017-07-19 23:56:27 +00:00
parent dc770c4a85
commit 40563ace6c
62 changed files with 4212 additions and 3499 deletions

View File

@@ -16,25 +16,165 @@
*/
package com.l2jmobius.gameserver.util;
import com.l2jserver.gameserver.geoengine.Direction;
import java.awt.Color;
import com.l2jmobius.gameserver.geodata.GeoData;
import com.l2jmobius.gameserver.geodata.geodriver.Cell;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.ExServerPrimitive;
/**
* @author FBIagent
* @author HorridoJoho
*/
public final class GeoUtils
{
public interface PointListener
public static void debug2DLine(L2PcInstance player, int x, int y, int tx, int ty, int z)
{
/**
* @param x
* @param y
* @return true proceed, false abort
*/
boolean onPoint(int x, int y);
final int gx = GeoData.getInstance().getGeoX(x);
final int gy = GeoData.getInstance().getGeoY(y);
final int tgx = GeoData.getInstance().getGeoX(tx);
final int tgy = GeoData.getInstance().getGeoY(ty);
final ExServerPrimitive prim = new ExServerPrimitive("Debug2DLine", x, y, z);
prim.addLine(Color.BLUE, GeoData.getInstance().getWorldX(gx), GeoData.getInstance().getWorldY(gy), z, GeoData.getInstance().getWorldX(tgx), GeoData.getInstance().getWorldY(tgy), z);
final LinePointIterator iter = new LinePointIterator(gx, gy, tgx, tgy);
while (iter.next())
{
final int wx = GeoData.getInstance().getWorldX(iter.x());
final int wy = GeoData.getInstance().getWorldY(iter.y());
prim.addPoint(Color.RED, wx, wy, z);
}
player.sendPacket(prim);
}
public static void debug3DLine(L2PcInstance player, int x, int y, int z, int tx, int ty, int tz)
{
final int gx = GeoData.getInstance().getGeoX(x);
final int gy = GeoData.getInstance().getGeoY(y);
final int tgx = GeoData.getInstance().getGeoX(tx);
final int tgy = GeoData.getInstance().getGeoY(ty);
final ExServerPrimitive prim = new ExServerPrimitive("Debug3DLine", x, y, z);
prim.addLine(Color.BLUE, GeoData.getInstance().getWorldX(gx), GeoData.getInstance().getWorldY(gy), z, GeoData.getInstance().getWorldX(tgx), GeoData.getInstance().getWorldY(tgy), tz);
final LinePointIterator3D iter = new LinePointIterator3D(gx, gy, z, tgx, tgy, tz);
iter.next();
int prevX = iter.x();
int prevY = iter.y();
int wx = GeoData.getInstance().getWorldX(prevX);
int wy = GeoData.getInstance().getWorldY(prevY);
int wz = iter.z();
prim.addPoint(Color.RED, wx, wy, wz);
while (iter.next())
{
final int curX = iter.x();
final int curY = iter.y();
if ((curX != prevX) || (curY != prevY))
{
wx = GeoData.getInstance().getWorldX(curX);
wy = GeoData.getInstance().getWorldY(curY);
wz = iter.z();
prim.addPoint(Color.RED, wx, wy, wz);
prevX = curX;
prevY = curY;
}
}
player.sendPacket(prim);
}
private static Color getDirectionColor(int x, int y, int z, int nswe)
{
if (GeoData.getInstance().checkNearestNswe(x, y, z, nswe))
{
return Color.GREEN;
}
return Color.RED;
}
public static void debugGrid(L2PcInstance player)
{
final int geoRadius = 20;
final int blocksPerPacket = 40;
int iBlock = blocksPerPacket;
int iPacket = 0;
ExServerPrimitive exsp = null;
final GeoData gd = GeoData.getInstance();
final int playerGx = gd.getGeoX(player.getX());
final int playerGy = gd.getGeoY(player.getY());
for (int dx = -geoRadius; dx <= geoRadius; ++dx)
{
for (int dy = -geoRadius; dy <= geoRadius; ++dy)
{
if (iBlock >= blocksPerPacket)
{
iBlock = 0;
if (exsp != null)
{
++iPacket;
player.sendPacket(exsp);
}
exsp = new ExServerPrimitive("DebugGrid_" + iPacket, player.getX(), player.getY(), -16000);
}
if (exsp == null)
{
throw new IllegalStateException();
}
final int gx = playerGx + dx;
final int gy = playerGy + dy;
final int x = gd.getWorldX(gx);
final int y = gd.getWorldY(gy);
final int z = gd.getNearestZ(gx, gy, player.getZ());
// north arrow
Color col = getDirectionColor(gx, gy, z, Cell.NSWE_NORTH);
exsp.addLine(col, x - 1, y - 7, z, x + 1, y - 7, z);
exsp.addLine(col, x - 2, y - 6, z, x + 2, y - 6, z);
exsp.addLine(col, x - 3, y - 5, z, x + 3, y - 5, z);
exsp.addLine(col, x - 4, y - 4, z, x + 4, y - 4, z);
// east arrow
col = getDirectionColor(gx, gy, z, Cell.NSWE_EAST);
exsp.addLine(col, x + 7, y - 1, z, x + 7, y + 1, z);
exsp.addLine(col, x + 6, y - 2, z, x + 6, y + 2, z);
exsp.addLine(col, x + 5, y - 3, z, x + 5, y + 3, z);
exsp.addLine(col, x + 4, y - 4, z, x + 4, y + 4, z);
// south arrow
col = getDirectionColor(gx, gy, z, Cell.NSWE_SOUTH);
exsp.addLine(col, x - 1, y + 7, z, x + 1, y + 7, z);
exsp.addLine(col, x - 2, y + 6, z, x + 2, y + 6, z);
exsp.addLine(col, x - 3, y + 5, z, x + 3, y + 5, z);
exsp.addLine(col, x - 4, y + 4, z, x + 4, y + 4, z);
col = getDirectionColor(gx, gy, z, Cell.NSWE_WEST);
exsp.addLine(col, x - 7, y - 1, z, x - 7, y + 1, z);
exsp.addLine(col, x - 6, y - 2, z, x - 6, y + 2, z);
exsp.addLine(col, x - 5, y - 3, z, x - 5, y + 3, z);
exsp.addLine(col, x - 4, y - 4, z, x - 4, y + 4, z);
++iBlock;
}
}
player.sendPacket(exsp);
}
/**
* difference between x values: never abover 1<br>
* difference between x values: never above 1<br>
* difference between y values: never above 1
* @param lastX
* @param lastY
@@ -42,36 +182,36 @@ public final class GeoUtils
* @param y
* @return
*/
public static Direction computeDirection(int lastX, int lastY, int x, int y)
public static int computeNswe(int lastX, int lastY, int x, int y)
{
if (x > lastX) // east
{
if (y > lastY)
{
return Direction.SOUTH_EAST;
return Cell.NSWE_SOUTH_EAST; // Direction.SOUTH_EAST;
}
else if (y < lastY)
{
return Direction.NORTH_EAST;
return Cell.NSWE_NORTH_EAST; // Direction.NORTH_EAST;
}
else
{
return Direction.EAST;
return Cell.NSWE_EAST; // Direction.EAST;
}
}
else if (x < lastX) // west
{
if (y > lastY)
{
return Direction.SOUTH_WEST;
return Cell.NSWE_SOUTH_WEST; // Direction.SOUTH_WEST;
}
else if (y < lastY)
{
return Direction.NORTH_WEST;
return Cell.NSWE_NORTH_WEST; // Direction.NORTH_WEST;
}
else
{
return Direction.WEST;
return Cell.NSWE_WEST; // Direction.WEST;
}
}
else
@@ -79,15 +219,15 @@ public final class GeoUtils
{
if (y > lastY)
{
return Direction.SOUTH;
return Cell.NSWE_SOUTH; // Direction.SOUTH;
}
else if (y < lastY)
{
return Direction.NORTH;
return Cell.NSWE_NORTH; // Direction.NORTH;
}
else
{
return null;// error, should never happen, TODO: Logging
throw new RuntimeException();
}
}
}

View File

@@ -325,4 +325,24 @@ public final class Util
}
return result;
}
/**
* @param text - the text to check
* @return {@code true} if {@code text} contains only numbers, {@code false} otherwise
*/
public static boolean isDigit(String text)
{
if ((text == null) || text.isEmpty())
{
return false;
}
for (char c : text.toCharArray())
{
if (!Character.isDigit(c))
{
return false;
}
}
return true;
}
}