Addition of fences support.

Contributed by Sahar.
This commit is contained in:
MobiusDev
2018-05-08 16:56:05 +00:00
parent e05d0a1a14
commit 138dd34c73
100 changed files with 6857 additions and 18 deletions

View File

@@ -628,6 +628,13 @@ INSERT IGNORE INTO `admin_command_access_rights` VALUES
('admin_zone_check','2'),
('admin_zone_reload','2'),
-- Section: Fences
('admin_addfence','1'),
('admin_setfencestate','1'),
('admin_removefence','1'),
('admin_listfence','1'),
('admin_gofence','1'),
-- Section: AIO
('admin_setaio','2'),
('admin_removeaio','2');

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xsd/FenceData.xsd">
<fence name="demo" x="-114552" y="-251256" z="-2992" width="100" length="100" height="3" state="CLOSED" />
</list>

View File

@@ -0,0 +1,25 @@
<html>
<head>
<title>Fence List</title>
</head>
<body>
<table width="100%">
<tr>
<td width=45>
<button value="Main" action="bypass -h admin_admin" width=45 height=21 back="sek.cbui94" fore="sek.cbui92">
</td>
<td width=180>
<center><font color="LEVEL">Fence List</font></center>
</td>
<td width=45>
<button value="Back" action="bypass -h admin_current_player" width=45 height=21 back="sek.cbui94" fore="sek.cbui92">
</td>
</tr>
</table>
<br>
<table width="100%">
%fences%
</table>
<br>%pages%<br>
</body>
</html>

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="fence">
<xs:attribute type="xs:string" name="name" />
<xs:attribute type="xs:integer" name="x" use="required" />
<xs:attribute type="xs:integer" name="y" use="required" />
<xs:attribute type="xs:integer" name="z" use="required" />
<xs:attribute type="xs:positiveInteger" name="width" use="required" />
<xs:attribute type="xs:positiveInteger" name="length" use="required" />
<xs:attribute name="height" use="required">
<xs:simpleType>
<xs:restriction base="xs:positiveInteger">
<xs:minInclusive value="1" />
<xs:maxInclusive value="3" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="state" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="HIDDEN" />
<xs:enumeration value="OPENED" />
<xs:enumeration value="CLOSED" />
<xs:enumeration value="CLOSED_HIDDEN" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element name="fence" maxOccurs="unbounded" type="fence" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -74,6 +74,7 @@ import com.l2jmobius.gameserver.datatables.sql.SpawnTable;
import com.l2jmobius.gameserver.datatables.sql.TeleportLocationTable;
import com.l2jmobius.gameserver.datatables.xml.AugmentationData;
import com.l2jmobius.gameserver.datatables.xml.ExperienceData;
import com.l2jmobius.gameserver.datatables.xml.FenceData;
import com.l2jmobius.gameserver.datatables.xml.ItemTable;
import com.l2jmobius.gameserver.datatables.xml.ZoneData;
import com.l2jmobius.gameserver.geodata.GeoData;
@@ -385,6 +386,7 @@ public class GameServer
Util.printSection("Doors");
DoorTable.getInstance().parseData();
FenceData.getInstance();
Util.printSection("Four Sepulchers");
FourSepulchersManager.getInstance();

View File

