/*
* 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.handler.admincommandhandlers;
import java.util.StringTokenizer;
import net.sf.l2j.Config;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
//import net.sf.l2j.gameserver.instancemanager.CastleManager; // TODO REMOVE
import net.sf.l2j.gameserver.instancemanager.TownManager;
import net.sf.l2j.gameserver.model.entity.Raid;
import net.sf.l2j.gameserver.model.entity.Castle; // TODO REMOVE
import net.sf.l2j.gameserver.model.entity.Town;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.model.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.serverpackets.SystemMessage;
/**
* This class handles all siege commands:
* Todo: change the class name, and neaten it up
*
*
*/
public class AdminUndeadRaid implements IAdminCommandHandler {
//private static Logger _log = Logger.getLogger(AdminSeige.class.getName());
private static String[] _adminCommands = {"admin_raid",
"admin_add_raid_attacker", "admin_add_raid_defender", "admin_add_raid_guard", "admin_add_raid_undead",
"admin_clear_raid_list", "admin_endraid", "admin_startraid",
"admin_setcity"};
private static final int REQUIRED_LEVEL = Config.GM_NPC_EDIT;
// Function to Handle admin commands listed above.
// First decides if the user is an admin, if not returns them
// Next it will get the command and then another word after that which is suppost to be the town
// Also it will get any xtra variables at the end of the command
// If no town is specified it will call ShowTownSelectPage
// Function will then get the gm's targetted player.
// First command to check is admin_add_raid_attacker which adds a player to the raid party.
// Second command to check is admin_add_raid_defender which adds a player to the guard party.
// Third command to check is admin_add_raid_guard which adds a guard to the guard party.
// Fourth command to check is admin_add_raid_undead which adds undead to the undead party.
// Fifth command to check is admin_clear_raid_list which removes all players from defenders and attackers list.
// Sixth command to check is admin_endraid which ends the current raid of the town
public boolean useAdminCommand(String command, L2PcInstance activeChar)
{
if (!Config.ALT_PRIVILEGES_ADMIN) // checking access level
if (activeChar.getAccessLevel() < REQUIRED_LEVEL || !activeChar.isGM()) {return false;}
StringTokenizer st = new StringTokenizer(command, " ");
command = st.nextToken(); // Get actual command
// Get Town
Town town = null;
Castle castle = null; // TODO REMOVE
if (st.hasMoreTokens()) {
town = TownManager.getInstance().getTown(st.nextToken()); // gets the town to be raided
}
// Get extra values.
String val = "";
if (st.hasMoreTokens()) {
val = st.nextToken();
}
if (town == null || town.getTownId() < 0)
// No town speciified - call showTownsSelectpage and reissue the command
showTownSlectPage(activeChar);
else
{
// Gets targetted player
L2Object target = activeChar.getTarget();
L2PcInstance player = null;
if (target instanceof L2PcInstance)
player = (L2PcInstance)target;
// Checks if the command is add raid attacker
if (command.equalsIgnoreCase("admin_add__raid_attacker"))
{
if (player == null) // if player is null
activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT));
else // if player is legit
town.getTown().registerRaidAttacker(player,true); // add to database
}
// Checks if command is add raid defender.
else if (command.equalsIgnoreCase("admin_add_defender"))
{
if (player == null) // if player is null
activeChar.sendPacket(new SystemMessage(SystemMessage.TARGET_IS_INCORRECT));
else // if player is legit
town.getTown().registerRaidDefender(player,true); // add to database
}
// Checks if command is add a new guard.
else if (command.equalsIgnoreCase("admin_add_raid_guard"))
{
if (val != "") // checks the third variable to see if it has value of npcID
{
try
{
int npcId = Integer.parseInt(val); // parse value into integer.
town.getTown().getRaidGuardManager().addRaidGuard(activeChar, npcId);
}
catch (Exception e)
{
activeChar.sendMessage("Value entered for Npc Id wasn't an integer");
}
}
else
activeChar.sendMessage("Missing Npc Id");
}
// Checks if the command is to add a new undead
else if (command.equalsIgnoreCase("admin_add_raid_undead"))
{
if (val != "") // checks the third variable to see if it has value of npcID
{
try
{
int npcId = Integer.parseInt(val); // parse value into integer.
town.getTown().getRaidGuardManager().addRaidUndead(activeChar, npcId);
}
catch (Exception e)
{
activeChar.sendMessage("Value entered for Npc Id wasn't an integer");
}
}
else
activeChar.sendMessage("Missing Npc Id");
}
// Checks if the command is a clear raid list
else if (command.equalsIgnoreCase("admin_clear_raid_list"))
{
town.getTown().clearRaidPlayers();
}
else if (command.equalsIgnoreCase("admin_endraid"))
{
town.getTown().endRaid();
}
else if (command.equalsIgnoreCase("admin_setcity"))
{
if (val != "")
{
int variable = Integer.parseInt(val); // parse value into integer
if (variable == 90) // If want to set to undead
town.setOwner(90); // set to Undead
else
town.setOwner(5); // set to human
}
else
activeChar.sendMessage("Missing value");
}
else if (command.equalsIgnoreCase("admin_startraid"))
{
town.getTown().startRaid();
}
showRaidPage(activeChar, town.getName());
}
return true;
}
// Will display the menu if the character doesn't specify a town in the command.
// Basically it will just redo the command based on what town the admin chooses
// DONE - V1. Changed Castle Instances to Town Instances.
public void showTownSlectPage(L2PcInstance activeChar)
{
NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
StringBuffer replyMSG = new StringBuffer("<html><body>");
replyMSG.append("<table width=260><tr>");
replyMSG.append("<td width=40><button value=\"Main\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("<td width=180><center>Town Raid Menu</center></td>");
replyMSG.append("<td width=40><button value=\"Back\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("</tr></table>");
replyMSG.append("<center>");
replyMSG.append("<br><br>Please select a town:<br><br>");
for (Town town: TownManager.getInstance().getTowns())
{
if (town != null)
replyMSG.append("<a action=\"bypass -h admin_raid " + town.getName() + "\">" + town.getName() + "</a><br>");
}
replyMSG.append("</center>");
replyMSG.append("</body></html>");
adminReply.setHtml(replyMSG.toString());
activeChar.sendPacket(adminReply);
}
public void showRaidPage(L2PcInstance activeChar, String townName)
{
NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
StringBuffer replyMSG = new StringBuffer("<html><body>");
replyMSG.append("<table width=260><tr>");
replyMSG.append("<td width=40><button value=\"Main\" action=\"bypass -h admin_admin\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("<td width=180><center>Raid Menu</center></td>");
replyMSG.append("<td width=40><button value=\"Back\" action=\"bypass -h admin_raid\" width=40 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("</tr></table>");
replyMSG.append("<center>");
replyMSG.append("<br><br><br>Town: " + townName + "<br><br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td><button value=\"Add Attacker\" action=\"bypass -h admin_add_raid_attacker " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("<td><button value=\"Add Defender\" action=\"bypass -h admin_add_raid_defender " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("<td><button value=\"Clear List\" action=\"bypass -h admin_clear_raid_list " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("<br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td><button value=\"Start Raid\" action=\"bypass -h admin_startraid " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td>");
replyMSG.append("<td><button value=\"End Raid\" action=\"bypass -h admin_endraid " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("<br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td><button value=\"Give Town\" action=\"bypass -h admin_setcity " + townName + "\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("<br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td>NpcId: <edit var=\"value\" width=40>");
replyMSG.append("<td><button value=\"Add Guard\" action=\"bypass -h admin_add_raid_guard " + townName + " $value\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("<br>");
replyMSG.append("<table>");
replyMSG.append("<tr><td>NpcId: <edit var=\"value\" width=40>");
replyMSG.append("<td><button value=\"Add Undead\" action=\"bypass -h admin_add_raid_undead " + townName + " $value\" width=80 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></td></tr>");
replyMSG.append("</table>");
replyMSG.append("</center>");
replyMSG.append("</body></html>");
adminReply.setHtml(replyMSG.toString());
activeChar.sendPacket(adminReply);
}
public String[] getAdminCommandList() {
return _adminCommands;
}
}