Diagonal movement GeoEngine.
This commit is contained in:
@@ -18,8 +18,8 @@ package com.l2jmobius.gameserver.util;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import com.l2jmobius.gameserver.geodata.GeoData;
|
||||
import com.l2jmobius.gameserver.geodata.geodriver.Cell;
|
||||
import com.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
import com.l2jmobius.gameserver.geoengine.geodata.GeoStructure;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.ExServerPrimitive;
|
||||
|
||||
@@ -30,41 +30,44 @@ public final class GeoUtils
|
||||
{
|
||||
public static void debug2DLine(L2PcInstance player, int x, int y, int tx, int ty, int z)
|
||||
{
|
||||
final int gx = GeoData.getInstance().getGeoX(x);
|
||||
final int gy = GeoData.getInstance().getGeoY(y);
|
||||
final int gx = GeoEngine.getInstance().getGeoX(x);
|
||||
final int gy = GeoEngine.getInstance().getGeoY(y);
|
||||
|
||||
final int tgx = GeoData.getInstance().getGeoX(tx);
|
||||
final int tgy = GeoData.getInstance().getGeoY(ty);
|
||||
final int tgx = GeoEngine.getInstance().getGeoX(tx);
|
||||
final int tgy = GeoEngine.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);
|
||||
prim.addLine(Color.BLUE, GeoEngine.getInstance().getWorldX(gx), GeoEngine.getInstance().getWorldY(gy), z, GeoEngine.getInstance().getWorldX(tgx), GeoEngine.getInstance().getWorldY(tgy), z);
|
||||
|
||||
final LinePointIterator iter = new LinePointIterator(gx, gy, tgx, tgy);
|
||||
|
||||
while (iter.next())
|
||||
{
|
||||
prim.addPoint(Color.RED, GeoData.getInstance().getWorldX(iter.x()), GeoData.getInstance().getWorldY(iter.y()), z);
|
||||
final int wx = GeoEngine.getInstance().getWorldX(iter.x());
|
||||
final int wy = GeoEngine.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 gx = GeoEngine.getInstance().getGeoX(x);
|
||||
final int gy = GeoEngine.getInstance().getGeoY(y);
|
||||
|
||||
final int tgx = GeoData.getInstance().getGeoX(tx);
|
||||
final int tgy = GeoData.getInstance().getGeoY(ty);
|
||||
final int tgx = GeoEngine.getInstance().getGeoX(tx);
|
||||
final int tgy = GeoEngine.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);
|
||||
prim.addLine(Color.BLUE, GeoEngine.getInstance().getWorldX(gx), GeoEngine.getInstance().getWorldY(gy), z, GeoEngine.getInstance().getWorldX(tgx), GeoEngine.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 wx = GeoEngine.getInstance().getWorldX(prevX);
|
||||
int wy = GeoEngine.getInstance().getWorldY(prevY);
|
||||
int wz = iter.z();
|
||||
prim.addPoint(Color.RED, wx, wy, wz);
|
||||
|
||||
@@ -75,8 +78,8 @@ public final class GeoUtils
|
||||
|
||||
if ((curX != prevX) || (curY != prevY))
|
||||
{
|
||||
wx = GeoData.getInstance().getWorldX(curX);
|
||||
wy = GeoData.getInstance().getWorldY(curY);
|
||||
wx = GeoEngine.getInstance().getWorldX(curX);
|
||||
wy = GeoEngine.getInstance().getWorldY(curY);
|
||||
wz = iter.z();
|
||||
|
||||
prim.addPoint(Color.RED, wx, wy, wz);
|
||||
@@ -90,18 +93,23 @@ public final class GeoUtils
|
||||
|
||||
private static Color getDirectionColor(int x, int y, int z, int nswe)
|
||||
{
|
||||
return GeoData.getInstance().checkNearestNswe(x, y, z, nswe) ? Color.GREEN : Color.RED;
|
||||
if ((GeoEngine.getInstance().getNsweNearest(x, y, z) & nswe) == nswe)
|
||||
{
|
||||
return Color.GREEN;
|
||||
}
|
||||
return Color.RED;
|
||||
}
|
||||
|
||||
public static void debugGrid(L2PcInstance player)
|
||||
{
|
||||
final int geoRadius = 10;
|
||||
final int blocksPerPacket = 49;
|
||||
final int geoRadius = 20;
|
||||
final int blocksPerPacket = 40;
|
||||
|
||||
int iBlock = blocksPerPacket;
|
||||
int iPacket = 0;
|
||||
|
||||
ExServerPrimitive exsp = null;
|
||||
final GeoData gd = GeoData.getInstance();
|
||||
final GeoEngine gd = GeoEngine.getInstance();
|
||||
final int playerGx = gd.getGeoX(player.getX());
|
||||
final int playerGy = gd.getGeoY(player.getY());
|
||||
for (int dx = -geoRadius; dx <= geoRadius; ++dx)
|
||||
@@ -129,30 +137,30 @@ public final class GeoUtils
|
||||
|
||||
final int x = gd.getWorldX(gx);
|
||||
final int y = gd.getWorldY(gy);
|
||||
final int z = gd.getNearestZ(gx, gy, player.getZ());
|
||||
final int z = gd.getHeightNearest(gx, gy, player.getZ());
|
||||
|
||||
// north arrow
|
||||
Color col = getDirectionColor(gx, gy, z, Cell.NSWE_NORTH);
|
||||
Color col = getDirectionColor(gx, gy, z, GeoStructure.CELL_FLAG_N);
|
||||
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);
|
||||
col = getDirectionColor(gx, gy, z, GeoStructure.CELL_FLAG_E);
|
||||
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);
|
||||
col = getDirectionColor(gx, gy, z, GeoStructure.CELL_FLAG_S);
|
||||
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);
|
||||
col = getDirectionColor(gx, gy, z, GeoStructure.CELL_FLAG_W);
|
||||
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);
|
||||
@@ -180,43 +188,47 @@ public final class GeoUtils
|
||||
{
|
||||
if (y > lastY)
|
||||
{
|
||||
return Cell.NSWE_SOUTH_EAST; // Direction.SOUTH_EAST;
|
||||
return GeoStructure.CELL_FLAG_SE; // Direction.SOUTH_EAST;
|
||||
}
|
||||
else if (y < lastY)
|
||||
{
|
||||
return Cell.NSWE_NORTH_EAST; // Direction.NORTH_EAST;
|
||||
return GeoStructure.CELL_FLAG_NE; // Direction.NORTH_EAST;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Cell.NSWE_EAST; // Direction.EAST;
|
||||
return GeoStructure.CELL_FLAG_E; // Direction.EAST;
|
||||
}
|
||||
}
|
||||
else if (x < lastX) // west
|
||||
{
|
||||
if (y > lastY)
|
||||
{
|
||||
return Cell.NSWE_SOUTH_WEST; // Direction.SOUTH_WEST;
|
||||
return GeoStructure.CELL_FLAG_SW; // Direction.SOUTH_WEST;
|
||||
}
|
||||
else if (y < lastY)
|
||||
{
|
||||
return Cell.NSWE_NORTH_WEST; // Direction.NORTH_WEST;
|
||||
return GeoStructure.CELL_FLAG_NW; // Direction.NORTH_WEST;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Cell.NSWE_WEST; // Direction.WEST;
|
||||
return GeoStructure.CELL_FLAG_W; // Direction.WEST;
|
||||
}
|
||||
}
|
||||
else if (y > lastY)
|
||||
{
|
||||
return Cell.NSWE_SOUTH; // Direction.SOUTH;
|
||||
}
|
||||
else if (y < lastY)
|
||||
{
|
||||
return Cell.NSWE_NORTH; // Direction.NORTH;
|
||||
}
|
||||
else
|
||||
// unchanged x
|
||||
{
|
||||
throw new RuntimeException();
|
||||
if (y > lastY)
|
||||
{
|
||||
return GeoStructure.CELL_FLAG_S; // Direction.SOUTH;
|
||||
}
|
||||
else if (y < lastY)
|
||||
{
|
||||
return GeoStructure.CELL_FLAG_N; // Direction.NORTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.l2jmobius.gameserver.util;
|
||||
|
||||
/**
|
||||
* @author UnAfraid
|
||||
*/
|
||||
public class MathUtil
|
||||
{
|
||||
public static byte add(byte oldValue, byte value)
|
||||
{
|
||||
return (byte) (oldValue + value);
|
||||
}
|
||||
|
||||
public static short add(short oldValue, short value)
|
||||
{
|
||||
return (short) (oldValue + value);
|
||||
}
|
||||
|
||||
public static int add(int oldValue, int value)
|
||||
{
|
||||
return oldValue + value;
|
||||
}
|
||||
|
||||
public static double add(double oldValue, double value)
|
||||
{
|
||||
return oldValue + value;
|
||||
}
|
||||
|
||||
public static byte mul(byte oldValue, byte value)
|
||||
{
|
||||
return (byte) (oldValue * value);
|
||||
}
|
||||
|
||||
public static short mul(short oldValue, short value)
|
||||
{
|
||||
return (short) (oldValue * value);
|
||||
}
|
||||
|
||||
public static int mul(int oldValue, int value)
|
||||
{
|
||||
return oldValue * value;
|
||||
}
|
||||
|
||||
public static double mul(double oldValue, double value)
|
||||
{
|
||||
return oldValue * value;
|
||||
}
|
||||
|
||||
public static byte div(byte oldValue, byte value)
|
||||
{
|
||||
return (byte) (oldValue / value);
|
||||
}
|
||||
|
||||
public static short div(short oldValue, short value)
|
||||
{
|
||||
return (short) (oldValue / value);
|
||||
}
|
||||
|
||||
public static int div(int oldValue, int value)
|
||||
{
|
||||
return oldValue / value;
|
||||
}
|
||||
|
||||
public static double div(double oldValue, double value)
|
||||
{
|
||||
return oldValue / value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numToTest : The number to test.
|
||||
* @param min : The minimum limit.
|
||||
* @param max : The maximum limit.
|
||||
* @return the number or one of the limit (mininum / maximum).
|
||||
*/
|
||||
public static int limit(int numToTest, int min, int max)
|
||||
{
|
||||
return (numToTest > max) ? max : ((numToTest < min) ? min : numToTest);
|
||||
}
|
||||
}
|
@@ -0,0 +1,276 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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.l2jmobius.gameserver.util;
|
||||
|
||||
import com.l2jmobius.Config;
|
||||
|
||||
/**
|
||||
* String utilities optimized for the best performance.<br>
|
||||
* <h1>How to Use It</h1>
|
||||
* <h2>concat() or append()</h2> If concatenating strings<br>
|
||||
* in single call, use StringUtil.concat(), otherwise use StringUtil.append()<br>
|
||||
* and its variants.<br>
|
||||
* <br>
|
||||
* <h2>Minimum Calls</h2><br>
|
||||
* Bad:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString = new StringBuilder();
|
||||
* StringUtil.append(sbString, "text 1", String.valueOf(npcId));
|
||||
* StringUtil.append("text 2");
|
||||
* </pre>
|
||||
*
|
||||
* Good:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString = new StringBuilder();
|
||||
* StringUtil.append(sbString, "text 1", String.valueOf(npcId), "text 2");
|
||||
* </pre>
|
||||
*
|
||||
* Why?<br/>
|
||||
* Because the less calls you do, the less memory re-allocations have to be done<br>
|
||||
* so the whole text fits into the memory and less array copy tasks has to be<br>
|
||||
* performed. So if using less calls, less memory is used and string concatenation is faster.<br>
|
||||
* <br>
|
||||
* <h2>Size Hints for Loops</h2><br>
|
||||
* Bad:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString = new StringBuilder();
|
||||
* StringUtil.append(sbString, "header start", someText, "header end");
|
||||
* for (int i = 0; i < 50; i++)
|
||||
* {
|
||||
* StringUtil.append(sbString, "text 1", stringArray[i], "text 2");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Good:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString = StringUtil.startAppend(1300, "header start", someText, "header end");
|
||||
* for (int i = 0; i < 50; i++)
|
||||
* {
|
||||
* StringUtil.append(sbString, "text 1", stringArray[i], "text 2");
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* Why?<br/>
|
||||
* When using StringUtil.append(), memory is only allocated to fit in the strings in method argument. So on each loop new memory for the string has to be allocated and old string has to be copied to the new string. With size hint, even if the size hint is above the needed memory, memory is saved
|
||||
* because new memory has not to be allocated on each cycle. Also it is much faster if no string copy tasks has to be performed. So if concatenating strings in a loop, count approximately the size and set it as the hint for the string builder size. It's better to make the size hint little bit larger
|
||||
* rather than smaller.<br/>
|
||||
* In case there is no text appended before the cycle, just use <code>new
|
||||
* StringBuilder(1300)</code>.<br>
|
||||
* <br>
|
||||
* <h2>Concatenation and Constants</h2><br>
|
||||
* Bad:
|
||||
*
|
||||
* <pre>
|
||||
* StringUtil.concat("text 1 ", "text 2", String.valueOf(npcId));
|
||||
* </pre>
|
||||
*
|
||||
* Good:
|
||||
*
|
||||
* <pre>
|
||||
* StringUtil.concat("text 1 " + "text 2", String.valueOf(npcId));
|
||||
* </pre>
|
||||
*
|
||||
* or
|
||||
*
|
||||
* <pre>
|
||||
* StringUtil.concat("text 1 text 2", String.valueOf(npcId));
|
||||
* </pre>
|
||||
*
|
||||
* Why?<br/>
|
||||
* It saves some cycles when determining size of memory that needs to be allocated because less strings are passed to concat() method. But do not use + for concatenation of non-constant strings, that degrades performance and makes extra memory allocations needed.<br>
|
||||
* <h2>Concatenation and Constant Variables</h2> Bad:
|
||||
*
|
||||
* <pre>
|
||||
* String glue = "some glue";
|
||||
* StringUtil.concat("text 1", glue, "text 2", glue, String.valueOf(npcId));
|
||||
* </pre>
|
||||
*
|
||||
* Good:
|
||||
*
|
||||
* <pre>
|
||||
* final String glue = "some glue";
|
||||
* StringUtil.concat("text 1" + glue + "text2" + glue, String.valueOf(npcId));
|
||||
* </pre>
|
||||
*
|
||||
* Why? Because when using <code>final</code> keyword, the <code>glue</code> is marked as constant string and compiler treats it as a constant string so it is able to create string "text1some gluetext2some glue" during the compilation. But this only works in case the value is known at compilation
|
||||
* time, so this cannot be used for cases like <code>final String objectIdString =
|
||||
* String.valueOf(getObjectId)</code>.<br>
|
||||
* <br>
|
||||
* <h2>StringBuilder Reuse</h2><br>
|
||||
* Bad:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString1 = new StringBuilder();
|
||||
* StringUtil.append(sbString1, "text 1", String.valueOf(npcId), "text 2");
|
||||
* ... // output of sbString1, it is no more needed
|
||||
* final StringBuilder sbString2 = new StringBuilder();
|
||||
* StringUtil.append(sbString2, "text 3", String.valueOf(npcId), "text 4");
|
||||
* </pre>
|
||||
*
|
||||
* Good:
|
||||
*
|
||||
* <pre>
|
||||
* final StringBuilder sbString = new StringBuilder();
|
||||
* StringUtil.append(sbString, "text 1", String.valueOf(npcId), "text 2");
|
||||
* ... // output of sbString, it is no more needed
|
||||
* sbString.setLength(0);
|
||||
* StringUtil.append(sbString, "text 3", String.valueOf(npcId), "text 4");
|
||||
* </pre>
|
||||
*
|
||||
* Why?</br>
|
||||
* In first case, new memory has to be allocated for the second string. In second case already allocated memory is reused, but only in case the new string is not longer than the previously allocated string. Anyway, the second way is better because the string either fits in the memory and some memory
|
||||
* is saved, or it does not fit in the memory, and in that case it works as in the first case.
|
||||
* <h2>Primitives to Strings</h2> To convert primitives to string, use String.valueOf().<br>
|
||||
* <br>
|
||||
* <h2>How much faster is it?</h2><br>
|
||||
* Here are some results of my tests. Count is number of strings concatenated. Don't take the numbers as 100% true as the numbers are affected by other programs running on my computer at the same time. Anyway, from the results it is obvious that using StringBuilder with predefined size is the
|
||||
* fastest (and also most memory efficient) solution. It is about 5 times faster when concatenating 7 strings, compared to TextBuilder. Also, with more strings concatenated, the difference between StringBuilder and TextBuilder gets larger. In code, there are many cases, where there are concatenated
|
||||
* 50+ strings so the time saving is even greater.<br>
|
||||
*
|
||||
* <pre>
|
||||
* Count: 2
|
||||
* TextBuilder: 1893
|
||||
* TextBuilder with size: 1703
|
||||
* String: 1033
|
||||
* StringBuilder: 993
|
||||
* StringBuilder with size: 1024
|
||||
* Count: 3
|
||||
* TextBuilder: 1973
|
||||
* TextBuilder with size: 1872
|
||||
* String: 2583
|
||||
* StringBuilder: 1633
|
||||
* StringBuilder with size: 1156
|
||||
* Count: 4
|
||||
* TextBuilder: 2188
|
||||
* TextBuilder with size: 2229
|
||||
* String: 4207
|
||||
* StringBuilder: 1816
|
||||
* StringBuilder with size: 1444
|
||||
* Count: 5
|
||||
* TextBuilder: 9185
|
||||
* TextBuilder with size: 9464
|
||||
* String: 6937
|
||||
* StringBuilder: 2745
|
||||
* StringBuilder with size: 1882
|
||||
* Count: 6
|
||||
* TextBuilder: 9785
|
||||
* TextBuilder with size: 10082
|
||||
* String: 9471
|
||||
* StringBuilder: 2889
|
||||
* StringBuilder with size: 1857
|
||||
* Count: 7
|
||||
* TextBuilder: 10169
|
||||
* TextBuilder with size: 10528
|
||||
* String: 12746
|
||||
* StringBuilder: 3081
|
||||
* StringBuilder with size: 2139
|
||||
* </pre>
|
||||
*
|
||||
* @author fordfrog
|
||||
*/
|
||||
public final class StringUtil
|
||||
{
|
||||
private StringUtil()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenates strings.
|
||||
* @param strings strings to be concatenated
|
||||
* @return concatenated string
|
||||
*/
|
||||
public static String concat(String... strings)
|
||||
{
|
||||
final StringBuilder sbString = new StringBuilder();
|
||||
for (String string : strings)
|
||||
{
|
||||
sbString.append(string);
|
||||
}
|
||||
return sbString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new string builder with size initializated to <code>sizeHint</code>, unless total length of strings is greater than <code>sizeHint</code>.
|
||||
* @param sizeHint hint for string builder size allocation
|
||||
* @param strings strings to be appended
|
||||
* @return created string builder
|
||||
*/
|
||||
public static StringBuilder startAppend(int sizeHint, String... strings)
|
||||
{
|
||||
final int length = getLength(strings);
|
||||
final StringBuilder sbString = new StringBuilder(sizeHint > length ? sizeHint : length);
|
||||
for (String string : strings)
|
||||
{
|
||||
sbString.append(string);
|
||||
}
|
||||
return sbString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends strings to existing string builder.
|
||||
* @param sbString string builder
|
||||
* @param strings strings to be appended
|
||||
*/
|
||||
public static void append(StringBuilder sbString, String... strings)
|
||||
{
|
||||
sbString.ensureCapacity(sbString.length() + getLength(strings));
|
||||
|
||||
for (String string : strings)
|
||||
{
|
||||
sbString.append(string);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLength(Iterable<String> strings)
|
||||
{
|
||||
int length = 0;
|
||||
for (String string : strings)
|
||||
{
|
||||
length += (string == null) ? 4 : string.length();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Counts total length of all the strings.
|
||||
* @param strings array of strings
|
||||
* @return total length of all the strings
|
||||
*/
|
||||
public static int getLength(String[] strings)
|
||||
{
|
||||
int length = 0;
|
||||
for (String string : strings)
|
||||
{
|
||||
length += (string == null) ? 4 : string.length();
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
public static String getTraceString(StackTraceElement[] trace)
|
||||
{
|
||||
final StringBuilder sbString = new StringBuilder();
|
||||
for (StackTraceElement element : trace)
|
||||
{
|
||||
sbString.append(element.toString()).append(Config.EOL);
|
||||
}
|
||||
return sbString.toString();
|
||||
}
|
||||
}
|
@@ -33,7 +33,7 @@ import com.l2jmobius.Config;
|
||||
import com.l2jmobius.gameserver.ThreadPoolManager;
|
||||
import com.l2jmobius.gameserver.enums.HtmlActionScope;
|
||||
import com.l2jmobius.gameserver.enums.IllegalActionPunishmentType;
|
||||
import com.l2jmobius.gameserver.geodata.GeoData;
|
||||
import com.l2jmobius.gameserver.geoengine.GeoEngine;
|
||||
import com.l2jmobius.gameserver.model.L2Object;
|
||||
import com.l2jmobius.gameserver.model.actor.L2Character;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
@@ -652,7 +652,7 @@ public final class Util
|
||||
}
|
||||
|
||||
final L2Character cha = (L2Character) obj;
|
||||
if (((cha.getZ() < (npc.getZ() - 100)) && (cha.getZ() > (npc.getZ() + 100))) || !GeoData.getInstance().canSeeTarget(cha.getX(), cha.getY(), cha.getZ(), npc.getX(), npc.getY(), npc.getZ()))
|
||||
if (((cha.getZ() < (npc.getZ() - 100)) && (cha.getZ() > (npc.getZ() + 100))) || !GeoEngine.getInstance().canSeeTarget(cha, npc))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user