/* * 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 2, 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * http://www.gnu.org/copyleft/gpl.html */ package net.sf.l2j.gameserver.model; import java.util.StringTokenizer; import java.util.logging.Logger; import net.sf.l2j.gameserver.DoorTable; import net.sf.l2j.gameserver.serverpackets.ActionFailed; import net.sf.l2j.gameserver.serverpackets.MyTargetSelected; import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.templates.L2NpcTemplate; /** * This class ... * * @version $Revision$ $Date$ */ public class L2DoormenInstance extends L2FolkInstance { private static Logger _log = Logger.getLogger(L2SiegeNpcInstance.class.getName()); private L2Castle _Castle; /** * @param template */ public L2DoormenInstance(int objectID, L2NpcTemplate template) { super(objectID, template); } public final L2Castle getCastle() { if (_Castle == null) _Castle = L2Castle.getCastle(getX(), getY()); return _Castle; } public void onBypassFeedback(L2PcInstance player, String command) { super.onBypassFeedback(player, command); if (command.startsWith("open_doors")) { DoorTable doorTable = DoorTable.getInstance(); StringTokenizer st = new StringTokenizer(command.substring(11), ", "); st.nextToken(); // Bypass first value since its castleid/hallid if (getCastle().getCastleId() > 0) { while (st.hasMoreTokens()) { getCastle().openDoor(Integer.parseInt(st.nextToken()), player); } } //else if (getClanHall().getHallId() > 0) //{ // while (st.hasMoreTokens()) // { // getClanHall().openDoor(Integer.parseInt(st.nextToken()), player); // } //} } else if (command.startsWith("close_doors")) { DoorTable doorTable = DoorTable.getInstance(); StringTokenizer st = new StringTokenizer(command.substring(11), ", "); st.nextToken(); // Bypass first value since its castleid/hallid L2Clan playersClan = player.getClan(); if (getCastle().getCastleId() > 0) { while (st.hasMoreTokens()) { getCastle().closeDoor(Integer.parseInt(st.nextToken()), player); } } //else if (getClanHall().getHallId() > 0) //{ // while (st.hasMoreTokens()) // { // getClanHall().closeDoor(Integer.parseInt(st.nextToken()), player); // } } } } /** * this is called when a player interacts with this NPC * @param player */ public void onAction(L2PcInstance player) { player.sendPacket(new ActionFailed()); if (player.getTarget()==this) { showMessageWindow(player,1); } player.setTarget(this); MyTargetSelected my = new MyTargetSelected(getObjectId(), -15); player.sendPacket(my); ActionFailed af = new ActionFailed(); player.sendPacket(af); } public void showMessageWindow(L2PcInstance player, int val) { L2Clan playersClan = player.getClan(); String filename = "data/html/doormen/" + getTemplate().npcId + "-no.htm"; if (player.getClan() != null) { if (getCastle().getCastleId() > 0) { if (getCastle().getSiege().getIsInProgress()) filename = "data/html/doormen/" + getTemplate().npcId + "-busy.htm"; // Owner message window else if (playersClan.getHasCastle() == getCastle().getCastleId()) // Clan owns castle filename = "data/html/doormen/" + getTemplate().npcId + ".htm"; // Owner message window } // Prepare doormen for clan hall //else if (getClanHall().getHallId() > 0) //{ // if (playersClan.getHasHideout() == getClanHall().getHallId()) // Clan owns hall // filename = "data/html/doormen/" + getTemplate().npcId + ".htm"; // Owner message window //} } NpcHtmlMessage html = new NpcHtmlMessage(1); html.setFile(filename); html.replace("%objectId%",String.valueOf(getObjectId())); player.sendPacket(html); player.sendPacket( new ActionFailed() ); } }