/* * 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 . */ package handlers.admincommandhandlers; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.StringTokenizer; import com.l2jmobius.Config; import com.l2jmobius.gameserver.data.xml.impl.SkillData; import com.l2jmobius.gameserver.data.xml.impl.SkillTreesData; import com.l2jmobius.gameserver.handler.IAdminCommandHandler; import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.skills.AbnormalType; import com.l2jmobius.gameserver.model.skills.BuffInfo; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage; import com.l2jmobius.gameserver.network.serverpackets.SkillCoolTime; import com.l2jmobius.gameserver.util.GMAudit; public class AdminBuffs implements IAdminCommandHandler { private final static int PAGE_LIMIT = 20; private static final String[] ADMIN_COMMANDS = { "admin_buff", "admin_getbuffs", "admin_getbuffs_ps", "admin_stopbuff", "admin_stopallbuffs", "admin_areacancel", "admin_removereuse", "admin_switch_gm_buffs" }; // Misc private static final String FONT_RED1 = ""; private static final String FONT_RED2 = ""; @Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (command.startsWith("admin_buff")) { if ((activeChar.getTarget() == null) || !activeChar.getTarget().isCharacter()) { activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); return false; } final StringTokenizer st = new StringTokenizer(command, " "); command = st.nextToken(); if (!st.hasMoreTokens()) { activeChar.sendMessage("Skill Id and level are not specified."); activeChar.sendMessage("Usage: //buff "); return false; } try { final int skillId = Integer.parseInt(st.nextToken()); final int skillLevel = st.hasMoreTokens() ? Integer.parseInt(st.nextToken()) : SkillData.getInstance().getMaxLevel(skillId); final L2Character target = (L2Character) activeChar.getTarget(); final Skill skill = SkillData.getInstance().getSkill(skillId, skillLevel); if (skill == null) { activeChar.sendMessage("Skill with id: " + skillId + ", lvl: " + skillLevel + " not found."); return false; } activeChar.sendMessage("Admin buffing " + skill.getName() + " (" + skillId + "," + skillLevel + ")"); skill.applyEffects(activeChar, target); return true; } catch (Exception e) { activeChar.sendMessage("Failed buffing: " + e.getMessage()); activeChar.sendMessage("Usage: //buff "); return false; } } else if (command.startsWith("admin_getbuffs")) { final StringTokenizer st = new StringTokenizer(command, " "); command = st.nextToken(); if (st.hasMoreTokens()) { final String playername = st.nextToken(); final L2PcInstance player = L2World.getInstance().getPlayer(playername); if (player != null) { int page = 1; if (st.hasMoreTokens()) { page = Integer.parseInt(st.nextToken()); } showBuffs(activeChar, player, page, command.endsWith("_ps")); return true; } activeChar.sendMessage("The player " + playername + " is not online."); return false; } else if ((activeChar.getTarget() != null) && activeChar.getTarget().isCharacter()) { showBuffs(activeChar, (L2Character) activeChar.getTarget(), 1, command.endsWith("_ps")); return true; } else { activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); return false; } } else if (command.startsWith("admin_stopbuff")) { try { final StringTokenizer st = new StringTokenizer(command, " "); st.nextToken(); final int objectId = Integer.parseInt(st.nextToken()); final int skillId = Integer.parseInt(st.nextToken()); removeBuff(activeChar, objectId, skillId); return true; } catch (Exception e) { activeChar.sendMessage("Failed removing effect: " + e.getMessage()); activeChar.sendMessage("Usage: //stopbuff "); return false; } } else if (command.startsWith("admin_stopallbuffs")) { try { final StringTokenizer st = new StringTokenizer(command, " "); st.nextToken(); final int objectId = Integer.parseInt(st.nextToken()); removeAllBuffs(activeChar, objectId); return true; } catch (Exception e) { activeChar.sendMessage("Failed removing all effects: " + e.getMessage()); activeChar.sendMessage("Usage: //stopallbuffs "); return false; } } else if (command.startsWith("admin_areacancel")) { final StringTokenizer st = new StringTokenizer(command, " "); st.nextToken(); final String val = st.nextToken(); try { final int radius = Integer.parseInt(val); L2World.getInstance().forEachVisibleObjectInRange(activeChar, L2PcInstance.class, radius, L2Character::stopAllEffects); activeChar.sendMessage("All effects canceled within radius " + radius); return true; } catch (NumberFormatException e) { activeChar.sendMessage("Usage: //areacancel "); return false; } } else if (command.startsWith("admin_removereuse")) { final StringTokenizer st = new StringTokenizer(command, " "); command = st.nextToken(); L2PcInstance player = null; if (st.hasMoreTokens()) { final String playername = st.nextToken(); try { player = L2World.getInstance().getPlayer(playername); } catch (Exception e) { } if (player == null) { activeChar.sendMessage("The player " + playername + " is not online."); return false; } } else if ((activeChar.getTarget() != null) && activeChar.getTarget().isPlayer()) { player = activeChar.getTarget().getActingPlayer(); } else { activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); return false; } try { player.resetTimeStamps(); player.resetDisabledSkills(); player.sendPacket(new SkillCoolTime(player)); activeChar.sendMessage("Skill reuse was removed from " + player.getName() + "."); return true; } catch (NullPointerException e) { return false; } } else if (command.startsWith("admin_switch_gm_buffs")) { if (Config.GM_GIVE_SPECIAL_SKILLS != Config.GM_GIVE_SPECIAL_AURA_SKILLS) { final boolean toAuraSkills = activeChar.getKnownSkill(7041) != null; switchSkills(activeChar, toAuraSkills); activeChar.sendSkillList(); activeChar.sendMessage("You have succefully changed to target " + (toAuraSkills ? "aura" : "one") + " special skills."); return true; } activeChar.sendMessage("There is nothing to switch."); return false; } return true; } /** * @param gmchar the player to switch the Game Master skills. * @param toAuraSkills if {@code true} it will remove "GM Aura" skills and add "GM regular" skills, vice versa if {@code false}. */ public static void switchSkills(L2PcInstance gmchar, boolean toAuraSkills) { final Collection skills = toAuraSkills ? SkillTreesData.getInstance().getGMSkillTree().values() : SkillTreesData.getInstance().getGMAuraSkillTree().values(); for (Skill skill : skills) { gmchar.removeSkill(skill, false); // Don't Save GM skills to database } SkillTreesData.getInstance().addSkills(gmchar, toAuraSkills); } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } public static void showBuffs(L2PcInstance activeChar, L2Character target, int page, boolean passive) { final List effects = new ArrayList<>(); if (!passive) { effects.addAll(target.getEffectList().getEffects()); } else { effects.addAll(target.getEffectList().getPassives()); } if ((page > ((effects.size() / PAGE_LIMIT) + 1)) || (page < 1)) { return; } int max = effects.size() / PAGE_LIMIT; if (effects.size() > (PAGE_LIMIT * max)) { max++; } final StringBuilder html = new StringBuilder(500 + (effects.size() * 200)); html.append("
Effects of "); html.append(target.getName()); html.append("

"); final int start = ((page - 1) * PAGE_LIMIT); final int end = Math.min(((page - 1) * PAGE_LIMIT) + PAGE_LIMIT, effects.size()); int count = 0; for (BuffInfo info : effects) { if ((count >= start) && (count < end)) { final Skill skill = info.getSkill(); for (AbstractEffect effect : info.getEffects()) { html.append(""); } } count++; } html.append("
SkillRem. TimeAction
"); html.append(!info.isInUse() ? FONT_RED1 : ""); html.append(skill.getName()); html.append(" Lv "); html.append(skill.getLevel()); html.append(" ("); html.append(effect.getClass().getSimpleName()); html.append(")"); html.append(!info.isInUse() ? FONT_RED2 : ""); html.append(""); html.append(skill.isToggle() ? "T (" + info.getTickCount(effect) + ")" : skill.isPassive() ? "P" : info.getTime() + "s"); html.append("
"); for (int x = 0; x < max; x++) { final int pagenr = x + 1; if (page == pagenr) { html.append(""); } else { html.append(""); } } html.append("
Page "); html.append(pagenr); html.append(" Page "); html.append(pagenr); html.append("
"); // Buttons html.append("