|
@@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|
import java.util.Collection;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
@@ -31,30 +32,19 @@ import com.l2jserver.gameserver.datatables.CharNameTable;
|
|
import com.l2jserver.gameserver.model.actor.L2Playable;
|
|
import com.l2jserver.gameserver.model.actor.L2Playable;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
|
|
import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
|
|
-import com.l2jserver.gameserver.util.L2TIntObjectHashMap;
|
|
|
|
|
|
+import com.l2jserver.gameserver.model.interfaces.IL2Procedure;
|
|
import com.l2jserver.gameserver.util.Point3D;
|
|
import com.l2jserver.gameserver.util.Point3D;
|
|
import com.l2jserver.util.StringUtil;
|
|
import com.l2jserver.util.StringUtil;
|
|
|
|
|
|
-import gnu.trove.procedure.TObjectProcedure;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * This class ...
|
|
|
|
- * @version $Revision: 1.21.2.5.2.7 $ $Date: 2005/03/27 15:29:32 $
|
|
|
|
- */
|
|
|
|
public final class L2World
|
|
public final class L2World
|
|
{
|
|
{
|
|
- private static Logger _log = Logger.getLogger(L2World.class.getName());
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Gracia border Flying objects not allowed to the east of it.
|
|
|
|
- */
|
|
|
|
|
|
+ private static final Logger _log = Logger.getLogger(L2World.class.getName());
|
|
|
|
+ /** Gracia border Flying objects not allowed to the east of it. */
|
|
public static final int GRACIA_MAX_X = -166168;
|
|
public static final int GRACIA_MAX_X = -166168;
|
|
public static final int GRACIA_MAX_Z = 6105;
|
|
public static final int GRACIA_MAX_Z = 6105;
|
|
public static final int GRACIA_MIN_Z = -895;
|
|
public static final int GRACIA_MIN_Z = -895;
|
|
|
|
|
|
- /*
|
|
|
|
- * biteshift, defines number of regions note, shifting by 15 will result in regions corresponding to map tiles shifting by 12 divides one tile to 8x8 regions
|
|
|
|
- */
|
|
|
|
|
|
+ /** Biteshift, defines number of regions note, shifting by 15 will result in regions corresponding to map tiles shifting by 12 divides one tile to 8x8 regions. */
|
|
public static final int SHIFT_BY = 12;
|
|
public static final int SHIFT_BY = 12;
|
|
|
|
|
|
private static final int TILE_SIZE = 32768;
|
|
private static final int TILE_SIZE = 32768;
|
|
@@ -73,43 +63,30 @@ public final class L2World
|
|
private static final int REGIONS_X = (MAP_MAX_X >> SHIFT_BY) + OFFSET_X;
|
|
private static final int REGIONS_X = (MAP_MAX_X >> SHIFT_BY) + OFFSET_X;
|
|
private static final int REGIONS_Y = (MAP_MAX_Y >> SHIFT_BY) + OFFSET_Y;
|
|
private static final int REGIONS_Y = (MAP_MAX_Y >> SHIFT_BY) + OFFSET_Y;
|
|
|
|
|
|
- // private FastMap<String, L2PcInstance> _allGms;
|
|
|
|
-
|
|
|
|
- /** HashMap(Integer Player id, L2PcInstance) containing all the players in game */
|
|
|
|
- private final L2TIntObjectHashMap<L2PcInstance> _allPlayers;
|
|
|
|
-
|
|
|
|
- /** L2ObjectHashMap(L2Object) containing all visible objects */
|
|
|
|
- private final L2TIntObjectHashMap<L2Object> _allObjects;
|
|
|
|
- private final L2TIntObjectHashMap<String> _allObjectsDebug;
|
|
|
|
-
|
|
|
|
- /** List with the pets instances and their owner id */
|
|
|
|
- private final L2TIntObjectHashMap<L2PetInstance> _petsInstance;
|
|
|
|
|
|
+ /** Map containing all the players in game. */
|
|
|
|
+ private final Map<Integer, L2PcInstance> _allPlayers = new ConcurrentHashMap<>();
|
|
|
|
+ /** Map containing all visible objects. */
|
|
|
|
+ private final Map<Integer, L2Object> _allObjects = new ConcurrentHashMap<>();
|
|
|
|
+ /** Map used for debug. */
|
|
|
|
+ private final Map<Integer, String> _allObjectsDebug = new ConcurrentHashMap<>();
|
|
|
|
+ /** Map with the pets instances and their owner ID. */
|
|
|
|
+ private final Map<Integer, L2PetInstance> _petsInstance = new ConcurrentHashMap<>();
|
|
|
|
|
|
private L2WorldRegion[][] _worldRegions;
|
|
private L2WorldRegion[][] _worldRegions;
|
|
|
|
|
|
- /**
|
|
|
|
- * Constructor of L2World.
|
|
|
|
- */
|
|
|
|
|
|
+ /** Constructor of L2World. */
|
|
protected L2World()
|
|
protected L2World()
|
|
{
|
|
{
|
|
- _allPlayers = new L2TIntObjectHashMap<>();
|
|
|
|
- _allObjects = new L2TIntObjectHashMap<>();
|
|
|
|
- _allObjectsDebug = new L2TIntObjectHashMap<>();
|
|
|
|
- _petsInstance = new L2TIntObjectHashMap<>();
|
|
|
|
-
|
|
|
|
initRegions();
|
|
initRegions();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @return the current instance of L2World.
|
|
|
|
- */
|
|
|
|
- public static L2World getInstance()
|
|
|
|
- {
|
|
|
|
- return SingletonHolder._instance;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Add L2Object object in _allObjects. <B><U> Example of use </U> :</B> <li>Withdraw an item from the warehouse, create an item</li> <li>Spawn a L2Character (PC, NPC, Pet)</li><BR>
|
|
|
|
|
|
+ * Adds an object to the world.<br>
|
|
|
|
+ * <B><U>Example of use</U>:</B>
|
|
|
|
+ * <ul>
|
|
|
|
+ * <li>Withdraw an item from the warehouse, create an item</li>
|
|
|
|
+ * <li>Spawn a L2Character (PC, NPC, Pet)</li>
|
|
|
|
+ * </ul>
|
|
* @param object
|
|
* @param object
|
|
*/
|
|
*/
|
|
public void storeObject(L2Object object)
|
|
public void storeObject(L2Object object)
|
|
@@ -129,8 +106,14 @@ public final class L2World
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Remove L2Object object from _allObjects of L2World. <B><U> Example of use </U> :</B> <li>Delete item from inventory, tranfer Item from inventory to warehouse</li> <li>Crystallize item</li> <li>Remove NPC/PC/Pet from the world</li><BR>
|
|
|
|
- * @param object L2Object to remove from _allObjects of L2World
|
|
|
|
|
|
+ * Removes an object from the world.<br>
|
|
|
|
+ * <B><U>Example of use</U>:</B>
|
|
|
|
+ * <ul>
|
|
|
|
+ * <li>Delete item from inventory, transfer Item from inventory to warehouse</li>
|
|
|
|
+ * <li>Crystallize item</li>
|
|
|
|
+ * <li>Remove NPC/PC/Pet from the world</li>
|
|
|
|
+ * </ul>
|
|
|
|
+ * @param object the object to remove
|
|
*/
|
|
*/
|
|
public void removeObject(L2Object object)
|
|
public void removeObject(L2Object object)
|
|
{
|
|
{
|
|
@@ -160,7 +143,10 @@ public final class L2World
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * <B><U> Example of use </U> :</B> <li>Client packets : Action, AttackRequest, RequestJoinParty, RequestJoinPledge...</li>
|
|
|
|
|
|
+ * <B><U> Example of use</U>:</B>
|
|
|
|
+ * <ul>
|
|
|
|
+ * <li>Client packets : Action, AttackRequest, RequestJoinParty, RequestJoinPledge...</li>
|
|
|
|
+ * </ul>
|
|
* @param oID Identifier of the L2Object
|
|
* @param oID Identifier of the L2Object
|
|
* @return the L2Object object that belongs to an ID or null if no object found.
|
|
* @return the L2Object object that belongs to an ID or null if no object found.
|
|
*/
|
|
*/
|
|
@@ -169,46 +155,40 @@ public final class L2World
|
|
return _allObjects.get(oID);
|
|
return _allObjects.get(oID);
|
|
}
|
|
}
|
|
|
|
|
|
- public final L2Object[] getAllVisibleObjectsArray()
|
|
|
|
- {
|
|
|
|
- return _allObjects.values(new L2Object[0]);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public final boolean forEachObject(final TObjectProcedure<L2Object> proc)
|
|
|
|
|
|
+ public Collection<L2Object> getVisibleObjects()
|
|
{
|
|
{
|
|
- return _allObjects.forEachValue(proc);
|
|
|
|
|
|
+ return _allObjects.values();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Get the count of all visible objects in world.
|
|
* Get the count of all visible objects in world.
|
|
* @return count off all L2World objects
|
|
* @return count off all L2World objects
|
|
*/
|
|
*/
|
|
- public final int getAllVisibleObjectsCount()
|
|
|
|
|
|
+ public int getVisibleObjectsCount()
|
|
{
|
|
{
|
|
return _allObjects.size();
|
|
return _allObjects.size();
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * @return a table containing all GMs.
|
|
|
|
- */
|
|
|
|
public List<L2PcInstance> getAllGMs()
|
|
public List<L2PcInstance> getAllGMs()
|
|
{
|
|
{
|
|
return AdminTable.getInstance().getAllGms(true);
|
|
return AdminTable.getInstance().getAllGms(true);
|
|
}
|
|
}
|
|
|
|
|
|
- public L2TIntObjectHashMap<L2PcInstance> getAllPlayers()
|
|
|
|
- {
|
|
|
|
- return _allPlayers;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public final L2PcInstance[] getAllPlayersArray()
|
|
|
|
|
|
+ public Collection<L2PcInstance> getPlayers()
|
|
{
|
|
{
|
|
- return _allPlayers.values(new L2PcInstance[0]);
|
|
|
|
|
|
+ return _allPlayers.values();
|
|
}
|
|
}
|
|
|
|
|
|
- public final boolean forEachPlayer(final TObjectProcedure<L2PcInstance> proc)
|
|
|
|
|
|
+ public boolean forEachPlayer(IL2Procedure<L2PcInstance> procedure)
|
|
{
|
|
{
|
|
- return _allPlayers.forEachValue(proc);
|
|
|
|
|
|
+ for (L2PcInstance player : _allPlayers.values())
|
|
|
|
+ {
|
|
|
|
+ if (!procedure.execute(player))
|
|
|
|
+ {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -290,23 +270,21 @@ public final class L2World
|
|
*/
|
|
*/
|
|
public void addVisibleObject(L2Object object, L2WorldRegion newRegion)
|
|
public void addVisibleObject(L2Object object, L2WorldRegion newRegion)
|
|
{
|
|
{
|
|
- // If selected L2Object is a L2PcIntance, add it in L2ObjectHashSet(L2PcInstance) _allPlayers of L2World
|
|
|
|
- // XXX TODO: this code should be obsoleted by protection in putObject func...
|
|
|
|
|
|
+ // TODO: this code should be obsoleted by protection in putObject func...
|
|
if (object.isPlayer())
|
|
if (object.isPlayer())
|
|
{
|
|
{
|
|
L2PcInstance player = object.getActingPlayer();
|
|
L2PcInstance player = object.getActingPlayer();
|
|
-
|
|
|
|
if (!player.isTeleporting())
|
|
if (!player.isTeleporting())
|
|
{
|
|
{
|
|
- L2PcInstance tmp = getPlayer(player.getObjectId());
|
|
|
|
- if (tmp != null)
|
|
|
|
|
|
+ final L2PcInstance old = getPlayer(player.getObjectId());
|
|
|
|
+ if (old != null)
|
|
{
|
|
{
|
|
_log.warning("Duplicate character!? Closing both characters (" + player.getName() + ")");
|
|
_log.warning("Duplicate character!? Closing both characters (" + player.getName() + ")");
|
|
player.logout();
|
|
player.logout();
|
|
- tmp.logout();
|
|
|
|
|
|
+ old.logout();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- addToAllPlayers(player);
|
|
|
|
|
|
+ addPlayerToWorld(player);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -345,21 +323,21 @@ public final class L2World
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Add the L2PcInstance to _allPlayers of L2World.
|
|
|
|
- * @param cha
|
|
|
|
|
|
+ * Adds the player to the world.
|
|
|
|
+ * @param player the player to add
|
|
*/
|
|
*/
|
|
- public void addToAllPlayers(L2PcInstance cha)
|
|
|
|
|
|
+ public void addPlayerToWorld(L2PcInstance player)
|
|
{
|
|
{
|
|
- _allPlayers.put(cha.getObjectId(), cha);
|
|
|
|
|
|
+ _allPlayers.put(player.getObjectId(), player);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Remove the L2PcInstance from _allPlayers of L2World. <B><U> Example of use </U> :</B> <li>Remove a player from the visible objects</li><BR>
|
|
|
|
- * @param cha
|
|
|
|
|
|
+ * Remove the player from the world.
|
|
|
|
+ * @param player the player to remove
|
|
*/
|
|
*/
|
|
- public void removeFromAllPlayers(L2PcInstance cha)
|
|
|
|
|
|
+ public void removeFromAllPlayers(L2PcInstance player)
|
|
{
|
|
{
|
|
- _allPlayers.remove(cha.getObjectId());
|
|
|
|
|
|
+ _allPlayers.remove(player.getObjectId());
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -564,7 +542,6 @@ public final class L2World
|
|
public List<L2Playable> getVisiblePlayable(L2Object object)
|
|
public List<L2Playable> getVisiblePlayable(L2Object object)
|
|
{
|
|
{
|
|
L2WorldRegion reg = object.getWorldRegion();
|
|
L2WorldRegion reg = object.getWorldRegion();
|
|
-
|
|
|
|
if (reg == null)
|
|
if (reg == null)
|
|
{
|
|
{
|
|
return null;
|
|
return null;
|
|
@@ -618,7 +595,7 @@ public final class L2World
|
|
* Returns the whole 2d array containing the world regions used by ZoneData.java to setup zones inside the world regions
|
|
* Returns the whole 2d array containing the world regions used by ZoneData.java to setup zones inside the world regions
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
- public L2WorldRegion[][] getAllWorldRegions()
|
|
|
|
|
|
+ public L2WorldRegion[][] getWorldRegions()
|
|
{
|
|
{
|
|
return _worldRegions;
|
|
return _worldRegions;
|
|
}
|
|
}
|
|
@@ -635,8 +612,7 @@ public final class L2World
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Init each L2WorldRegion and their surrounding table. <B><U> Concept</U> :</B> All surrounding L2WorldRegion are identified in <B>_surroundingRegions</B> of the selected L2WorldRegion in order to scan a large area around a L2Object <B><U> Example of use </U> :</B> <li>Constructor of L2World</li>
|
|
|
|
- * <BR>
|
|
|
|
|
|
+ * Initialize the world regions.
|
|
*/
|
|
*/
|
|
private void initRegions()
|
|
private void initRegions()
|
|
{
|
|
{
|
|
@@ -687,6 +663,14 @@ public final class L2World
|
|
_log.info("All visible NPC's deleted.");
|
|
_log.info("All visible NPC's deleted.");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @return the current instance of L2World
|
|
|
|
+ */
|
|
|
|
+ public static L2World getInstance()
|
|
|
|
+ {
|
|
|
|
+ return SingletonHolder._instance;
|
|
|
|
+ }
|
|
|
|
+
|
|
private static class SingletonHolder
|
|
private static class SingletonHolder
|
|
{
|
|
{
|
|
protected static final L2World _instance = new L2World();
|
|
protected static final L2World _instance = new L2World();
|