123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- /*
- * 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 net.sf.l2j.gameserver.handler.admincommandhandlers;
- import java.util.StringTokenizer;
- import java.util.logging.Logger;
- import javolution.text.TextBuilder;
- import net.sf.l2j.Config;
- import net.sf.l2j.gameserver.datatables.SkillTable;
- import net.sf.l2j.gameserver.datatables.SkillTreeTable;
- import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
- 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.network.SystemMessageId;
- import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
- import net.sf.l2j.gameserver.network.serverpackets.PledgeSkillList;
- import net.sf.l2j.gameserver.network.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
- * - remove_all_skills
- * - add_clan_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 final String[] ADMIN_COMMANDS =
- {
- "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",
- "admin_remove_all_skills",
- "admin_add_clan_skill"
- };
-
- private static L2Skill[] adminSkills;
-
- public boolean useAdminCommand(String command, L2PcInstance activeChar)
- {
- if (command.equals("admin_show_skills"))
- showMainPage(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);
- adminAddSkill(activeChar, val);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //add_skill <skill_id> <level>");
- }
- }
- else if (command.startsWith("admin_remove_skill"))
- {
- try
- {
- String id = command.substring(19);
- int idval = Integer.parseInt(id);
- adminRemoveSkill(activeChar, idval);
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //remove_skill <skill_id>");
- }
- }
- else if (command.equals("admin_get_skills"))
- {
- adminGetSkills(activeChar);
- }
- else if (command.equals("admin_reset_skills"))
- {
- adminResetSkills(activeChar);
- }
- else if (command.equals("admin_give_all_skills"))
- {
- adminGiveAllSkills(activeChar);
- }
-
- else if (command.equals("admin_remove_all_skills"))
- {
- if (activeChar.getTarget() instanceof L2PcInstance)
- {
- L2PcInstance player = (L2PcInstance) activeChar.getTarget();
- for (L2Skill skill : player.getAllSkills())
- player.removeSkill(skill);
- activeChar.sendMessage("You removed all skills from " + player.getName());
- player.sendMessage("Admin removed all skills from you.");
- player.sendSkillList();
- }
- }
- else if (command.startsWith("admin_add_clan_skill"))
- {
- try
- {
- String[] val = command.split(" ");
- adminAddClanSkill(activeChar, Integer.parseInt(val[1]), Integer.parseInt(val[2]));
- }
- catch (Exception e)
- {
- activeChar.sendMessage("Usage: //add_clan_skill <skill_id> <level>");
- }
- }
- return true;
- }
-
- /**
- * This function will give all the skills that the target can learn at his/her level
- * @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
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- 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, true);
- }
- 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());
- player.sendSkillList();
- }
-
- public String[] getAdminCommandList()
- {
- return ADMIN_COMMANDS;
- }
-
- private void removeSkillsPage(L2PcInstance activeChar, int page)
- { //TODO: Externalize HTML
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_IS_INCORRECT));
- 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);
- TextBuilder replyMSG = new TextBuilder("<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=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
- replyMSG.append("<td width=180><center>Character Selection Menu</center></td>");
- replyMSG.append("<td width=40><button value=\"Back\" action=\"bypass -h admin_show_skills\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td>");
- replyMSG.append("</tr></table>");
- replyMSG.append("<br><br>");
- replyMSG.append("<center>Editing <font color=\"LEVEL\">" + player.getName() + "</font></center>");
- replyMSG.append("<br><table width=270><tr><td>Lv: " + player.getLevel() + " " + player.getTemplate().className + "</td></tr></table>");
- replyMSG.append("<br><table width=270><tr><td>Note: Dont forget that modifying players skills can</td></tr>");
- replyMSG.append("<tr><td>ruin the game...</td></tr></table>");
- replyMSG.append("<br><center>Click on the skill you wish to remove:</center>");
- replyMSG.append("<br>");
- String pages = "<center><table width=270><tr>";
- for (int x = 0; x < MaxPages; x++)
- {
- int pagenr = x + 1;
- pages += "<td><a action=\"bypass -h admin_remove_skills " + x + "\">Page " + pagenr + "</a></td>";
- }
- pages += "</tr></table></center>";
- replyMSG.append(pages);
- replyMSG.append("<br><table width=270>");
- replyMSG.append("<tr><td width=80>Name:</td><td width=60>Level:</td><td width=40>Id:</td></tr>");
- for (int i = SkillsStart; i < SkillsEnd; i++)
- replyMSG.append("<tr><td width=80><a action=\"bypass -h admin_remove_skill " + skills[i].getId() + "\">" + skills[i].getName() + "</a></td><td width=60>" + skills[i].getLevel() + "</td><td width=40>" + skills[i].getId()
- + "</td></tr>");
- replyMSG.append("</table>");
- replyMSG.append("<br><center><table>");
- replyMSG.append("Remove skill by ID :");
- replyMSG.append("<tr><td>Id: </td>");
- replyMSG.append("<td><edit var=\"id_to_remove\" width=110></td></tr>");
- replyMSG.append("</table></center>");
- replyMSG.append("<center><button value=\"Remove skill\" action=\"bypass -h admin_remove_skill $id_to_remove\" width=110 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
- replyMSG.append("<br><center><button value=\"Back\" action=\"bypass -h admin_current_player\" width=40 height=15 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></center>");
- replyMSG.append("</body></html>");
- adminReply.setHtml(replyMSG.toString());
- activeChar.sendPacket(adminReply);
- }
-
- private void showMainPage(L2PcInstance activeChar)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
- adminReply.setFile("data/html/admin/charskills.htm");
- adminReply.replace("%name%", player.getName());
- adminReply.replace("%level%", String.valueOf(player.getLevel()));
- adminReply.replace("%class%", player.getTemplate().className);
- activeChar.sendPacket(adminReply);
- }
-
- private void adminGetSkills(L2PcInstance activeChar)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- if (player.getName().equals(activeChar.getName()))
- player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_ON_YOURSELF));
- else
- {
- L2Skill[] skills = player.getAllSkills();
- adminSkills = activeChar.getAllSkills();
- for (int i = 0; i < adminSkills.length; i++)
- activeChar.removeSkill(adminSkills[i]);
- for (int i = 0; i < skills.length; i++)
- activeChar.addSkill(skills[i], true);
- activeChar.sendMessage("You now have all the skills of " + player.getName() + ".");
- activeChar.sendSkillList();
- }
- showMainPage(activeChar);
- }
-
- private void adminResetSkills(L2PcInstance activeChar)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- if (adminSkills == null)
- activeChar.sendMessage("You must get the skills of someone in order to do this.");
- else
- {
- L2Skill[] skills = player.getAllSkills();
- for (int i = 0; i < skills.length; i++)
- player.removeSkill(skills[i]);
- for (int i = 0; i < activeChar.getAllSkills().length; i++)
- player.addSkill(activeChar.getAllSkills()[i], true);
- for (int i = 0; i < skills.length; i++)
- activeChar.removeSkill(skills[i]);
- for (int i = 0; i < adminSkills.length; i++)
- activeChar.addSkill(adminSkills[i], true);
- player.sendMessage("[GM]" + activeChar.getName() + " updated your skills.");
- activeChar.sendMessage("You now have all your skills back.");
- adminSkills = null;
- activeChar.sendSkillList();
- }
- showMainPage(activeChar);
- }
-
- private void adminAddSkill(L2PcInstance activeChar, String val)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- showMainPage(activeChar);
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- StringTokenizer st = new StringTokenizer(val);
- if (st.countTokens() != 2)
- {
- showMainPage(activeChar);
- }
- else
- {
- L2Skill skill = null;
- try
- {
- String id = st.nextToken();
- String level = st.nextToken();
- int idval = Integer.parseInt(id);
- int levelval = Integer.parseInt(level);
- skill = SkillTable.getInstance().getInfo(idval, levelval);
- }
- catch (Exception e)
- {
- }
- if (skill != null)
- {
- String name = skill.getName();
- player.sendMessage("Admin gave you the skill " + name + ".");
- player.addSkill(skill, true);
- //Admin information
- activeChar.sendMessage("You gave the skill " + name + " to " + player.getName() + ".");
- if (Config.DEBUG)
- _log.fine("[GM]" + activeChar.getName() + " gave skill " + name + " to " + player.getName() + ".");
- activeChar.sendSkillList();
- }
- else
- activeChar.sendMessage("Error: there is no such skill.");
- showMainPage(activeChar); //Back to start
- }
- }
-
- private void adminRemoveSkill(L2PcInstance activeChar, int idval)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- L2Skill skill = SkillTable.getInstance().getInfo(idval, player.getSkillLevel(idval));
- if (skill != null)
- {
- String skillname = skill.getName();
- player.sendMessage("Admin removed the skill " + skillname + " from your skills list.");
- player.removeSkill(skill);
- //Admin information
- activeChar.sendMessage("You removed the skill " + skillname + " from " + player.getName() + ".");
- if (Config.DEBUG)
- _log.fine("[GM]" + activeChar.getName() + " removed skill " + skillname + " from " + player.getName() + ".");
- activeChar.sendSkillList();
- }
- else
- activeChar.sendMessage("Error: there is no such skill.");
- removeSkillsPage(activeChar, 0); //Back to previous page
- }
-
- private void adminAddClanSkill(L2PcInstance activeChar, int id, int level)
- {
- L2Object target = activeChar.getTarget();
- L2PcInstance player = null;
- if (target instanceof L2PcInstance)
- player = (L2PcInstance) target;
- else
- {
- showMainPage(activeChar);
- activeChar.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_TARGET));
- return;
- }
- if (!player.isClanLeader())
- {
- activeChar.sendPacket(new SystemMessage(SystemMessageId.S1_IS_NOT_A_CLAN_LEADER).addString(player.getName()));
- showMainPage(activeChar);
- return;
- }
- if ((id < 370) || (id > 391) || (level < 1) || (level > 3))
- {
- activeChar.sendMessage("Usage: //add_clan_skill <skill_id> <level>");
- showMainPage(activeChar);
- return;
- }
- else
- {
- L2Skill skill = SkillTable.getInstance().getInfo(id, level);
- if (skill != null)
- {
- String skillname = skill.getName();
- SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_SKILL_S1_ADDED);
- sm.addSkillName(skill);
- player.sendPacket(sm);
- player.getClan().broadcastToOnlineMembers(sm);
- player.getClan().addNewSkill(skill);
- activeChar.sendMessage("You gave the Clan Skill: " + skillname + " to the clan " + player.getClan().getName() + ".");
-
- activeChar.getClan().broadcastToOnlineMembers(new PledgeSkillList(activeChar.getClan()));
- for (L2PcInstance member : activeChar.getClan().getOnlineMembers(0))
- {
- member.sendSkillList();
- }
-
- showMainPage(activeChar);
- return;
- }
- else
- {
- activeChar.sendMessage("Error: there is no such skill.");
- return;
- }
-
- }
- }
-
- }
|