Skip to content

Instantly share code, notes, and snippets.

@ChaosPaladin
Created April 24, 2016 15:32
Show Gist options
  • Save ChaosPaladin/1fc272d3941f28702a2f4561d95dcb0e to your computer and use it in GitHub Desktop.
Save ChaosPaladin/1fc272d3941f28702a2f4561d95dcb0e to your computer and use it in GitHub Desktop.
FBIagent's Fense support
### Eclipse Workspace Patch 1.0
#P L2J_Server_BETA
Index: java/com/l2jserver/gameserver/model/entity/Instance.java
===================================================================
--- java/com/l2jserver/gameserver/model/entity/Instance.java (revision 6624)
+++ 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/datatables/ColosseumFenceData.java
===================================================================
--- java/com/l2jserver/gameserver/datatables/ColosseumFenceData.java (revision 0)
+++ java/com/l2jserver/gameserver/datatables/ColosseumFenceData.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 java.util.concurrent.ConcurrentHashMap;
+
+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 ColosseumFenceData extends DocumentParser
+{
+ private final Map<Integer, List<L2ColosseumFence>> _static = new HashMap<>();
+ private final Map<Integer, List<L2ColosseumFence>> _dynamic = new ConcurrentHashMap<>();
+
+ protected ColosseumFenceData()
+ {
+ 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)
+ {
+ final Collection<L2ColosseumFence> allFences;
+ if ((instanceId > 0) && (InstanceManager.getInstance().getInstance(instanceId) != null))
+ {
+ allFences = InstanceManager.getInstance().getInstance(instanceId).getFences();
+ }
+ else
+ {
+ allFences = new ArrayList<>();
+ final int mapRegionId = MapRegionManager.getInstance().getMapRegionLocId(x, y);
+ if (_static.containsKey(mapRegionId))
+ {
+ allFences.addAll(_static.get(mapRegionId));
+ }
+ if (_dynamic.containsKey(mapRegionId))
+ {
+ allFences.addAll(_dynamic.get(mapRegionId));
+ }
+ }
+
+ for (L2ColosseumFence fence : allFences)
+ {
+ if ((fence.getFenceState() == FenceState.CLOSED) && (fence.isInsideFence(x, y, z) != fence.isInsideFence(tx, ty, tz)))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private static final class SingletonHolder
+ {
+ protected static final ColosseumFenceData INSTANCE = new ColosseumFenceData();
+ }
+
+ public static ColosseumFenceData getInstance()
+ {
+ return SingletonHolder.INSTANCE;
+ }
+}
Index: java/com/l2jserver/gameserver/instancemanager/InstanceManager.java
===================================================================
--- java/com/l2jserver/gameserver/instancemanager/InstanceManager.java (revision 6624)
+++ 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/GameServer.java
===================================================================
--- java/com/l2jserver/gameserver/GameServer.java (revision 6624)
+++ 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.ColosseumFenceData;
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();
+ ColosseumFenceData.getInstance();
ItemAuctionManager.getInstance();
CastleManager.getInstance().loadInstances();
FortManager.getInstance().loadInstances();
Index: java/com/l2jserver/gameserver/GeoData.java
===================================================================
--- java/com/l2jserver/gameserver/GeoData.java (revision 6624)
+++ 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.ColosseumFenceData;
import com.l2jserver.gameserver.datatables.DoorTable;
import com.l2jserver.gameserver.geoengine.Direction;
import com.l2jserver.gameserver.geoengine.NullDriver;
@@ -256,6 +257,10 @@
{
return false;
}
+ if (ColosseumFenceData.getInstance().checkIfFencesBetween(x, y, z, tx, ty, tz, instanceId))
+ {
+ return false;
+ }
return canSeeTarget(x, y, z, tx, ty, tz);
}
@@ -458,6 +463,10 @@
{
return new Location(x, y, getHeight(x, y, z));
}
+ if (ColosseumFenceData.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
@@ -544,6 +553,10 @@
{
return false;
}
+ if (ColosseumFenceData.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
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,59 @@
+/*
+ * 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(0x03);
+
+ writeD(_fence.getObjectId());
+ writeD(_fence.getFenceState().ordinal());
+ writeD(_fence.getX());
+ writeD(_fence.getY());
+ writeD(_fence.getZ());
+ writeD(_fence.getFenceWidth());
+ writeD(_fence.getFenceHeight());
+ }
+}
\ No newline at end of file
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));
+ }
+}
#P L2J_DataPack_BETA
Index: dist/game/data/xsd/colosseum_fences.xsd
===================================================================
--- dist/game/data/xsd/colosseum_fences.xsd (revision 0)
+++ dist/game/data/xsd/colosseum_fences.xsd (working copy)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <xs:element name="list">
+ <xs:complexType>
+ <xs:sequence maxOccurs="1" minOccurs="1">
+ <xs:element name="colosseum_fence" maxOccurs="unbounded" minOccurs="0">
+ <xs:complexType>
+ <xs:attribute name="x" type="xs:integer" use="required" />
+ <xs:attribute name="y" type="xs:integer" use="required" />
+ <xs:attribute name="z" type="xs:integer" use="required" />
+ <xs:attribute name="min_z" type="xs:integer" use="required" />
+ <xs:attribute name="max_z" type="xs:integer" use="required" />
+ <xs:attribute name="width" type="xs:positiveInteger" use="required" />
+ <xs:attribute name="height" type="xs:positiveInteger" use="required" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>
\ No newline at end of file
Index: dist/game/data/xsd/instance.xsd
===================================================================
--- dist/game/data/xsd/instance.xsd (revision 10425)
+++ dist/game/data/xsd/instance.xsd (working copy)
@@ -64,6 +64,23 @@
</xs:sequence>
</xs:complexType>
</xs:element>
+ <xs:element name="colosseum_fence_list" maxOccurs="1" minOccurs="0">
+ <xs:complexType>
+ <xs:sequence maxOccurs="1" minOccurs="1">
+ <xs:element name="colosseum_fence" maxOccurs="unbounded" minOccurs="1">
+ <xs:complexType>
+ <xs:attribute name="x" type="xs:int" />
+ <xs:attribute name="y" type="xs:int" />
+ <xs:attribute name="z" type="xs:int" />
+ <xs:attribute name="min_z" type="xs:int" />
+ <xs:attribute name="max_z" type="xs:int" />
+ <xs:attribute name="width" type="xs:positiveInteger" />
+ <xs:attribute name="height" type="xs:positiveInteger" />
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
<xs:element name="spawnlist" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
Index: dist/game/data/colosseum_fences.xml
===================================================================
--- dist/game/data/colosseum_fences.xml (revision 0)
+++ dist/game/data/colosseum_fences.xml (working copy)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd/colosseum_fences.xsd">
+</list>
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment