/* * 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 java.util.logging.Logger; import net.sf.l2j.Config; import net.sf.l2j.gameserver.SkillTable; import net.sf.l2j.gameserver.SkillTreeTable; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; import net.sf.l2j.gameserver.model.GMAudit; import net.sf.l2j.gameserver.model.L2Object; import net.sf.l2j.gameserver.model.L2Skill; import net.sf.l2j.gameserver.model.L2SkillLearn; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.serverpackets.ActionFailed; import net.sf.l2j.gameserver.serverpackets.MagicSkillUser; import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.serverpackets.SystemMessage; /** * This class handles following admin commands: * - show_skills * - remove_skills * - skill_list * - skill_index * - add_skill * - remove_skill * - get_skills * - reset_skills * - give_all_skills * * @version $Revision: 1.2.4.7 $ $Date: 2005/04/11 10:06:02 $ */ public class AdminSkill implements IAdminCommandHandler { private static Logger _log = Logger.getLogger(AdminSkill.class.getName()); private static String[] _adminCommands = { "admin_show_skills", "admin_remove_skills", "admin_skill_list", "admin_skill_index", "admin_add_skill", "admin_remove_skill", "admin_get_skills", "admin_reset_skills", "admin_give_all_skills" }; private static final int REQUIRED_LEVEL = Config.GM_CHAR_EDIT; private static final int REQUIRED_LEVEL2 = Config.GM_CHAR_EDIT_OTHER; private static L2Skill[] adminSkills; public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (!Config.ALT_PRIVILEGES_ADMIN) if (!(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false; String target = (activeChar.getTarget() != null?activeChar.getTarget().getName():"no-target"); GMAudit.auditGMAction(activeChar.getName(), command, target, ""); if (command.equals("admin_show_skills")) { showSkillsPage(activeChar); } else if (command.startsWith("admin_remove_skills")) { try { String val = command.substring(20); removeSkillsPage(activeChar, Integer.parseInt(val)); } catch (StringIndexOutOfBoundsException e) { } } else if (command.startsWith("admin_skill_list")) { AdminHelpPage.showHelpPage(activeChar, "skills.htm"); } else if (command.startsWith("admin_skill_index")) { try { String val = command.substring(18); AdminHelpPage.showHelpPage(activeChar, "skills/" + val + ".htm"); } catch (StringIndexOutOfBoundsException e) { } } else if (command.startsWith("admin_add_skill")) { try { String val = command.substring(15); if (activeChar == activeChar.getTarget() || activeChar.getAccessLevel() >= REQUIRED_LEVEL2) adminAddSkill(activeChar, val); } catch (StringIndexOutOfBoundsException e) { //Case of empty character name SystemMessage sm = new SystemMessage(614); sm.addString("Error while adding skill."); activeChar.sendPacket(sm); } } else if (command.startsWith("admin_remove_skill")) { try { String id = command.substring(19); int idval = Integer.parseInt(id); if (activeChar == activeChar.getTarget() || activeChar.getAccessLevel() >= REQUIRED_LEVEL2) adminRemoveSkill(activeChar, idval); } catch (StringIndexOutOfBoundsException e) { //Case of empty character name SystemMessage sm = new SystemMessage(614); sm.addString("Error while removing skill."); activeChar.sendPacket(sm); } } else if (command.equals("admin_get_skills")) { adminGetSkills(activeChar); } else if (command.equals("admin_reset_skills")) { if (activeChar == activeChar.getTarget() || activeChar.getAccessLevel() >= REQUIRED_LEVEL2) adminResetSkills(activeChar); } else if (command.equals("admin_give_all_skills")) { if (activeChar == activeChar.getTarget() || activeChar.getAccessLevel() >= REQUIRED_LEVEL2) adminGiveAllSkills(activeChar); } return true; } /** * This function will give all the skills that the gm target can have at its level * to the traget * @param activeChar: the gm char */ private void adminGiveAllSkills(L2PcInstance activeChar) { L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance)target; } else { SystemMessage sm = new SystemMessage(614); sm.addString("Incorrect target."); activeChar.sendPacket(sm); return; } boolean countUnlearnable = true; int unLearnable = 0; int skillCounter = 0; L2SkillLearn[] skills = SkillTreeTable.getInstance().getAvailableSkills(player, player.getClassId()); while(skills.length > unLearnable) { for (L2SkillLearn s : skills) { L2Skill sk = SkillTable.getInstance().getInfo(s.getId(), s.getLevel()); if (sk == null || !sk.getCanLearn(player.getClassId())) { if(countUnlearnable) unLearnable++; continue; } if(player.getSkillLevel(sk.getId()) == -1) { skillCounter++; } player.addSkill(sk); } countUnlearnable = false; skills = SkillTreeTable.getInstance().getAvailableSkills(player, player.getClassId()); } //Notify player and admin player.sendMessage("A GM gave you " + skillCounter + " skills."); activeChar.sendMessage("You gave " + skillCounter + " skills to " + player.getName()); } public String[] getAdminCommandList() { return _adminCommands; } private boolean checkLevel(int level) { return (level >= REQUIRED_LEVEL); } //ok private void removeSkillsPage(L2PcInstance activeChar, int page) { L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance)target; } else { SystemMessage sm = new SystemMessage(614); sm.addString("Incorrect target."); activeChar.sendPacket(sm); return; } L2Skill[] skills = player.getAllSkills(); int MaxSkillsPerPage = 10; int MaxPages = skills.length / MaxSkillsPerPage; if (skills.length > MaxSkillsPerPage * MaxPages) MaxPages++; if (page>MaxPages) page = MaxPages; int SkillsStart = MaxSkillsPerPage*page; int SkillsEnd = skills.length; if (SkillsEnd - SkillsStart > MaxSkillsPerPage) SkillsEnd = SkillsStart + MaxSkillsPerPage; NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Character Selection Menu
"); replyMSG.append("

"); replyMSG.append("
Editing " + player.getName() + "
"); replyMSG.append("
Lv: " + player.getLevel() + " " + player.getTemplate().className + "
"); replyMSG.append("
"); replyMSG.append("
Note: Dont forget that modifying players skills can
ruin the game...
"); replyMSG.append("
Click on the skill you wish to remove:
"); replyMSG.append("
"); for (int x=0; xPage " + pagenr + ""); } replyMSG.append("
"); replyMSG.append(""); for (int i = SkillsStart; i < SkillsEnd; i++) { replyMSG.append(""); } replyMSG.append("
Name:Level:Id:
"+skills[i].getName()+""+skills[i].getLevel()+""+skills[i].getId()+"
"); replyMSG.append("
"); replyMSG.append("Remove custom skill:"); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Id:
"); replyMSG.append("
"); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); } //ok private void showSkillsPage(L2PcInstance activeChar) { L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance)target; } else { SystemMessage sm = new SystemMessage(614); sm.addString("Incorrect target."); activeChar.sendPacket(sm); return; } NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Character Selection Menu
"); replyMSG.append("

"); replyMSG.append("
Editing " + player.getName() + "
"); replyMSG.append("
Lv: " + player.getLevel() + " " + player.getTemplate().className + "
"); replyMSG.append("
"); replyMSG.append("
Note: Dont forget that modifying players skills can
ruin the game...
"); replyMSG.append("
"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); } private void adminGetSkills(L2PcInstance activeChar) { L2Object target = activeChar.getTarget(); L2PcInstance player = null; if (target instanceof L2PcInstance) { player = (L2PcInstance)target; } else { SystemMessage sm = new SystemMessage(614); sm.addString("Incorrect target."); activeChar.sendPacket(sm); return; } if (player.getName().equals(activeChar.getName())) { SystemMessage sm = new SystemMessage(614); sm.addString("There is no point in doing it on your character..."); player.sendPacket(sm); } else { L2Skill[] skills = player.getAllSkills(); adminSkills = activeChar.getAllSkills(); for (int i=0;i