Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: com/l2jserver/gameserver/GameServer.java
- ===================================================================
- --- com/l2jserver/gameserver/GameServer.java (revision 5685)
- +++ com/l2jserver/gameserver/GameServer.java (working copy)
- @@ -49,6 +49,7 @@
- import com.l2jserver.gameserver.datatables.EnchantOptionsData;
- import com.l2jserver.gameserver.datatables.EventDroplist;
- import com.l2jserver.gameserver.datatables.ExperienceTable;
- +import com.l2jserver.gameserver.datatables.FencesTable;
- import com.l2jserver.gameserver.datatables.FishData;
- import com.l2jserver.gameserver.datatables.FishingMonstersData;
- import com.l2jserver.gameserver.datatables.FishingRodsData;
- @@ -256,7 +257,7 @@
- PathFinding.getInstance();
- }
- - printSection("NPCs");
- + printSection("WorldObjects");
- HerbDropTable.getInstance();
- NpcTable.getInstance();
- NpcWalkerRoutesData.getInstance();
- @@ -269,6 +270,7 @@
- FortManager.getInstance().loadInstances();
- NpcBufferTable.getInstance();
- SpawnTable.getInstance();
- + FencesTable.getInstance();
- HellboundManager.getInstance();
- RaidBossSpawnManager.getInstance();
- DayNightSpawnManager.getInstance().trim().notifyChangeMode();
- Index: com/l2jserver/gameserver/datatables/FencesTable.java
- ===================================================================
- --- com/l2jserver/gameserver/datatables/FencesTable.java (revision 0)
- +++ com/l2jserver/gameserver/datatables/FencesTable.java (revision 0)
- @@ -0,0 +1,173 @@
- +/*
- + * 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.l2jserver.gameserver.datatables;
- +
- +import java.sql.Connection;
- +import java.sql.PreparedStatement;
- +import java.sql.ResultSet;
- +import java.sql.SQLException;
- +import java.util.HashMap;
- +import java.util.Map;
- +import java.util.logging.Level;
- +import java.util.logging.Logger;
- +
- +import com.l2jserver.L2DatabaseFactory;
- +import com.l2jserver.gameserver.model.Location;
- +import com.l2jserver.gameserver.model.actor.instance.L2FenceInstance;
- +import com.l2jserver.util.StringUtil;
- +
- +/**
- + * @author Nik based on Christian's work.
- + */
- +public class FencesTable
- +{
- + protected static final Logger _log = Logger.getLogger(FencesTable.class.getName());
- +
- + private static final class SingletonHolder
- + {
- + protected static final FencesTable _instance = new FencesTable();
- + }
- +
- + public static FencesTable getInstance()
- + {
- + return SingletonHolder._instance;
- + }
- +
- + private final Map<Integer, L2FenceInstance> _fences = new HashMap<>();
- +
- + protected FencesTable()
- + {
- + load();
- + _log.log(Level.INFO, StringUtil.concat("Loaded ", String.valueOf(_fences.size()), " stored fences."));
- + }
- +
- + private void load()
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement stmt = con.prepareStatement("SELECT * FROM fences"))
- + {
- + ResultSet res = stmt.executeQuery();
- + while (res.next())
- + {
- + L2FenceInstance fence = new L2FenceInstance(res.getInt("object_id"), res.getInt("state"), res.getInt("x"), res.getInt("y"), res.getInt("z"), res.getInt("width"), res.getInt("length"), res.getInt("height"));
- + fence.setStoredToDB(true); // They are loaded from DB, therefore they are stored there.
- + fence.spawnMe();
- + }
- + }
- + catch (SQLException sqle)
- + {
- + _log.log(Level.WARNING, "Exception while loading fences: ", sqle);
- + }
- + }
- +
- + public void reload()
- + {
- + for (L2FenceInstance fence : _fences.values())
- + {
- + // Do not delete temp fences, they aren't stored in DB therefore they won't be reloaded, but deleted.
- + if (!fence.isStoredToDB())
- + {
- + fence.decayMe();
- + }
- + }
- +
- + load();
- + }
- +
- + public void addFence(L2FenceInstance fence)
- + {
- + _fences.put(fence.getObjectId(), fence);
- + }
- +
- + public void getFence(int objectId)
- + {
- + _fences.get(objectId);
- + }
- +
- + public L2FenceInstance removeFence(int objectId)
- + {
- + return _fences.remove(objectId);
- + }
- +
- + public void deleteFence(int objectId, boolean deleteFromDB)
- + {
- + L2FenceInstance fence = removeFence(objectId);
- + if (fence != null)
- + {
- + fence.decayMe();
- + }
- +
- + if (deleteFromDB)
- + {
- + deleteStoredFence(objectId);
- + }
- + }
- +
- + /**
- + * @param fence - Stores the fence to the database.
- + */
- + public void storeFence(L2FenceInstance fence)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement stmt = con.prepareStatement("INSERT INTO fences (object_id,state,x,y,z,width,length,height) VALUES(?,?,?,?,?,?,?,?)"))
- + {
- + stmt.setInt(1, fence.getObjectId());
- + stmt.setInt(2, fence.getX());
- + stmt.setInt(3, fence.getY());
- + stmt.setInt(4, fence.getZ());
- + stmt.setInt(5, fence.getWidth());
- + stmt.setInt(6, fence.getLength());
- + stmt.setInt(6, fence.getHeight());
- + stmt.executeUpdate();
- + }
- + catch (SQLException sqle)
- + {
- + _log.log(Level.WARNING, "Error while storing fence:", sqle);
- + }
- + }
- +
- + public boolean deleteStoredFence(int objectId)
- + {
- + try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- + PreparedStatement stmt = con.prepareStatement("DELETE FROM fences WHERE object_id=?");)
- + {
- +
- + stmt.setInt(1, objectId);
- + if (stmt.executeUpdate() > 0)
- + {
- + return true;
- + }
- + }
- + catch (SQLException sqle)
- + {
- + _log.log(Level.WARNING, "Error while deleting stored fence:", sqle);
- + }
- +
- + return false;
- + }
- +
- + public boolean checkIfBetweenFences(Location loc1, Location loc2)
- + {
- + for (L2FenceInstance fence : _fences.values())
- + {
- + if (!fence.canSee(loc1, loc2))
- + {
- + return true;
- + }
- + }
- +
- + return true;
- + }
- +}
- Index: com/l2jserver/gameserver/model/L2Object.java
- ===================================================================
- --- com/l2jserver/gameserver/model/L2Object.java (revision 5685)
- +++ com/l2jserver/gameserver/model/L2Object.java (working copy)
- @@ -64,6 +64,7 @@
- L2Object(null),
- L2ItemInstance(L2Object),
- L2Character(L2Object),
- + L2FenceInstance(L2Object),
- L2Npc(L2Character),
- L2Playable(L2Character),
- L2Summon(L2Playable),
- Index: com/l2jserver/gameserver/model/actor/instance/L2FenceInstance.java
- ===================================================================
- --- com/l2jserver/gameserver/model/actor/instance/L2FenceInstance.java (revision 0)
- +++ com/l2jserver/gameserver/model/actor/instance/L2FenceInstance.java (revision 0)
- @@ -0,0 +1,214 @@
- +/*
- + * 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.l2jserver.gameserver.model.actor.instance;
- +
- +import java.awt.Rectangle;
- +
- +import com.l2jserver.gameserver.datatables.FencesTable;
- +import com.l2jserver.gameserver.idfactory.IdFactory;
- +import com.l2jserver.gameserver.model.L2Object;
- +import com.l2jserver.gameserver.model.Location;
- +import com.l2jserver.gameserver.model.actor.L2Character;
- +import com.l2jserver.gameserver.network.serverpackets.ExColosseumFenceInfo;
- +
- +/**
- + * @author Nik
- + */
- +public final class L2FenceInstance extends L2Object
- +{
- + public static final int HIDDEN = 0;
- + public static final int UNCLOSED = 1;
- + public static final int CLOSED = 2;
- +
- + private int _state;
- + private final int _width;
- + private final int _length;
- + private int _height;
- + private Rectangle _shape;
- + private boolean _storedToDB = false;
- +
- + public L2FenceInstance(int objectId, int state, int x, int y, int z, int width, int length, int height)
- + {
- + super(objectId);
- + setInstanceType(InstanceType.L2FenceInstance);
- + initPosition();
- + setXYZ(x, y, z);
- +
- + if ((state < 0) || (state > 2))
- + {
- + state = 0;
- + }
- + _state = state;
- + _width = width;
- + _length = length;
- + _height = height;
- + _shape = new Rectangle(getX(), getY(), _width, _length);
- + }
- +
- + public L2FenceInstance(int x, int y, int z, int width, int length)
- + {
- + super(IdFactory.getInstance().getNextId());
- + setInstanceType(InstanceType.L2FenceInstance);
- + initPosition();
- + setXYZ(x, y, z);
- + _state = CLOSED; // Its a better default than HIDDEN.
- + _width = width;
- + _length = length;
- + _height = 50;
- + _shape = new Rectangle(getX(), getY(), _width, _length);
- + }
- +
- + public boolean isLocInside(Location loc)
- + {
- + boolean isInsideZ = (loc.getZ() >= getZ()) && (loc.getZ() <= (getZ() + _height));
- + return _shape.contains(loc.getX(), loc.getY()) && isInsideZ && (getInstanceId() == loc.getInstanceId());
- + }
- +
- + public boolean isLocOutside(Location loc)
- + {
- + return !isLocInside(loc);
- + }
- +
- + /**
- + * @param x1 - obj1's X loc
- + * @param y1 - obj1's Y loc
- + * @param x2 - obj2's X loc
- + * @param y2 - obj2's Y loc
- + * @return can obj1 see obj2 through this fence (their LOS do not intersect the fence's bounds). <B>No Z</B> checks are done. <B>No Instance</B> checks are done.
- + */
- + public boolean canSee(int x1, int y1, int x2, int y2)
- + {
- + return !_shape.intersectsLine(x1, y1, x2, y2);
- + }
- +
- + /**
- + * @param loc1 - obj1's xyz & instanceId location
- + * @param loc2 - obj2's xyz & instanceId location
- + * @return can obj1 see obj2 through this fence (their LOS do not intersect the fence's bounds). <B>Z</B> checks are done. <B>Instance</B> checks are done.
- + */
- + public boolean canSee(Location loc1, Location loc2)
- + {
- + if ((getState() == CLOSED) && (loc1.getInstanceId() == loc2.getInstanceId()))
- + {
- + // Those Z checks are probably not 100% accurate, rework them if it must.
- + int higherZ = loc1.getZ() >= loc2.getZ() ? loc1.getZ() : loc2.getZ();
- + if ((higherZ >= getZ()) && (higherZ <= (getZ() + _height)))
- + {
- + return canSee(loc1.getX(), loc1.getY(), loc2.getX(), loc2.getY());
- + }
- + }
- +
- + return true;
- + }
- +
- + /**
- + * @param obj1
- + * @param obj2
- + * @return can obj1 see obj2 through this fence (their LOS do not intersect the fence's bounds). <B>Z</B> checks are done. <B>Instance</B> checks are done.
- + */
- + public boolean canSee(L2Object obj1, L2Object obj2)
- + {
- + if ((getState() == CLOSED) && (obj1.getInstanceId() == obj2.getInstanceId()))
- + {
- + // Those Z checks are probably not 100% accurate, rework them if it must.
- + int higherZ = obj1.getZ() >= obj2.getZ() ? obj1.getZ() : obj2.getZ();
- + if ((higherZ >= getZ()) && (higherZ <= (getZ() + _height)))
- + {
- + return canSee(obj1.getX(), obj1.getY(), obj2.getX(), obj2.getY());
- + }
- + }
- +
- + return true;
- + }
- +
- + @Override
- + public void sendInfo(L2PcInstance activeChar)
- + {
- + activeChar.sendPacket(new ExColosseumFenceInfo(this));
- + }
- +
- + @Override
- + public boolean isAutoAttackable(L2Character attacker)
- + {
- + return false;
- + }
- +
- + /**
- + * Also removes the fence from FencesTable, but its not removed from DB
- + */
- + @Override
- + public void decayMe()
- + {
- + FencesTable.getInstance().removeFence(getObjectId());
- + }
- +
- + @Override
- + public void onSpawn()
- + {
- + // Maybe someone for some reason decided to respawn this fence on different XYZ. RESHAPE!!!
- + _shape = new Rectangle(getX(), getY(), _width, _length);
- + FencesTable.getInstance().addFence(this);
- + }
- +
- + /**
- + * @param height - how high the fence is :D :D Although the client height of the fence is ~50, you can set it to as much as you want. <BR>
- + * Setting it to lower might result in some strange LOS checks. Setting it too high might result in weird LOS checks in all the floors of TOI :P
- + */
- + public void setHeight(int height)
- + {
- + _height = height;
- + }
- +
- + public void setState(int state)
- + {
- + if ((state < 0) || (state > 2))
- + {
- + state = 0;
- + }
- +
- + _state = state;
- + }
- +
- + public int getState()
- + {
- + return _state;
- + }
- +
- + public int getWidth()
- + {
- + return _width;
- + }
- +
- + public int getLength()
- + {
- + return _length;
- + }
- +
- + public int getHeight()
- + {
- + return _height;
- + }
- +
- + public void setStoredToDB(boolean storedToDB)
- + {
- + _storedToDB = storedToDB;
- + }
- +
- + public boolean isStoredToDB()
- + {
- + return _storedToDB;
- + }
- +}
- \ No newline at end of file
- Index: com/l2jserver/gameserver/GeoEngine.java
- ===================================================================
- --- com/l2jserver/gameserver/GeoEngine.java (revision 5685)
- +++ com/l2jserver/gameserver/GeoEngine.java (working copy)
- @@ -34,6 +34,7 @@
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.datatables.DoorTable;
- +import com.l2jserver.gameserver.datatables.FencesTable;
- import com.l2jserver.gameserver.model.L2Object;
- import com.l2jserver.gameserver.model.L2Spawn;
- import com.l2jserver.gameserver.model.L2World;
- @@ -101,6 +102,12 @@
- {
- return false;
- }
- +
- + if (FencesTable.getInstance().checkIfBetweenFences(new Location(cha), new Location(target.getX(), target.getY(), target.getZ(), 0, cha.getInstanceId())))
- + {
- + return false;
- + }
- +
- if (cha.getZ() >= target.getZ())
- {
- return canSeeTarget(cha.getX(), cha.getY(), cha.getZ(), target.getX(), target.getY(), target.getZ());
- @@ -138,6 +145,10 @@
- {
- return true; // door coordinates are hinge coords..
- }
- + if (FencesTable.getInstance().checkIfBetweenFences(new Location(cha), new Location(target)))
- + {
- + return false;
- + }
- if (target instanceof L2DefenderInstance)
- {
- z2 += 30; // well they don't move closer to balcony fence at the moment :(
- @@ -189,6 +200,10 @@
- {
- return startpoint;
- }
- + if (FencesTable.getInstance().checkIfBetweenFences(new Location(x, y, z, 0, instanceId), new Location(tx, ty, tz, 0, instanceId)))
- + {
- + return startpoint;
- + }
- Location destiny = new Location(tx, ty, tz);
- return moveCheck(startpoint, destiny, (x - L2World.MAP_MIN_X) >> 4, (y - L2World.MAP_MIN_Y) >> 4, z, (tx - L2World.MAP_MIN_X) >> 4, (ty - L2World.MAP_MIN_Y) >> 4, tz);
- Index: com/l2jserver/gameserver/idfactory/IdFactory.java
- ===================================================================
- --- com/l2jserver/gameserver/idfactory/IdFactory.java (revision 5685)
- +++ com/l2jserver/gameserver/idfactory/IdFactory.java (working copy)
- @@ -102,7 +102,8 @@
- "SELECT ally_id FROM clan_data WHERE ally_id >= ? AND ally_id < ?",
- "SELECT leader_id FROM clan_data WHERE leader_id >= ? AND leader_id < ?",
- "SELECT item_obj_id FROM pets WHERE item_obj_id >= ? AND item_obj_id < ?",
- - "SELECT object_id FROM itemsonground WHERE object_id >= ? AND object_id < ?"
- + "SELECT object_id FROM itemsonground WHERE object_id >= ? AND object_id < ?",
- + "SELECT object_id FROM fences WHERE object_id >= ? AND object_id < ?"
- };
- private static final String[] TIMESTAMPS_CLEAN =
- @@ -400,6 +401,20 @@
- temp.add(rs.getInt(1));
- }
- }
- +
- + try (ResultSet rs = s.executeQuery("SELECT COUNT(*) FROM fences"))
- + {
- + rs.next();
- + temp.ensureCapacity(temp.size() + rs.getInt(1));
- + }
- +
- + try (ResultSet rs = s.executeQuery("SELECT object_id FROM fences"))
- + {
- + while (rs.next())
- + {
- + temp.add(rs.getInt(1));
- + }
- + }
- temp.sort();
- return temp.toArray();
- }
- Index: com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java
- ===================================================================
- --- com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java (revision 0)
- +++ com/l2jserver/gameserver/network/serverpackets/ExColosseumFenceInfo.java (revision 0)
- @@ -0,0 +1,57 @@
- +/*
- + * 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.l2jserver.gameserver.network.serverpackets;
- +
- +import com.l2jserver.gameserver.model.actor.instance.L2FenceInstance;
- +
- +/**
- + * 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>
- + */
- +public class ExColosseumFenceInfo extends L2GameServerPacket
- +{
- + private final L2FenceInstance _fence;
- +
- + public ExColosseumFenceInfo(L2FenceInstance fence)
- + {
- + _fence = fence;
- + }
- +
- + /**
- + * @see com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket#writeImpl()
- + */
- + @Override
- + protected void writeImpl()
- + {
- + writeC(0xfe);
- + writeH(0x0003);
- +
- + writeD(_fence.getObjectId());
- + writeD(_fence.getState());
- + writeD(_fence.getX());
- + writeD(_fence.getY());
- + writeD(_fence.getZ());
- + writeD(_fence.getWidth());
- + writeD(_fence.getLength());
- + }
- +}
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement