L2J_GeoDriver, java-engine-1.8 and mmocore libraries are dropped and directly integrated to project under "com.l2jserver.commons".
This commit is contained in:
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.commons.geodriver.blocks;
|
||||
|
||||
import com.l2jserver.commons.geodriver.IBlock;
|
||||
|
||||
/**
|
||||
* @author HorridoJoho
|
||||
*/
|
||||
public abstract class AbstractBlock implements IBlock
|
||||
{
|
||||
private int limitZ(int z, int newZ, int deltaLimit)
|
||||
{
|
||||
if (Math.abs(z - newZ) > deltaLimit)
|
||||
{
|
||||
return z;
|
||||
}
|
||||
return newZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestZ(int geoX, int geoY, int worldZ, int zDeltaLimit)
|
||||
{
|
||||
return limitZ(worldZ, getNearestZ(geoX, geoY, worldZ), zDeltaLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextLowerZ(int geoX, int geoY, int worldZ, int zDeltaLimit)
|
||||
{
|
||||
return limitZ(worldZ, getNextLowerZ(geoX, geoY, worldZ), zDeltaLimit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextHigherZ(int geoX, int geoY, int worldZ, int zDeltaLimit)
|
||||
{
|
||||
return limitZ(worldZ, getNextHigherZ(geoX, geoY, worldZ), zDeltaLimit);
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.commons.geodriver.blocks;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.l2jserver.commons.geodriver.IBlock;
|
||||
|
||||
/**
|
||||
* @author HorridoJoho
|
||||
*/
|
||||
public final class ComplexBlock extends AbstractBlock
|
||||
{
|
||||
private final short[] _data;
|
||||
|
||||
public ComplexBlock(ByteBuffer bb)
|
||||
{
|
||||
_data = new short[IBlock.BLOCK_CELLS];
|
||||
for (int cellOffset = 0; cellOffset < IBlock.BLOCK_CELLS; cellOffset++)
|
||||
{
|
||||
_data[cellOffset] = bb.getShort();
|
||||
}
|
||||
}
|
||||
|
||||
private short _getCellData(int geoX, int geoY)
|
||||
{
|
||||
return _data[((geoX % IBlock.BLOCK_CELLS_X) * IBlock.BLOCK_CELLS_Y) + (geoY % IBlock.BLOCK_CELLS_Y)];
|
||||
}
|
||||
|
||||
private byte _getCellNSWE(int geoX, int geoY)
|
||||
{
|
||||
return (byte) (_getCellData(geoX, geoY) & 0x000F);
|
||||
}
|
||||
|
||||
private int _getCellHeight(int geoX, int geoY)
|
||||
{
|
||||
short height = (short) (_getCellData(geoX, geoY) & 0x0FFF0);
|
||||
return height >> 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe)
|
||||
{
|
||||
return (_getCellNSWE(geoX, geoY) & nswe) == nswe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe, int zDeltaLimit)
|
||||
{
|
||||
int height = _getCellHeight(geoX, geoY);
|
||||
return Math.abs(worldZ - height) > zDeltaLimit ? true : (_getCellNSWE(geoX, geoY) & nswe) == nswe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _getCellHeight(geoX, geoY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextLowerZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
int cellHeight = _getCellHeight(geoX, geoY);
|
||||
return cellHeight <= worldZ ? cellHeight : worldZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextHigherZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
int cellHeight = _getCellHeight(geoX, geoY);
|
||||
return cellHeight >= worldZ ? cellHeight : worldZ;
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.commons.geodriver.blocks;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* @author HorridoJoho
|
||||
*/
|
||||
public class FlatBlock extends AbstractBlock
|
||||
{
|
||||
private final short _height;
|
||||
|
||||
public FlatBlock(ByteBuffer bb)
|
||||
{
|
||||
_height = bb.getShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe, int zDeltaLimit)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextLowerZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _height <= worldZ ? _height : worldZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextHigherZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _height >= worldZ ? _height : worldZ;
|
||||
}
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2015 L2J Server
|
||||
*
|
||||
* This file is part of L2J Server.
|
||||
*
|
||||
* L2J Server is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* L2J Server is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.commons.geodriver.blocks;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import com.l2jserver.commons.geodriver.IBlock;
|
||||
|
||||
/**
|
||||
* @author FBIagent
|
||||
*/
|
||||
public class MultilayerBlock extends AbstractBlock
|
||||
{
|
||||
private final byte[] _data;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this block reading the specified buffer.
|
||||
* @param bb the buffer
|
||||
*/
|
||||
public MultilayerBlock(ByteBuffer bb)
|
||||
{
|
||||
int start = bb.position();
|
||||
|
||||
for (int blockCellOffset = 0; blockCellOffset < IBlock.BLOCK_CELLS; blockCellOffset++)
|
||||
{
|
||||
byte nLayers = bb.get();
|
||||
if ((nLayers <= 0) || (nLayers > 125))
|
||||
{
|
||||
throw new RuntimeException("L2JGeoDriver: Geo file corrupted! Invalid layers count!");
|
||||
}
|
||||
|
||||
bb.position(bb.position() + (nLayers * 2));
|
||||
}
|
||||
|
||||
_data = new byte[bb.position() - start];
|
||||
bb.position(start);
|
||||
bb.get(_data);
|
||||
}
|
||||
|
||||
private short _getNearestLayer(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
int startOffset = _getCellDataOffset(geoX, geoY);
|
||||
byte nLayers = _data[startOffset];
|
||||
int endOffset = startOffset + 1 + (nLayers * 2);
|
||||
|
||||
// 1 layer at least was required on loading so this is set at least once on the loop below
|
||||
int nearestDZ = 0;
|
||||
short nearestData = 0;
|
||||
for (int offset = startOffset + 1; offset < endOffset; offset += 2)
|
||||
{
|
||||
short layerData = _extractLayerData(offset);
|
||||
int layerZ = _extractLayerHeight(layerData);
|
||||
if (layerZ == worldZ)
|
||||
{
|
||||
// exact z
|
||||
return layerData;
|
||||
}
|
||||
|
||||
int layerDZ = Math.abs(layerZ - worldZ);
|
||||
if ((offset == (startOffset + 1)) || (layerDZ < nearestDZ))
|
||||
{
|
||||
nearestDZ = layerDZ;
|
||||
nearestData = layerData;
|
||||
}
|
||||
}
|
||||
|
||||
return nearestData;
|
||||
}
|
||||
|
||||
private int _getCellDataOffset(int geoX, int geoY)
|
||||
{
|
||||
int cellLocalOffset = ((geoX % IBlock.BLOCK_CELLS_X) * IBlock.BLOCK_CELLS_Y) + (geoY % IBlock.BLOCK_CELLS_Y);
|
||||
int cellDataOffset = 0;
|
||||
// move index to cell, we need to parse on each request, OR we parse on creation and save indexes
|
||||
for (int i = 0; i < cellLocalOffset; i++)
|
||||
{
|
||||
cellDataOffset += 1 + (_data[cellDataOffset] * 2);
|
||||
}
|
||||
// now the index points to the cell we need
|
||||
|
||||
return cellDataOffset;
|
||||
}
|
||||
|
||||
private short _extractLayerData(int dataOffset)
|
||||
{
|
||||
return (short) ((_data[dataOffset] & 0xFF) | (_data[dataOffset + 1] << 8));
|
||||
}
|
||||
|
||||
private int _getNearestNSWE(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _extractLayerNswe(_getNearestLayer(geoX, geoY, worldZ));
|
||||
}
|
||||
|
||||
private int _extractLayerNswe(short layer)
|
||||
{
|
||||
return (byte) (layer & 0x000F);
|
||||
}
|
||||
|
||||
private int _extractLayerHeight(short layer)
|
||||
{
|
||||
layer = (short) (layer & 0x0fff0);
|
||||
return layer >> 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe)
|
||||
{
|
||||
return (_getNearestNSWE(geoX, geoY, worldZ) & nswe) == nswe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkNearestNswe(int geoX, int geoY, int worldZ, int nswe, int zDeltaLimit)
|
||||
{
|
||||
short layer = _getNearestLayer(geoX, geoY, worldZ);
|
||||
int height = _extractLayerHeight(layer);
|
||||
return Math.abs(worldZ - height) > zDeltaLimit ? true : (_extractLayerNswe(layer) & nswe) == nswe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNearestZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
return _extractLayerHeight(_getNearestLayer(geoX, geoY, worldZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextLowerZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
int startOffset = _getCellDataOffset(geoX, geoY);
|
||||
byte nLayers = _data[startOffset];
|
||||
int endOffset = startOffset + 1 + (nLayers * 2);
|
||||
|
||||
int lowerZ = Integer.MIN_VALUE;
|
||||
for (int offset = startOffset + 1; offset < endOffset; offset += 2)
|
||||
{
|
||||
short layerData = _extractLayerData(offset);
|
||||
|
||||
int layerZ = _extractLayerHeight(layerData);
|
||||
if (layerZ == worldZ)
|
||||
{
|
||||
// exact z
|
||||
return layerZ;
|
||||
}
|
||||
|
||||
if ((layerZ < worldZ) && (layerZ > lowerZ))
|
||||
{
|
||||
lowerZ = layerZ;
|
||||
}
|
||||
}
|
||||
|
||||
return lowerZ == Integer.MIN_VALUE ? worldZ : lowerZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNextHigherZ(int geoX, int geoY, int worldZ)
|
||||
{
|
||||
int startOffset = _getCellDataOffset(geoX, geoY);
|
||||
byte nLayers = _data[startOffset];
|
||||
int endOffset = startOffset + 1 + (nLayers * 2);
|
||||
|
||||
int higherZ = Integer.MAX_VALUE;
|
||||
for (int offset = startOffset + 1; offset < endOffset; offset += 2)
|
||||
{
|
||||
short layerData = _extractLayerData(offset);
|
||||
|
||||
int layerZ = _extractLayerHeight(layerData);
|
||||
if (layerZ == worldZ)
|
||||
{
|
||||
// exact z
|
||||
return layerZ;
|
||||
}
|
||||
|
||||
if ((layerZ > worldZ) && (layerZ < higherZ))
|
||||
{
|
||||
higherZ = layerZ;
|
||||
}
|
||||
}
|
||||
|
||||
return higherZ == Integer.MAX_VALUE ? worldZ : higherZ;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user