Last active
August 29, 2015 14:05
-
-
Save u3games/f04f36b0dfa44f2dbc86 to your computer and use it in GitHub Desktop.
L2J-Server_Core-6625_Fences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: java/com/l2jserver/gameserver/datatables/ColosseumFenceTable.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/datatables/ColosseumFenceTable.java (revision 0) | |
+++ java/com/l2jserver/gameserver/datatables/ColosseumFenceTable.java (working copy) | |
@@ -0,0 +1,137 @@ | |
+/* | |
+ * Copyright (C) 2004-2014 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.gameserver.datatables; | |
+ | |
+import java.util.ArrayList; | |
+import java.util.Collection; | |
+import java.util.HashMap; | |
+import java.util.List; | |
+import java.util.Map; | |
+ | |
+import org.w3c.dom.Element; | |
+import org.w3c.dom.NodeList; | |
+ | |
+import com.l2jserver.gameserver.engines.DocumentParser; | |
+import com.l2jserver.gameserver.instancemanager.InstanceManager; | |
+import com.l2jserver.gameserver.instancemanager.MapRegionManager; | |
+import com.l2jserver.gameserver.model.actor.L2ColosseumFence; | |
+import com.l2jserver.gameserver.model.actor.L2ColosseumFence.FenceState; | |
+ | |
+/** | |
+ * @author FBIagent | |
+ */ | |
+public final class ColosseumFenceTable extends DocumentParser | |
+{ | |
+ private static final class SingletonHolder | |
+ { | |
+ protected static final ColosseumFenceTable INSTANCE = new ColosseumFenceTable(); | |
+ } | |
+ | |
+ public static ColosseumFenceTable getInstance() | |
+ { | |
+ return SingletonHolder.INSTANCE; | |
+ } | |
+ | |
+ private final Map<Integer, List<L2ColosseumFence>> _static = new HashMap<>(); | |
+ private final Map<Integer, List<L2ColosseumFence>> _dynamic = new HashMap<>(); | |
+ | |
+ protected ColosseumFenceTable() | |
+ { | |
+ load(); | |
+ } | |
+ | |
+ @Override | |
+ public void load() | |
+ { | |
+ _static.clear(); | |
+ parseDatapackFile("data/colosseum_fences.xml"); | |
+ } | |
+ | |
+ @Override | |
+ protected void parseDocument() | |
+ { | |
+ Element root = getCurrentDocument().getDocumentElement(); | |
+ NodeList fences = root.getElementsByTagName("colosseum_fence"); | |
+ for (int i = 0; i < fences.getLength(); ++i) | |
+ { | |
+ Element fence = (Element) fences.item(i); | |
+ int x = Integer.parseInt(fence.getAttribute("x")); | |
+ int y = Integer.parseInt(fence.getAttribute("y")); | |
+ int z = Integer.parseInt(fence.getAttribute("z")); | |
+ int minZ = Integer.parseInt(fence.getAttribute("min_z")); | |
+ int maxZ = Integer.parseInt(fence.getAttribute("max_z")); | |
+ int width = Integer.parseInt(fence.getAttribute("width")); | |
+ int height = Integer.parseInt(fence.getAttribute("height")); | |
+ L2ColosseumFence fenceInstance = new L2ColosseumFence(0, x, y, z, minZ, maxZ, width, height, FenceState.CLOSED); | |
+ Integer region = MapRegionManager.getInstance().getMapRegionLocId(fenceInstance); | |
+ if (!_static.containsKey(region)) | |
+ { | |
+ _static.put(region, new ArrayList<L2ColosseumFence>()); | |
+ } | |
+ _static.get(region).add(fenceInstance); | |
+ fenceInstance.spawnMe(); | |
+ } | |
+ } | |
+ | |
+ public L2ColosseumFence addDynamic(int x, int y, int z, int minZ, int maxZ, int width, int height) | |
+ { | |
+ L2ColosseumFence fence = new L2ColosseumFence(0, x, y, z, minZ, maxZ, width, height, FenceState.CLOSED); | |
+ Integer region = MapRegionManager.getInstance().getMapRegionLocId(fence); | |
+ if (!_dynamic.containsKey(region)) | |
+ { | |
+ _dynamic.put(region, new ArrayList<L2ColosseumFence>()); | |
+ } | |
+ _dynamic.get(region).add(fence); | |
+ fence.spawnMe(); | |
+ return fence; | |
+ } | |
+ | |
+ public boolean checkIfFencesBetween(int x, int y, int z, int tx, int ty, int tz, int instanceId) | |
+ { | |
+ Collection<L2ColosseumFence> allFences; | |
+ if ((instanceId > 0) && (InstanceManager.getInstance().getInstance(instanceId) != null)) | |
+ { | |
+ allFences = InstanceManager.getInstance().getInstance(instanceId).getFences(); | |
+ } | |
+ else | |
+ { | |
+ int mapRegion = MapRegionManager.getInstance().getMapRegionLocId(x, y); | |
+ allFences = new ArrayList<>(); | |
+ if (_static.containsKey(mapRegion)) | |
+ { | |
+ allFences.addAll(_static.get(mapRegion)); | |
+ } | |
+ | |
+ if (_dynamic.containsKey(mapRegion)) | |
+ { | |
+ allFences.addAll(_dynamic.get(mapRegion)); | |
+ } | |
+ } | |
+ | |
+ for (L2ColosseumFence fence : allFences) | |
+ { | |
+ if ((fence.getFenceState() == FenceState.CLOSED) && (fence.isInsideFence(x, y, z) != fence.isInsideFence(tx, ty, tz))) | |
+ { | |
+ return true; | |
+ } | |
+ } | |
+ | |
+ return false; | |
+ } | |
+} | |
Index: java/com/l2jserver/gameserver/GameServer.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/GameServer.java (revision 6625) | |
+++ java/com/l2jserver/gameserver/GameServer.java (working copy) | |
@@ -49,6 +49,7 @@ | |
import com.l2jserver.gameserver.datatables.CharTemplateTable; | |
import com.l2jserver.gameserver.datatables.ClanTable; | |
import com.l2jserver.gameserver.datatables.ClassListData; | |
+import com.l2jserver.gameserver.datatables.ColosseumFenceTable; | |
import com.l2jserver.gameserver.datatables.CrestTable; | |
import com.l2jserver.gameserver.datatables.DoorTable; | |
import com.l2jserver.gameserver.datatables.EnchantItemData; | |
@@ -281,6 +282,7 @@ | |
StaticObjects.getInstance(); | |
ZoneManager.getInstance(); | |
DoorTable.getInstance(); | |
+ ColosseumFenceTable.getInstance(); | |
ItemAuctionManager.getInstance(); | |
CastleManager.getInstance().loadInstances(); | |
FortManager.getInstance().loadInstances(); | |
Index: java/com/l2jserver/gameserver/GeoData.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/GeoData.java (revision 6625) | |
+++ java/com/l2jserver/gameserver/GeoData.java (working copy) | |
@@ -26,6 +26,7 @@ | |
import java.util.logging.Logger; | |
import com.l2jserver.Config; | |
+import com.l2jserver.gameserver.datatables.ColosseumFenceTable; | |
import com.l2jserver.gameserver.datatables.DoorTable; | |
import com.l2jserver.gameserver.geoengine.Direction; | |
import com.l2jserver.gameserver.geoengine.NullDriver; | |
@@ -256,6 +257,12 @@ | |
{ | |
return false; | |
} | |
+ | |
+ if (ColosseumFenceTable.getInstance().checkIfFencesBetween(x, y, z, tx, ty, tz, instanceId)) | |
+ { | |
+ return false; | |
+ } | |
+ | |
return canSeeTarget(x, y, z, tx, ty, tz); | |
} | |
@@ -459,6 +466,11 @@ | |
return new Location(x, y, getHeight(x, y, z)); | |
} | |
+ if (ColosseumFenceTable.getInstance().checkIfFencesBetween(x, y, z, tx, ty, tz, instanceId)) | |
+ { | |
+ return new Location(x, y, getHeight(x, y, z)); | |
+ } | |
+ | |
LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY); | |
// first point is guaranteed to be available | |
pointIter.next(); | |
@@ -545,6 +557,11 @@ | |
return false; | |
} | |
+ if (ColosseumFenceTable.getInstance().checkIfFencesBetween(fromX, fromY, fromZ, toX, toY, toZ, instanceId)) | |
+ { | |
+ return false; | |
+ } | |
+ | |
LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY); | |
// first point is guaranteed to be available | |
pointIter.next(); | |
Index: java/com/l2jserver/gameserver/instancemanager/InstanceManager.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/instancemanager/InstanceManager.java (revision 6625) | |
+++ java/com/l2jserver/gameserver/instancemanager/InstanceManager.java (working copy) | |
@@ -268,6 +268,7 @@ | |
temp.removeNpcs(); | |
temp.removePlayers(); | |
temp.removeDoors(); | |
+ temp.removeFences(); | |
temp.cancelTimer(); | |
_instanceList.remove(instanceid); | |
if (_instanceWorlds.containsKey(instanceid)) | |
Index: java/com/l2jserver/gameserver/model/actor/L2ColosseumFence.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/model/actor/L2ColosseumFence.java (revision 0) | |
+++ java/com/l2jserver/gameserver/model/actor/L2ColosseumFence.java (working copy) | |
@@ -0,0 +1,130 @@ | |
+/* | |
+ * Copyright (C) 2004-2014 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.gameserver.model.actor; | |
+ | |
+import java.awt.Rectangle; | |
+ | |
+import com.l2jserver.gameserver.idfactory.IdFactory; | |
+import com.l2jserver.gameserver.model.L2Object; | |
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; | |
+import com.l2jserver.gameserver.network.serverpackets.ExColosseumFenceInfo; | |
+ | |
+/** | |
+ * @author FBIagent | |
+ */ | |
+public final class L2ColosseumFence extends L2Object | |
+{ | |
+ public enum FenceState | |
+ { | |
+ HIDDEN, // the fene isn't shown at all | |
+ OPEN, // the 4 edges of the fence is shown only | |
+ CLOSED // full fence | |
+ } | |
+ | |
+ private final int _minZ; | |
+ private final int _maxZ; | |
+ private final FenceState _state; | |
+ private final Rectangle _bounds; | |
+ | |
+ private L2ColosseumFence(int objectId, int instanceId, int x, int y, int z, int minZ, int maxZ, int width, int height, FenceState state) | |
+ { | |
+ super(objectId); | |
+ setInstanceId(instanceId); | |
+ setXYZ(x, y, z); | |
+ _minZ = minZ; | |
+ _maxZ = maxZ; | |
+ _state = state; | |
+ _bounds = new Rectangle(x - (width / 2), y - (height / 2), width, height); | |
+ } | |
+ | |
+ /** | |
+ * Creates a new fence with auto generated object id. | |
+ * @param instanceId the instance | |
+ * @param x the middle point x | |
+ * @param y the middle point y | |
+ * @param z the middle point z | |
+ * @param minZ min z | |
+ * @param maxZ max z | |
+ * @param width the width along the x axis | |
+ * @param height the height along the y axis | |
+ * @param state the fence state | |
+ */ | |
+ public L2ColosseumFence(int instanceId, int x, int y, int z, int minZ, int maxZ, int width, int height, FenceState state) | |
+ { | |
+ this(IdFactory.getInstance().getNextId(), instanceId, x, y, z, minZ, maxZ, width, height, state); | |
+ } | |
+ | |
+ @Override | |
+ public void sendInfo(L2PcInstance activeChar) | |
+ { | |
+ activeChar.sendPacket(new ExColosseumFenceInfo(this)); | |
+ } | |
+ | |
+ public int getFenceX() | |
+ { | |
+ return _bounds.x; | |
+ } | |
+ | |
+ public int getFenceY() | |
+ { | |
+ return _bounds.y; | |
+ } | |
+ | |
+ public int getFenceMinZ() | |
+ { | |
+ return _minZ; | |
+ } | |
+ | |
+ public int getFenceMaxZ() | |
+ { | |
+ return _maxZ; | |
+ } | |
+ | |
+ public int getFenceWidth() | |
+ { | |
+ return _bounds.width; | |
+ } | |
+ | |
+ public int getFenceHeight() | |
+ { | |
+ return _bounds.height; | |
+ } | |
+ | |
+ public FenceState getFenceState() | |
+ { | |
+ return _state; | |
+ } | |
+ | |
+ @Override | |
+ public int getId() | |
+ { | |
+ return getObjectId(); | |
+ } | |
+ | |
+ @Override | |
+ public boolean isAutoAttackable(L2Character attacker) | |
+ { | |
+ return false; | |
+ } | |
+ | |
+ public boolean isInsideFence(int x, int y, int z) | |
+ { | |
+ return (x >= _bounds.x) && (y >= _bounds.y) && (z >= _minZ) && (z <= _maxZ) && (x <= (_bounds.x + _bounds.width)) && (y <= (_bounds.y + _bounds.width)); | |
+ } | |
+} | |
Index: java/com/l2jserver/gameserver/model/entity/Instance.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/model/entity/Instance.java (revision 6625) | |
+++ java/com/l2jserver/gameserver/model/entity/Instance.java (working copy) | |
@@ -36,8 +36,10 @@ | |
import javolution.util.FastMap; | |
import org.w3c.dom.Document; | |
+import org.w3c.dom.Element; | |
import org.w3c.dom.NamedNodeMap; | |
import org.w3c.dom.Node; | |
+import org.w3c.dom.NodeList; | |
import com.l2jserver.Config; | |
import com.l2jserver.gameserver.Announcements; | |
@@ -54,6 +56,8 @@ | |
import com.l2jserver.gameserver.model.TeleportWhereType; | |
import com.l2jserver.gameserver.model.actor.L2Attackable; | |
import com.l2jserver.gameserver.model.actor.L2Character; | |
+import com.l2jserver.gameserver.model.actor.L2ColosseumFence; | |
+import com.l2jserver.gameserver.model.actor.L2ColosseumFence.FenceState; | |
import com.l2jserver.gameserver.model.actor.L2Npc; | |
import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance; | |
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; | |
@@ -81,6 +85,7 @@ | |
private final List<Integer> _players = new FastList<Integer>().shared(); | |
private final List<L2Npc> _npcs = new FastList<L2Npc>().shared(); | |
private final Map<Integer, L2DoorInstance> _doors = new ConcurrentHashMap<>(); | |
+ private final Map<Integer, L2ColosseumFence> _fences = new ConcurrentHashMap<>(); | |
private final Map<String, List<L2Spawn>> _manualSpawn = new HashMap<>(); | |
private Location _spawnLoc = null; | |
private boolean _allowSummon = true; | |
@@ -256,13 +261,14 @@ | |
* Adds a door into the instance | |
* @param doorId - from doors.xml | |
* @param set - StatsSet for initializing door | |
+ * @return the new door | |
*/ | |
- public void addDoor(int doorId, StatsSet set) | |
+ public L2DoorInstance addDoor(int doorId, StatsSet set) | |
{ | |
if (_doors.containsKey(doorId)) | |
{ | |
_log.warning("Door ID " + doorId + " already exists in instance " + getId()); | |
- return; | |
+ return null; | |
} | |
final L2DoorInstance newdoor = new L2DoorInstance(IdFactory.getInstance().getNextId(), new L2DoorTemplate(set)); | |
@@ -270,8 +276,17 @@ | |
newdoor.setCurrentHp(newdoor.getMaxHp()); | |
newdoor.spawnMe(newdoor.getTemplate().getX(), newdoor.getTemplate().getY(), newdoor.getTemplate().getZ()); | |
_doors.put(doorId, newdoor); | |
+ return newdoor; | |
} | |
+ public L2ColosseumFence addFence(int x, int y, int z, int minZ, int maxZ, int width, int height, FenceState state) | |
+ { | |
+ L2ColosseumFence newFence = new L2ColosseumFence(getId(), x, y, z, minZ, maxZ, width, height, state); | |
+ newFence.spawnMe(); | |
+ _fences.put(newFence.getObjectId(), newFence); | |
+ return newFence; | |
+ } | |
+ | |
public List<Integer> getPlayers() | |
{ | |
return _players; | |
@@ -287,6 +302,11 @@ | |
return _doors.values(); | |
} | |
+ public Collection<L2ColosseumFence> getFences() | |
+ { | |
+ return _fences.values(); | |
+ } | |
+ | |
public L2DoorInstance getDoor(int id) | |
{ | |
return _doors.get(id); | |
@@ -393,6 +413,21 @@ | |
_doors.clear(); | |
} | |
+ public void removeFences() | |
+ { | |
+ for (L2ColosseumFence fence : _fences.values()) | |
+ { | |
+ if (fence == null) | |
+ { | |
+ continue; | |
+ } | |
+ | |
+ fence.decayMe(); | |
+ fence.getKnownList().removeAllKnownObjects(); | |
+ } | |
+ _fences.clear(); | |
+ } | |
+ | |
/** | |
* Spawns group of instance NPC's | |
* @param groupName - name of group from XML definition to spawn | |
@@ -554,6 +589,23 @@ | |
} | |
} | |
} | |
+ else if ((n.getNodeType() == Node.ELEMENT_NODE) && "colloseum_fence_list".equalsIgnoreCase(n.getNodeName())) | |
+ { | |
+ Element parent = (Element) n; | |
+ NodeList childs = parent.getElementsByTagName("colosseum_fence"); | |
+ for (int i = 0; i < childs.getLength(); ++i) | |
+ { | |
+ Element f = (Element) childs.item(i); | |
+ int x = Integer.parseInt(f.getAttribute("x")); | |
+ int y = Integer.parseInt(f.getAttribute("y")); | |
+ int z = Integer.parseInt(f.getAttribute("z")); | |
+ int minz = Integer.parseInt(f.getAttribute("min_z")); | |
+ int maxz = Integer.parseInt(f.getAttribute("max_z")); | |
+ int width = Integer.parseInt(f.getAttribute("width")); | |
+ int height = Integer.parseInt(f.getAttribute("height")); | |
+ addFence(x, y, z, minz, maxz, width, height, FenceState.CLOSED); | |
+ } | |
+ } | |
else if ("spawnlist".equalsIgnoreCase(n.getNodeName())) | |
{ | |
for (Node group = n.getFirstChild(); group != null; group = group.getNextSibling()) | |
Index: java/com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java | |
=================================================================== | |
--- java/com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java (revision 0) | |
+++ java/com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java (working copy) | |
@@ -0,0 +1,60 @@ | |
+/* | |
+ * Copyright (C) 2004-2014 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.gameserver.network.serverpackets; | |
+ | |
+import com.l2jserver.gameserver.model.actor.L2ColosseumFence; | |
+ | |
+/** | |
+ * OP: 0xFE<br> | |
+ * OP2: 0x0003<br> | |
+ * Format: ddddddd<br> | |
+ * - d: object id<br> | |
+ * - d: state(0=hidden, 1=unconnected corners, 2=connected corners)<br> | |
+ * - d: x<br> | |
+ * - d: y<br> | |
+ * - d: z<br> | |
+ * - d: a side length<br> | |
+ * - d: b side length<br> | |
+ * @author FBIagent | |
+ */ | |
+ | |
+public class ExColosseumFenceInfo extends L2GameServerPacket | |
+{ | |
+ private final L2ColosseumFence _fence; | |
+ | |
+ public ExColosseumFenceInfo(L2ColosseumFence fence) | |
+ { | |
+ _fence = fence; | |
+ } | |
+ | |
+ @Override | |
+ protected void writeImpl() | |
+ { | |
+ writeC(0xfe); | |
+ writeH(0x0003); | |
+ | |
+ writeD(_fence.getObjectId()); | |
+ writeD(_fence.getFenceState().ordinal()); | |
+ writeD(_fence.getX()); | |
+ writeD(_fence.getY()); | |
+ writeD(_fence.getZ()); | |
+ writeD(_fence.getFenceWidth()); | |
+ writeD(_fence.getFenceHeight()); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment