Support for random teleport list locations.
Contributed by Index.
This commit is contained in:
@@ -17,13 +17,16 @@
|
||||
package org.l2jmobius.gameserver.data.xml;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.l2jmobius.commons.util.IXmlReader;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
import org.l2jmobius.gameserver.model.StatSet;
|
||||
import org.l2jmobius.gameserver.model.holders.TeleportListHolder;
|
||||
|
||||
@@ -34,7 +37,7 @@ public class TeleportListData implements IXmlReader
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(TeleportListData.class.getName());
|
||||
private final Map<Integer, TeleportListHolder> _teleports = new HashMap<>();
|
||||
private int _teleportsCount = 0;
|
||||
private int _teleportCount = 0;
|
||||
|
||||
protected TeleportListData()
|
||||
{
|
||||
@@ -46,8 +49,8 @@ public class TeleportListData implements IXmlReader
|
||||
{
|
||||
_teleports.clear();
|
||||
parseDatapackFile("data/TeleportListData.xml");
|
||||
_teleportsCount = _teleports.size();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _teleportsCount + " teleports.");
|
||||
_teleportCount = _teleports.size();
|
||||
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _teleportCount + " teleports.");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,11 +60,18 @@ public class TeleportListData implements IXmlReader
|
||||
{
|
||||
final StatSet set = new StatSet(parseAttributes(teleportNode));
|
||||
final int tpId = set.getInt("id");
|
||||
final int x = set.getInt("x");
|
||||
final int y = set.getInt("y");
|
||||
final int z = set.getInt("z");
|
||||
final int tpPrice = set.getInt("price");
|
||||
_teleports.put(tpId, new TeleportListHolder(tpId, x, y, z, tpPrice));
|
||||
final List<Location> locations = new ArrayList<>();
|
||||
forEach(teleportNode, "location", locationsNode ->
|
||||
{
|
||||
final StatSet locationSet = new StatSet(parseAttributes(locationsNode));
|
||||
locations.add(new Location(locationSet.getInt("x"), locationSet.getInt("y"), locationSet.getInt("z")));
|
||||
});
|
||||
if (locations.isEmpty())
|
||||
{
|
||||
locations.add(new Location(set.getInt("x"), set.getInt("y"), set.getInt("z")));
|
||||
}
|
||||
_teleports.put(tpId, new TeleportListHolder(tpId, locations, tpPrice));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -70,9 +80,9 @@ public class TeleportListData implements IXmlReader
|
||||
return _teleports.get(teleportId);
|
||||
}
|
||||
|
||||
public int getTeleportsCount()
|
||||
public int getTeleportCount()
|
||||
{
|
||||
return _teleportsCount;
|
||||
return _teleportCount;
|
||||
}
|
||||
|
||||
public static TeleportListData getInstance()
|
||||
|
@@ -16,23 +16,33 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.holders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
|
||||
/**
|
||||
* @author NviX
|
||||
* @author NviX, Index
|
||||
*/
|
||||
public class TeleportListHolder
|
||||
{
|
||||
private final int _locId;
|
||||
private final int _x;
|
||||
private final int _y;
|
||||
private final int _z;
|
||||
private final List<Location> _locations;
|
||||
private final int _price;
|
||||
|
||||
public TeleportListHolder(int locId, int x, int y, int z, int price)
|
||||
{
|
||||
_locId = locId;
|
||||
_x = x;
|
||||
_y = y;
|
||||
_z = z;
|
||||
_locations = new ArrayList<>(1);
|
||||
_locations.add(new Location(x, y, z));
|
||||
_price = price;
|
||||
}
|
||||
|
||||
public TeleportListHolder(int locId, List<Location> locations, int price)
|
||||
{
|
||||
_locId = locId;
|
||||
_locations = locations;
|
||||
_price = price;
|
||||
}
|
||||
|
||||
@@ -41,23 +51,18 @@ public class TeleportListHolder
|
||||
return _locId;
|
||||
}
|
||||
|
||||
public int getX()
|
||||
public List<Location> getLocations()
|
||||
{
|
||||
return _x;
|
||||
}
|
||||
|
||||
public int getY()
|
||||
{
|
||||
return _y;
|
||||
}
|
||||
|
||||
public int getZ()
|
||||
{
|
||||
return _z;
|
||||
return _locations;
|
||||
}
|
||||
|
||||
public int getPrice()
|
||||
{
|
||||
return _price;
|
||||
}
|
||||
|
||||
public Location getLocation()
|
||||
{
|
||||
return _locations.get(Rnd.get(_locations.size()));
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.network.PacketReader;
|
||||
import org.l2jmobius.gameserver.data.xml.TeleportListData;
|
||||
import org.l2jmobius.gameserver.instancemanager.CastleManager;
|
||||
import org.l2jmobius.gameserver.model.Location;
|
||||
import org.l2jmobius.gameserver.model.actor.Player;
|
||||
import org.l2jmobius.gameserver.model.effects.EffectFlag;
|
||||
import org.l2jmobius.gameserver.model.holders.TeleportListHolder;
|
||||
@@ -95,9 +96,10 @@ public class ExRequestTeleport implements IClientIncomingPacket
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = teleport.getLocation();
|
||||
if (!Config.TELEPORT_WHILE_SIEGE_IN_PROGRESS)
|
||||
{
|
||||
final Castle castle = CastleManager.getInstance().getCastle(teleport.getX(), teleport.getY(), teleport.getZ());
|
||||
final Castle castle = CastleManager.getInstance().getCastle(location.getX(), location.getY(), location.getZ());
|
||||
if ((castle != null) && castle.getSiege().isInProgress())
|
||||
{
|
||||
player.sendPacket(SystemMessageId.YOU_CANNOT_TELEPORT_TO_A_VILLAGE_THAT_IS_IN_A_SIEGE);
|
||||
@@ -121,6 +123,6 @@ public class ExRequestTeleport implements IClientIncomingPacket
|
||||
|
||||
player.abortCast();
|
||||
player.stopMove(null);
|
||||
player.teleToLocation(teleport.getX(), teleport.getY(), teleport.getZ());
|
||||
player.teleToLocation(location);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user