@@ -0,0 +1,260 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.datatables.xml;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import com.l2jmobius.Config;
import com.l2jmobius.commons.util.Point3D;
import com.l2jmobius.gameserver.enums.FenceState;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.L2WorldRegion;
import com.l2jmobius.gameserver.model.actor.instance.L2FenceInstance;
/**
* @author HoridoJoho / FBIagent
*/
public final class FenceData
{
private static final Logger LOGGER = Logger.getLogger(FenceData.class.getSimpleName());
private static final int MAX_Z_DIFF = 100;
private final Map<L2WorldRegion, List<L2FenceInstance>> _regions = new ConcurrentHashMap<>();
private final Map<Integer, L2FenceInstance> _fences = new ConcurrentHashMap<>();
protected FenceData()
{
load();
}
public void load()
{
final File xml = new File(Config.DATAPACK_ROOT, "data/FenceData.xml");
if (!xml.exists())
{
LOGGER.warning(getClass().getSimpleName() + ": FenceData.xml not found!");
return;
}
Document doc = null;
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setIgnoringComments(true);
try
{
doc = factory.newDocumentBuilder().parse(xml);
}
catch (Exception e)
{
LOGGER.warning("Could not parse FenceData.xml: " + e.getMessage());
return;
}
if (!_fences.isEmpty())
{
// Remove old fences when reloading
_fences.values().forEach(this::removeFence);
}
final Node table = doc.getFirstChild();
for (Node fence = table.getFirstChild(); fence != null; fence = fence.getNextSibling())
{
if (fence.getNodeName().equals("fence"))
{
spawnFence(fence);
}
}
LOGGER.info("Loaded " + _fences.size() + " Fences.");
}
public int getLoadedElementsCount()
{
return _fences.size();
}
private void spawnFence(Node fenceNode)
{
final NamedNodeMap attrs = fenceNode.getAttributes();
final String name = attrs.getNamedItem("name").getNodeValue();
final int x = Integer.parseInt(attrs.getNamedItem("x").getNodeValue());
final int y = Integer.parseInt(attrs.getNamedItem("y").getNodeValue());
final int z = Integer.parseInt(attrs.getNamedItem("z").getNodeValue());
final int width = Integer.parseInt(attrs.getNamedItem("width").getNodeValue());
final int length = Integer.parseInt(attrs.getNamedItem("length").getNodeValue());
final int height = Integer.parseInt(attrs.getNamedItem("height").getNodeValue());
final FenceState state = FenceState.valueOf(attrs.getNamedItem("state").getNodeValue());
spawnFence(x, y, z, name, width, length, height, state);
}
public L2FenceInstance spawnFence(int x, int y, int z, final String name, int width, int length, int height, FenceState state)
{
final L2FenceInstance fence = new L2FenceInstance(x, y, name, width, length, height, state);
fence.spawnMe(x, y, z);
addFence(fence);
return fence;
}
private void addFence(L2FenceInstance fence)
{
final Point3D point = new Point3D(fence.getX(), fence.getY(), fence.getZ());
_fences.put(fence.getObjectId(), fence);
_regions.computeIfAbsent(L2World.getInstance().getRegion(point), key -> new ArrayList<>()).add(fence);
}
public void removeFence(L2FenceInstance fence)
{
_fences.remove(fence.getObjectId());
final Point3D point = new Point3D(fence.getX(), fence.getY(), fence.getZ());
final List<L2FenceInstance> fencesInRegion = _regions.get(L2World.getInstance().getRegion(point));
if (fencesInRegion != null)
{
fencesInRegion.remove(fence);
}
}
public Map<Integer, L2FenceInstance> getFences()
{
return _fences;
}
public L2FenceInstance getFence(int objectId)
{
return _fences.get(objectId);
}
public boolean checkIfFenceBetween(int x, int y, int z, int tx, int ty, int tz)
{
final Predicate<L2FenceInstance> filter = fence ->
{
// Check if fence is geodata enabled.
if (!fence.getState().isGeodataEnabled())
{
return false;
}
final int xMin = fence.getXMin();
final int xMax = fence.getXMax();
final int yMin = fence.getYMin();
final int yMax = fence.getYMax();
if ((x < xMin) && (tx < xMin))
{
return false;
}
if ((x > xMax) && (tx > xMax))
{
return false;
}
if ((y < yMin) && (ty < yMin))
{
return false;
}
if ((y > yMax) && (ty > yMax))
{
return false;
}
if ((x > xMin) && (tx > xMin) && (x < xMax) && (tx < xMax))
{
if ((y > yMin) && (ty > yMin) && (y < yMax) && (ty < yMax))
{
return false;
}
}
if (crossLinePart(xMin, yMin, xMax, yMin, x, y, tx, ty, xMin, yMin, xMax, yMax) || crossLinePart(xMax, yMin, xMax, yMax, x, y, tx, ty, xMin, yMin, xMax, yMax) || crossLinePart(xMax, yMax, xMin, yMax, x, y, tx, ty, xMin, yMin, xMax, yMax) || crossLinePart(xMin, yMax, xMin, yMin, x, y, tx, ty, xMin, yMin, xMax, yMax))
{
if ((z > (fence.getZ() - MAX_Z_DIFF)) && (z < (fence.getZ() + MAX_Z_DIFF)))
{
return true;
}
}
return false;
};
final Point3D point = new Point3D(x, y, z);
return _regions.getOrDefault(L2World.getInstance().getRegion(point), Collections.emptyList()).stream().anyMatch(filter);
}
private boolean crossLinePart(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double xMin, double yMin, double xMax, double yMax)
{
final double[] result = intersection(x1, y1, x2, y2, x3, y3, x4, y4);
if (result == null)
{
return false;
}
final double xCross = result[0];
final double yCross = result[1];
if ((xCross <= xMax) && (xCross >= xMin))
{
return true;
}
if ((yCross <= yMax) && (yCross >= yMin))
{
return true;
}
return false;
}
private double[] intersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
{
final double d = ((x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4));
if (d == 0)
{
return null;
}
final double xi = (((x3 - x4) * ((x1 * y2) - (y1 * x2))) - ((x1 - x2) * ((x3 * y4) - (y3 * x4)))) / d;
final double yi = (((y3 - y4) * ((x1 * y2) - (y1 * x2))) - ((y1 - y2) * ((x3 * y4) - (y3 * x4)))) / d;
return new double[]
{
xi,
yi
};
}
public static FenceData getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final FenceData INSTANCE = new FenceData();
}
}

