/* * 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.actionhandlers; import com.l2jserver.Config; import com.l2jserver.gameserver.datatables.ItemTable; import com.l2jserver.gameserver.handler.IActionHandler; import com.l2jserver.gameserver.model.Elementals; import com.l2jserver.gameserver.model.L2DropCategory; import com.l2jserver.gameserver.model.L2DropData; import com.l2jserver.gameserver.model.L2Object; import com.l2jserver.gameserver.model.L2Object.InstanceType; import com.l2jserver.gameserver.model.actor.L2Attackable; import com.l2jserver.gameserver.model.actor.L2Character; import com.l2jserver.gameserver.model.actor.L2Npc; import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected; import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage; import com.l2jserver.gameserver.network.serverpackets.StatusUpdate; import com.l2jserver.gameserver.skills.BaseStats; import com.l2jserver.gameserver.skills.Stats; import com.l2jserver.gameserver.templates.item.L2Item; import com.l2jserver.util.StringUtil; public class L2NpcActionShift implements IActionHandler { /** * Manage and Display the GM console to modify the L2NpcInstance (GM only).

* * Actions (If the L2PcInstance is a GM only) :

*
  • Set the L2NpcInstance as target of the L2PcInstance player (if necessary)
  • *
  • Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)
  • *
  • If L2NpcInstance is autoAttackable, send a Server->Client packet StatusUpdate to the L2PcInstance in order to update L2NpcInstance HP bar
  • *
  • Send a Server->Client NpcHtmlMessage() containing the GM console about this L2NpcInstance


  • * * Caution : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid * that client wait an other packet

    * * Example of use :

    *
  • Client packet : Action


  • */ @Override public boolean action(L2PcInstance activeChar, L2Object target, boolean interact) { // Check if the L2PcInstance is a GM if (activeChar.getAccessLevel().isGm()) { // Set the target of the L2PcInstance activeChar activeChar.setTarget(target); // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar // The activeChar.getLevel() - getLevel() permit to display the correct color in the select window MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel()); activeChar.sendPacket(my); // Check if the activeChar is attackable (without a forced attack) if (target.isAutoAttackable(activeChar)) { // Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar StatusUpdate su = new StatusUpdate(target); su.addAttribute(StatusUpdate.CUR_HP, (int)((L2Character)target).getCurrentHp()); su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp()); activeChar.sendPacket(su); } NpcHtmlMessage html = new NpcHtmlMessage(0); html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npcinfo.htm"); html.replace("%objid%", String.valueOf(target.getObjectId())); html.replace("%class%", target.getClass().getSimpleName()); html.replace("%id%", String.valueOf(((L2Npc)target).getTemplate().npcId)); html.replace("%lvl%", String.valueOf(((L2Npc)target).getTemplate().level)); html.replace("%name%", String.valueOf(((L2Npc)target).getTemplate().name)); html.replace("%tmplid%",String.valueOf(((L2Npc)target).getTemplate().npcId)); html.replace("%aggro%", String.valueOf((target instanceof L2Attackable) ? ((L2Attackable) target).getAggroRange() : 0)); html.replace("%hp%", String.valueOf((int)((L2Character)target).getCurrentHp())); html.replace("%hpmax%", String.valueOf(((L2Character)target).getMaxHp())); html.replace("%mp%", String.valueOf((int)((L2Character)target).getCurrentMp())); html.replace("%mpmax%", String.valueOf(((L2Character)target).getMaxMp())); html.replace("%patk%", String.valueOf(((L2Character)target).getPAtk(null))); html.replace("%matk%", String.valueOf(((L2Character)target).getMAtk(null, null))); html.replace("%pdef%", String.valueOf(((L2Character)target).getPDef(null))); html.replace("%mdef%", String.valueOf(((L2Character)target).getMDef(null, null))); html.replace("%accu%", String.valueOf(((L2Character)target).getAccuracy())); html.replace("%evas%", String.valueOf(((L2Character)target).getEvasionRate(null))); html.replace("%crit%", String.valueOf(((L2Character)target).getCriticalHit(null, null))); html.replace("%rspd%", String.valueOf(((L2Character)target).getRunSpeed())); html.replace("%aspd%", String.valueOf(((L2Character)target).getPAtkSpd())); html.replace("%cspd%", String.valueOf(((L2Character)target).getMAtkSpd())); html.replace("%str%", String.valueOf(((L2Character)target).getSTR())); html.replace("%dex%", String.valueOf(((L2Character)target).getDEX())); html.replace("%con%", String.valueOf(((L2Character)target).getCON())); html.replace("%int%", String.valueOf(((L2Character)target).getINT())); html.replace("%wit%", String.valueOf(((L2Character)target).getWIT())); html.replace("%men%", String.valueOf(((L2Character)target).getMEN())); html.replace("%loc%", String.valueOf(target.getX()+" "+target.getY()+" "+target.getZ())); html.replace("%dist%", String.valueOf((int)Math.sqrt(activeChar.getDistanceSq(target)))); byte attackAttribute = ((L2Character)target).getAttackElement(); html.replace("%ele_atk%", Elementals.getElementName(attackAttribute)); html.replace("%ele_atk_value%", String.valueOf(((L2Character)target).getAttackElementValue(attackAttribute))); html.replace("%ele_dfire%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.FIRE))); html.replace("%ele_dwater%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WATER))); html.replace("%ele_dwind%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WIND))); html.replace("%ele_dearth%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.EARTH))); html.replace("%ele_dholy%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.HOLY))); html.replace("%ele_ddark%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.DARK))); if (((L2Npc)target).getSpawn() != null) { html.replace("%spawn%", ((L2Npc)target).getSpawn().getLocx()+" "+((L2Npc)target).getSpawn().getLocy()+" "+((L2Npc)target).getSpawn().getLocz()); html.replace("%loc2d%", String.valueOf((int)Math.sqrt(((L2Character)target).getPlanDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy())))); html.replace("%loc3d%", String.valueOf((int)Math.sqrt(((L2Character)target).getDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy(), ((L2Npc)target).getSpawn().getLocz())))); html.replace("%resp%", String.valueOf(((L2Npc)target).getSpawn().getRespawnDelay() / 1000)); } else { html.replace("%spawn%", "null"); html.replace("%loc2d%", "--"); html.replace("%loc3d%", "--"); html.replace("%resp%", "--"); } if (((L2Npc)target).hasAI()) { html.replace("%ai_intention%", "
    Intention:"+String.valueOf(((L2Npc)target).getAI().getIntention().name())+"
    "); html.replace("%ai%", "
    AI"+((L2Npc)target).getAI().getClass().getSimpleName()+"
    "); html.replace("%ai_type%", "
    AIType"+String.valueOf(((L2Npc)target).getAiType())+"
    "); html.replace("%ai_clan%", "
    Clan & Range:"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClanRange())+"
    "); html.replace("%ai_enemy_clan%", "
    Enemy & Range:"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyRange())+"
    "); } else { html.replace("%ai_intention%", ""); html.replace("%ai%", ""); html.replace("%ai_type%", ""); html.replace("%ai_clan%", ""); html.replace("%ai_enemy_clan%", ""); } if (target instanceof L2MerchantInstance) { html.replace("%butt%","