View File

@@ -0,0 +1,45 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.enums;
/**
* @author Nik64
*/
public enum FenceState
{
HIDDEN(0),
OPENED(1),
CLOSED(2),
CLOSED_HIDDEN(0);
final int _clientId;
private FenceState(int clientId)
{
_clientId = clientId;
}
public int getClientId()
{
return _clientId;
}
public boolean isGeodataEnabled()
{
return (this == CLOSED_HIDDEN) || (this == CLOSED);
}
}

View File

@@ -22,6 +22,7 @@ import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.gameserver.datatables.csv.DoorTable;
import com.l2jmobius.gameserver.datatables.xml.FenceData;
import com.l2jmobius.gameserver.geodata.geodriver.Cell;
import com.l2jmobius.gameserver.geodata.geodriver.GeoDriver;
import com.l2jmobius.gameserver.model.L2Object;
@@ -413,6 +414,10 @@ public class GeoData
{
return new Location(x, y, getHeight(x, y, z));
}
if (FenceData.getInstance().checkIfFenceBetween(x, y, z, tx, ty, tz))
{
return new Location(x, y, getHeight(x, y, z));
}
final LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY);
// first point is guaranteed to be available
@@ -474,6 +479,10 @@ public class GeoData
{
return false;
}
if (FenceData.getInstance().checkIfFenceBetween(fromX, fromY, fromZ, toX, toY, toZ))
{
return false;
}
final LinePointIterator pointIter = new LinePointIterator(geoX, geoY, tGeoX, tGeoY);
// first point is guaranteed to be available

View File

@@ -44,6 +44,7 @@ import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminEffects;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminEnchant;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminEventEngine;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminExpSp;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminFence;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminFightCalculator;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminFortSiege;
import com.l2jmobius.gameserver.handler.admincommandhandlers.AdminGeodata;
@@ -135,6 +136,7 @@ public class AdminCommandHandler
registerAdminCommandHandler(new AdminScript());
registerAdminCommandHandler(new AdminExpSp());
registerAdminCommandHandler(new AdminEventEngine());
registerAdminCommandHandler(new AdminFence());
registerAdminCommandHandler(new AdminGmChat());
registerAdminCommandHandler(new AdminGmSpeed());
registerAdminCommandHandler(new AdminHide());

View File

@@ -0,0 +1,230 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.handler.admincommandhandlers;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import com.l2jmobius.gameserver.datatables.xml.FenceData;
import com.l2jmobius.gameserver.enums.FenceState;
import com.l2jmobius.gameserver.handler.IAdminCommandHandler;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.PageResult;
import com.l2jmobius.gameserver.model.actor.instance.L2FenceInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jmobius.gameserver.util.BuilderUtil;
import com.l2jmobius.gameserver.util.HtmlUtil;
/**
* @author Sahar, Nik64
*/
public class AdminFence implements IAdminCommandHandler
{
private static final String[] ADMIN_COMMANDS =
{
"admin_addfence",
"admin_setfencestate",
"admin_removefence",
"admin_listfence",
"admin_gofence"
};
@Override
public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
final StringTokenizer st = new StringTokenizer(command, " ");
final String cmd = st.nextToken();
switch (cmd)
{
case "admin_addfence":
{
try
{
final int width = Integer.parseInt(st.nextToken());
final int length = Integer.parseInt(st.nextToken());
final int height = Integer.parseInt(st.nextToken());
if ((width < 1) || (length < 1))
{
BuilderUtil.sendSysMessage(activeChar, "Width and length values must be positive numbers.");
return false;
}
if ((height < 1) || (height > 3))
{
BuilderUtil.sendSysMessage(activeChar, "The range for height can only be 1-3.");
return false;
}
FenceData.getInstance().spawnFence(activeChar.getX(), activeChar.getY(), activeChar.getZ(), null, width, length, height, FenceState.CLOSED);
BuilderUtil.sendSysMessage(activeChar, "Fence added succesfully.");
}
catch (NoSuchElementException | NumberFormatException e)
{
BuilderUtil.sendSysMessage(activeChar, "Format must be: //addfence <width> <length> <height>");
}
break;
}
case "admin_setfencestate":
{
try
{
final int objId = Integer.parseInt(st.nextToken());
final int fenceTypeOrdinal = Integer.parseInt(st.nextToken());
if ((fenceTypeOrdinal < 0) || (fenceTypeOrdinal >= FenceState.values().length))
{
BuilderUtil.sendSysMessage(activeChar, "Specified FenceType is out of range. Only 0-" + (FenceState.values().length - 1) + " are permitted.");
}
else
{
final L2Object obj = L2World.getInstance().findObject(objId);
if (obj instanceof L2FenceInstance)
{
final L2FenceInstance fence = (L2FenceInstance) obj;
final FenceState state = FenceState.values()[fenceTypeOrdinal];
fence.setState(state);
BuilderUtil.sendSysMessage(activeChar, "Fence " + fence.getName() + "[" + fence.getObjectId() + "]'s state has been changed to " + state.toString());
}
else
{
BuilderUtil.sendSysMessage(activeChar, "Target is not a fence.");
}
}
}
catch (NoSuchElementException | NumberFormatException e)
{
BuilderUtil.sendSysMessage(activeChar, "Format mustr be: //setfencestate <fenceObjectId> <fenceState>");
}
break;
}
case "admin_removefence":
{
try
{
final int objId = Integer.parseInt(st.nextToken());
final L2Object obj = L2World.getInstance().findObject(objId);
if (obj instanceof L2FenceInstance)
{
((L2FenceInstance) obj).deleteMe();
BuilderUtil.sendSysMessage(activeChar, "Fence removed succesfully.");
}
else
{
BuilderUtil.sendSysMessage(activeChar, "Target is not a fence.");
}
}
catch (Exception e)
{
BuilderUtil.sendSysMessage(activeChar, "Invalid object ID or target was not found.");
}
sendHtml(activeChar, 0);
break;
}
case "admin_listfence":
{
int page = 0;
if (st.hasMoreTokens())
{
page = Integer.parseInt(st.nextToken());
}
sendHtml(activeChar, page);
break;
}
case "admin_gofence":
{
try
{
final int objId = Integer.parseInt(st.nextToken());
final L2Object obj = L2World.getInstance().findObject(objId);
if (obj != null)
{
activeChar.teleToLocation(obj.getX(), obj.getY(), obj.getZ());
}
}
catch (Exception e)
{
BuilderUtil.sendSysMessage(activeChar, "Invalid object ID or target was not found.");
}
break;
}
}
return true;
}
@Override
public String[] getAdminCommandList()
{
return ADMIN_COMMANDS;
}
private static void sendHtml(L2PcInstance activeChar, int page)
{
final PageResult result = HtmlUtil.createPage(FenceData.getInstance().getFences().values(), page, 10, currentPage ->
{
return "<td align=center><button action=\"bypass -h admin_listfence " + currentPage + "\" value=\"" + (currentPage + 1) + "\" width=35 height=20 back=\"sek.cbui94\" fore=\"sek.cbui92\">></td>";
}, fence ->
{
final StringBuilder sb = new StringBuilder();
sb.append("<tr><td>");
sb.append(fence.getName());
sb.append("</td><td>");
sb.append("<button value=\"Go\" action=\"bypass -h admin_gofence ");
sb.append(fence.getObjectId());
sb.append("\" width=30 height=21 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
sb.append("</td><td>");
sb.append("<button value=\"Hide\" action=\"bypass -h admin_setfencestate ");
sb.append(fence.getObjectId());
sb.append(" 0");
sb.append("\" width=30 height=21 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
sb.append("</td><td>");
sb.append("<button value=\"Off\" action=\"bypass -h admin_setfencestate ");
sb.append(fence.getObjectId());
sb.append(" 1");
sb.append("\" width=30 height=21 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
sb.append("</td><td>");
sb.append("<button value=\"On\" action=\"bypass -h admin_setfencestate ");
sb.append(fence.getObjectId());
sb.append(" 2");
sb.append("\" width=30 height=21 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
sb.append("</td><td>");
sb.append("<button value=\"X\" action=\"bypass -h admin_removefence ");
sb.append(fence.getObjectId());
sb.append("\" width=30 height=21 back=\"sek.cbui94\" fore=\"sek.cbui92\">");
sb.append("</td></tr>");
return sb.toString();
});
final NpcHtmlMessage html = new NpcHtmlMessage(0);
html.setFile("data/html/admin/fences.htm");
html.replace("%pages%", result.getPagerTemplate().toString());
html.replace("%announcements%", result.getBodyTemplate().toString());
if (result.getPages() > 0)
{
html.replace("%pages%", "<table width=280 cellspacing=0><tr>" + result.getPagerTemplate() + "</tr></table>");
}
else
{
html.replace("%pages%", "");
}
html.replace("%fences%", result.getBodyTemplate().toString());
activeChar.sendPacket(html);
}
}

View File

@@ -0,0 +1,49 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model;
/**
* @author UnAfraid
*/
public class PageResult
{
private final int _pages;
private final StringBuilder _pagerTemplate;
private final StringBuilder _bodyTemplate;
public PageResult(int pages, StringBuilder pagerTemplate, StringBuilder bodyTemplate)
{
_pages = pages;
_pagerTemplate = pagerTemplate;
_bodyTemplate = bodyTemplate;
}
public int getPages()
{
return _pages;
}
public StringBuilder getPagerTemplate()
{
return _pagerTemplate;
}
public StringBuilder getBodyTemplate()
{
return _bodyTemplate;
}
}

View File

@@ -0,0 +1,153 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.model.actor.instance;
import com.l2jmobius.gameserver.datatables.xml.FenceData;
import com.l2jmobius.gameserver.enums.FenceState;
import com.l2jmobius.gameserver.idfactory.IdFactory;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.network.serverpackets.DeleteObject;
import com.l2jmobius.gameserver.network.serverpackets.ExColosseumFenceInfo;
/**
* @author HoridoJoho / FBIagent
*/
public final class L2FenceInstance extends L2Object
{
private final int _xMin;
private final int _xMax;
private final int _yMin;
private final int _yMax;
private final int _width;
private final int _length;
private FenceState _state;
private int[] _heightFences;
public L2FenceInstance(int x, int y, String name, int width, int length, int height, FenceState state)
{
super(IdFactory.getInstance().getNextId());
_xMin = x - (width / 2);
_xMax = x + (width / 2);
_yMin = y - (length / 2);
_yMax = y + (length / 2);
super.setName(name);
_width = width;
_length = length;
_state = state;
if (height > 1)
{
_heightFences = new int[height - 1];
for (int i = 0; i < _heightFences.length; i++)
{
_heightFences[i] = IdFactory.getInstance().getNextId();
}
}
}
@Override
public boolean isAutoAttackable(L2Character attacker)
{
return false;
}
public void sendInfo(L2PcInstance activeChar)
{
activeChar.sendPacket(new ExColosseumFenceInfo(this));
if (_heightFences != null)
{
for (int objId : _heightFences)
{
activeChar.sendPacket(new ExColosseumFenceInfo(objId, getX(), getY(), getZ(), _width, _length, _state));
}
}
}
public boolean deleteMe()
{
if (_heightFences != null)
{
final DeleteObject[] deleteObjects = new DeleteObject[_heightFences.length];
for (int i = 0; i < _heightFences.length; i++)
{
deleteObjects[i] = new DeleteObject(_heightFences[i]);
}
getKnownList().getKnownObjects().values().stream().filter(L2PcInstance.class::isInstance).map(L2PcInstance.class::cast).forEach(player ->
{
for (DeleteObject deleteObject : deleteObjects)
{
player.sendPacket(deleteObject);
}
});
}
decayMe();
FenceData.getInstance().removeFence(this);
return false;
}
public FenceState getState()
{
return _state;
}
public void setState(FenceState type)
{
_state = type;
getKnownList().getKnownObjects().values().stream().filter(L2PcInstance.class::isInstance).map(L2PcInstance.class::cast).forEach(this::sendInfo);
}
public int getWidth()
{
return _width;
}
public int getLength()
{
return _length;
}
public int getXMin()
{
return _xMin;
}
public int getYMin()
{
return _yMin;
}
public int getXMax()
{
return _xMax;
}
public int getYMax()
{
return _yMax;
}
}

View File

@@ -23,6 +23,7 @@ import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Summon;
import com.l2jmobius.gameserver.model.actor.instance.L2BoatInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2DoorInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2FenceInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2NpcInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
@@ -135,6 +136,10 @@ public class PcKnownList extends PlayableKnownList
active_char.sendPacket(new DoorInfo((L2DoorInstance) object, false));
active_char.sendPacket(new DoorStatusUpdate((L2DoorInstance) object));
}
else if (object instanceof L2FenceInstance)
{
((L2FenceInstance) object).sendInfo(active_char);
}
else if (object instanceof L2BoatInstance)
{
if (!active_char.isInBoat())

View File

@@ -31,6 +31,11 @@ public class DeleteObject extends L2GameServerPacket
_objectId = obj.getObjectId();
}
public DeleteObject(int objId)
{
_objectId = objId;
}
@Override
protected final void writeImpl()
{

View File

@@ -0,0 +1,64 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.network.serverpackets;
import com.l2jmobius.gameserver.enums.FenceState;
import com.l2jmobius.gameserver.model.actor.instance.L2FenceInstance;
/**
* @author HoridoJoho / FBIagent
*/
public class ExColosseumFenceInfo extends L2GameServerPacket
{
private final int _objId;
private final int _x;
private final int _y;
private final int _z;
private final int _width;
private final int _length;
private final int _clientState;
public ExColosseumFenceInfo(L2FenceInstance fence)
{
this(fence.getObjectId(), fence.getX(), fence.getY(), fence.getZ(), fence.getWidth(), fence.getLength(), fence.getState());
}
public ExColosseumFenceInfo(int objId, double x, double y, double z, int width, int length, FenceState state)
{
_objId = objId;
_x = (int) x;
_y = (int) y;
_z = (int) z;
_width = width;
_length = length;
_clientState = state.getClientId();
}
@Override
protected void writeImpl()
{
writeC(0xFE);
writeH(0x09);
writeD(_objId);
writeD(_clientState);
writeD(_x);
writeD(_y);
writeD(_z);
writeD(_width);
writeD(_length);
}
}

View File

@@ -0,0 +1,90 @@
/*
* This file is part of the L2J Mobius project.
*
* 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.l2jmobius.gameserver.util;
import java.util.Arrays;
import java.util.Collection;
import java.util.function.Function;
import com.l2jmobius.gameserver.model.PageResult;
/**
* A class containing useful methods for constructing HTML
* @author NosBit
*/
public class HtmlUtil
{
public static <T> PageResult createPage(Collection<T> elements, int page, int elementsPerPage, Function<Integer, String> pagerFunction, Function<T, String> bodyFunction)
{
return createPage(elements, elements.size(), page, elementsPerPage, pagerFunction, bodyFunction);
}
public static <T> PageResult createPage(T[] elements, int page, int elementsPerPage, Function<Integer, String> pagerFunction, Function<T, String> bodyFunction)
{
return createPage(Arrays.asList(elements), elements.length, page, elementsPerPage, pagerFunction, bodyFunction);
}
public static <T> PageResult createPage(Iterable<T> elements, int size, int page, int elementsPerPage, Function<Integer, String> pagerFunction, Function<T, String> bodyFunction)
{
int pages = size / elementsPerPage;
if ((elementsPerPage * pages) < size)
{
pages++;
}
final StringBuilder pagerTemplate = new StringBuilder();
if (pages > 1)
{
int breakit = 0;
for (int i = 0; i < pages; i++)
{
pagerTemplate.append(pagerFunction.apply(i));
breakit++;
if (breakit > 5)
{
pagerTemplate.append("</tr><tr>");
breakit = 0;
}
}
}
if (page >= pages)
{
page = pages - 1;
}
final int start = page > 0 ? elementsPerPage * page : 0;
final StringBuilder sb = new StringBuilder();
int i = 0;
for (T element : elements)
{
if (i++ < start)
{
continue;
}
sb.append(bodyFunction.apply(element));
if (i >= (elementsPerPage + start))
{
break;
}
}
return new PageResult(pages, pagerTemplate, sb);
}
}