Guest User

L2NpcActionShift.java

a guest
Jul 31st, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 17.11 KB | None | 0 0
  1. /*
  2.  * This program is free software: you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License as published by the Free Software
  4.  * Foundation, either version 3 of the License, or (at your option) any later
  5.  * version.
  6.  *
  7.  * This program is distributed in the hope that it will be useful, but WITHOUT
  8.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10.  * details.
  11.  *
  12.  * You should have received a copy of the GNU General Public License along with
  13.  * this program. If not, see <http://www.gnu.org/licenses/>.
  14.  */
  15. package handlers.actionhandlers;
  16.  
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.handler.IActionHandler;
  19. import com.l2jserver.gameserver.model.Elementals;
  20. import com.l2jserver.gameserver.model.L2Object;
  21. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  22. import com.l2jserver.gameserver.model.actor.L2Attackable;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MerchantInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  28. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  29. import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
  30.  
  31. public class L2NpcActionShift implements IActionHandler
  32. {
  33.     /**
  34.      * Manage and Display the GM console to modify the L2NpcInstance (GM only).<BR><BR>
  35.      *
  36.      * <B><U> Actions (If the L2PcInstance is a GM only)</U> :</B><BR><BR>
  37.      * <li>Set the L2NpcInstance as target of the L2PcInstance player (if necessary)</li>
  38.      * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
  39.      * <li>If L2NpcInstance is autoAttackable, send a Server->Client packet StatusUpdate to the L2PcInstance in order to update L2NpcInstance HP bar </li>
  40.      * <li>Send a Server->Client NpcHtmlMessage() containing the GM console about this L2NpcInstance </li><BR><BR>
  41.      *
  42.      * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid
  43.      * that client wait an other packet</B></FONT><BR><BR>
  44.      *
  45.      * <B><U> Example of use </U> :</B><BR><BR>
  46.      * <li> Client packet : Action</li><BR><BR>
  47.      */
  48.     public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  49.     {
  50.         // Check if the L2PcInstance is a GM
  51.         if (activeChar.getAccessLevel().isGm())
  52.         {
  53.             // Set the target of the L2PcInstance activeChar
  54.             activeChar.setTarget(target);
  55.            
  56.             // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
  57.             // The activeChar.getLevel() - getLevel() permit to display the correct color in the select window
  58.             MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel());
  59.             activeChar.sendPacket(my);
  60.            
  61.             // Check if the activeChar is attackable (without a forced attack)
  62.             if (target.isAutoAttackable(activeChar))
  63.             {
  64.                 // Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
  65.                 StatusUpdate su = new StatusUpdate(target);
  66.                 su.addAttribute(StatusUpdate.CUR_HP, (int)((L2Character)target).getCurrentHp());
  67.                 su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
  68.                 activeChar.sendPacket(su);
  69.             }
  70.            
  71.             NpcHtmlMessage html = new NpcHtmlMessage(0);
  72.             html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npcinfo.htm");
  73.            
  74.             html.replace("%objid%", String.valueOf(target.getObjectId()));
  75.             html.replace("%class%", target.getClass().getSimpleName());
  76.             html.replace("%id%",    String.valueOf(((L2Npc)target).getTemplate().npcId));
  77.             html.replace("%lvl%",   String.valueOf(((L2Npc)target).getTemplate().level));
  78.             html.replace("%name%",  String.valueOf(((L2Npc)target).getTemplate().name));
  79.             html.replace("%tmplid%",String.valueOf(((L2Npc)target).getTemplate().npcId));
  80.             html.replace("%aggro%", String.valueOf((target instanceof L2Attackable) ? ((L2Attackable) target).getAggroRange() : 0));
  81.             html.replace("%hp%",    String.valueOf((int)((L2Character)target).getCurrentHp()));
  82.             html.replace("%hpmax%", String.valueOf(((L2Character)target).getMaxHp()));
  83.             html.replace("%mp%",    String.valueOf((int)((L2Character)target).getCurrentMp()));
  84.             html.replace("%mpmax%", String.valueOf(((L2Character)target).getMaxMp()));
  85.            
  86.             html.replace("%patk%", String.valueOf(((L2Character)target).getPAtk(null)));
  87.             html.replace("%matk%", String.valueOf(((L2Character)target).getMAtk(null, null)));
  88.             html.replace("%pdef%", String.valueOf(((L2Character)target).getPDef(null)));
  89.             html.replace("%mdef%", String.valueOf(((L2Character)target).getMDef(null, null)));
  90.             html.replace("%accu%", String.valueOf(((L2Character)target).getAccuracy()));
  91.             html.replace("%evas%", String.valueOf(((L2Character)target).getEvasionRate(null)));
  92.             html.replace("%crit%", String.valueOf(((L2Character)target).getCriticalHit(null, null)));
  93.             html.replace("%rspd%", String.valueOf(((L2Character)target).getRunSpeed()));
  94.             html.replace("%aspd%", String.valueOf(((L2Character)target).getPAtkSpd()));
  95.             html.replace("%cspd%", String.valueOf(((L2Character)target).getMAtkSpd()));
  96.             html.replace("%str%",  String.valueOf(((L2Character)target).getSTR()));
  97.             html.replace("%dex%",  String.valueOf(((L2Character)target).getDEX()));
  98.             html.replace("%con%",  String.valueOf(((L2Character)target).getCON()));
  99.             html.replace("%int%",  String.valueOf(((L2Character)target).getINT()));
  100.             html.replace("%wit%",  String.valueOf(((L2Character)target).getWIT()));
  101.             html.replace("%men%",  String.valueOf(((L2Character)target).getMEN()));
  102.             html.replace("%loc%",  String.valueOf(target.getX()+" "+target.getY()+" "+target.getZ()));
  103.             html.replace("%dist%", String.valueOf((int)Math.sqrt(activeChar.getDistanceSq(target))));
  104.            
  105.             byte attackAttribute = ((L2Character)target).getAttackElement();
  106.             html.replace("%ele_atk%", Elementals.getElementName(attackAttribute));
  107.             html.replace("%ele_atk_value%", String.valueOf(((L2Character)target).getAttackElementValue(attackAttribute)));
  108.             html.replace("%ele_dfire%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.FIRE)));
  109.             html.replace("%ele_dwater%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WATER)));
  110.             html.replace("%ele_dwind%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WIND)));
  111.             html.replace("%ele_dearth%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.EARTH)));
  112.             html.replace("%ele_dholy%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.HOLY)));
  113.             html.replace("%ele_ddark%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.DARK)));
  114.            
  115.             if (((L2Npc)target).getSpawn() != null)
  116.             {
  117.                 html.replace("%spawn%", ((L2Npc)target).getSpawn().getLocx()+" "+((L2Npc)target).getSpawn().getLocy()+" "+((L2Npc)target).getSpawn().getLocz());
  118.                 html.replace("%loc2d%", String.valueOf((int)Math.sqrt(((L2Character)target).getPlanDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy()))));
  119.                 html.replace("%loc3d%", String.valueOf((int)Math.sqrt(((L2Character)target).getDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy(), ((L2Npc)target).getSpawn().getLocz()))));
  120.                 html.replace("%resp%",  String.valueOf(((L2Npc)target).getSpawn().getRespawnDelay() / 1000));
  121.             }
  122.             else
  123.             {
  124.                 html.replace("%spawn%", "<font color=FF0000>null</font>");
  125.                 html.replace("%loc2d%", "<font color=FF0000>--</font>");
  126.                 html.replace("%loc3d%", "<font color=FF0000>--</font>");
  127.                 html.replace("%resp%",  "<font color=FF0000>--</font>");
  128.             }
  129.            
  130.             if (((L2Npc)target).hasAI())
  131.             {
  132.                 html.replace("%ai_intention%",  "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>Intention:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getAI().getIntention().name())+"</td></tr></table></td></tr>");
  133.                 html.replace("%ai%",            "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>AI</font></td><td align=right width=170>"+((L2Npc)target).getAI().getClass().getSimpleName()+"</td></tr></table></td></tr>");
  134.                 html.replace("%ai_type%",       "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>AIType</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getAiType())+"</td></tr></table></td></tr>");
  135.                 html.replace("%ai_clan%",       "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>Clan & Range:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClanRange())+"</td></tr></table></td></tr>");
  136.                 html.replace("%ai_enemy_clan%", "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>Enemy & Range:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyRange())+"</td></tr></table></td></tr>");
  137.             }
  138.             else
  139.             {
  140.                 html.replace("%ai_intention%",  "");
  141.                 html.replace("%ai%",            "");
  142.                 html.replace("%ai_type%",       "");
  143.                 html.replace("%ai_clan%",       "");
  144.                 html.replace("%ai_enemy_clan%", "");
  145.             }
  146.            
  147.             if (target instanceof L2MerchantInstance)
  148.             {
  149.                 html.replace("%butt%","<button value=\"Shop\" action=\"bypass -h admin_showShop "+String.valueOf(((L2Npc)target).getTemplate().npcId)+"\" width=60 height=21 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">");
  150.             }
  151.             else
  152.             {
  153.                 html.replace("%butt%","");
  154.             }
  155.            
  156.             activeChar.sendPacket(html);
  157.         }
  158.         else if (Config.ALT_GAME_VIEWNPC)
  159.         {
  160.             // Set the target of the L2PcInstance activeChar
  161.             activeChar.setTarget(target);
  162.            
  163.             // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
  164.             // The activeChar.getLevel() - getLevel() permit to display the correct color in the select window
  165.             MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel());
  166.             activeChar.sendPacket(my);
  167.            
  168.             // Check if the activeChar is attackable (without a forced attack)
  169.             if (target.isAutoAttackable(activeChar))
  170.             {
  171.                 // Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
  172.                 StatusUpdate su = new StatusUpdate(target);
  173.                 su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character)target).getCurrentHp());
  174.                 su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
  175.                 activeChar.sendPacket(su);
  176.             }
  177.            
  178.             NpcHtmlMessage html = new NpcHtmlMessage(0);
  179.             html.setFile(activeChar.getHtmlPrefix(), "data/html/custom/mobinfo.htm");
  180.            
  181.             html.replace("%objid%", String.valueOf(target.getObjectId()));
  182.             html.replace("%class%", target.getClass().getSimpleName());
  183.             html.replace("%id%",    String.valueOf(((L2Npc)target).getTemplate().npcId));
  184.             html.replace("%lvl%",   String.valueOf(((L2Npc)target).getTemplate().level));
  185.             html.replace("%name%",  String.valueOf(((L2Npc)target).getTemplate().name));
  186.             html.replace("%tmplid%",String.valueOf(((L2Npc)target).getTemplate().npcId));
  187.             html.replace("%aggro%", String.valueOf((target instanceof L2Attackable) ? ((L2Attackable) target).getAggroRange() : 0));
  188.             html.replace("%hp%",    String.valueOf((int)((L2Character)target).getCurrentHp()));
  189.             html.replace("%hpmax%", String.valueOf(((L2Character)target).getMaxHp()));
  190.             html.replace("%mp%",    String.valueOf((int)((L2Character)target).getCurrentMp()));
  191.             html.replace("%mpmax%", String.valueOf(((L2Character)target).getMaxMp()));
  192.            
  193.             html.replace("%patk%", String.valueOf(((L2Character)target).getPAtk(null)));
  194.             html.replace("%matk%", String.valueOf(((L2Character)target).getMAtk(null, null)));
  195.             html.replace("%pdef%", String.valueOf(((L2Character)target).getPDef(null)));
  196.             html.replace("%mdef%", String.valueOf(((L2Character)target).getMDef(null, null)));
  197.             html.replace("%accu%", String.valueOf(((L2Character)target).getAccuracy()));
  198.             html.replace("%evas%", String.valueOf(((L2Character)target).getEvasionRate(null)));
  199.             html.replace("%crit%", String.valueOf(((L2Character)target).getCriticalHit(null, null)));
  200.             html.replace("%rspd%", String.valueOf(((L2Character)target).getRunSpeed()));
  201.             html.replace("%aspd%", String.valueOf(((L2Character)target).getPAtkSpd()));
  202.             html.replace("%cspd%", String.valueOf(((L2Character)target).getMAtkSpd()));
  203.             html.replace("%str%",  String.valueOf(((L2Character)target).getSTR()));
  204.             html.replace("%dex%",  String.valueOf(((L2Character)target).getDEX()));
  205.             html.replace("%con%",  String.valueOf(((L2Character)target).getCON()));
  206.             html.replace("%int%",  String.valueOf(((L2Character)target).getINT()));
  207.             html.replace("%wit%",  String.valueOf(((L2Character)target).getWIT()));
  208.             html.replace("%men%",  String.valueOf(((L2Character)target).getMEN()));
  209.             html.replace("%loc%",  String.valueOf(target.getX()+" "+target.getY()+" "+target.getZ()));
  210.             html.replace("%dist%", String.valueOf((int)Math.sqrt(activeChar.getDistanceSq(target))));
  211.            
  212.             byte attackAttribute = ((L2Character)target).getAttackElement();
  213.             html.replace("%ele_atk%", Elementals.getElementName(attackAttribute));
  214.             html.replace("%ele_atk_value%", String.valueOf(((L2Character)target).getAttackElementValue(attackAttribute)));
  215.             html.replace("%ele_dfire%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.FIRE)));
  216.             html.replace("%ele_dwater%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WATER)));
  217.             html.replace("%ele_dwind%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.WIND)));
  218.             html.replace("%ele_dearth%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.EARTH)));
  219.             html.replace("%ele_dholy%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.HOLY)));
  220.             html.replace("%ele_ddark%", String.valueOf(((L2Character)target).getDefenseElementValue(Elementals.DARK)));
  221.            
  222.             if (((L2Npc)target).getSpawn() != null)
  223.             {
  224.                 html.replace("%spawn%", ((L2Npc)target).getSpawn().getLocx()+" "+((L2Npc)target).getSpawn().getLocy()+" "+((L2Npc)target).getSpawn().getLocz());
  225.                 html.replace("%loc2d%", String.valueOf((int)Math.sqrt(((L2Character)target).getPlanDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy()))));
  226.                 html.replace("%loc3d%", String.valueOf((int)Math.sqrt(((L2Character)target).getDistanceSq(((L2Npc)target).getSpawn().getLocx(), ((L2Npc)target).getSpawn().getLocy(), ((L2Npc)target).getSpawn().getLocz()))));
  227.                 html.replace("%resp%",  String.valueOf(((L2Npc)target).getSpawn().getRespawnDelay() / 1000));
  228.             }
  229.             else
  230.             {
  231.                 html.replace("%spawn%", "<font color=FF0000>null</font>");
  232.                 html.replace("%loc2d%", "<font color=FF0000>--</font>");
  233.                 html.replace("%loc3d%", "<font color=FF0000>--</font>");
  234.                 html.replace("%resp%",  "<font color=FF0000>--</font>");
  235.             }
  236.            
  237.             if (((L2Npc)target).hasAI())
  238.             {
  239.                 html.replace("%ai_intention%",  "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>Intention:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getAI().getIntention().name())+"</td></tr></table></td></tr>");
  240.                 html.replace("%ai%",            "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>AI</font></td><td align=right width=170>"+((L2Npc)target).getAI().getClass().getSimpleName()+"</td></tr></table></td></tr>");
  241.                 html.replace("%ai_type%",       "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>AIType</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getAiType())+"</td></tr></table></td></tr>");
  242.                 html.replace("%ai_clan%",       "<tr><td><table width=270 border=0><tr><td width=100><font color=FFAA00>Clan & Range:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getClanRange())+"</td></tr></table></td></tr>");
  243.                 html.replace("%ai_enemy_clan%", "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>Enemy & Range:</font></td><td align=right width=170>"+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyClan())+" "+String.valueOf(((L2Npc)target).getTemplate().getAIDataStatic().getEnemyRange())+"</td></tr></table></td></tr>");
  244.             }
  245.             else
  246.             {
  247.                 html.replace("%ai_intention%",  "");
  248.                 html.replace("%ai%",            "");
  249.                 html.replace("%ai_type%",       "");
  250.                 html.replace("%ai_clan%",       "");
  251.                 html.replace("%ai_enemy_clan%", "");
  252.             }
  253.            
  254.             activeChar.sendPacket(html);
  255.         }
  256.        
  257.         return true;
  258.     }
  259.    
  260.     public InstanceType getInstanceType()
  261.     {
  262.         return InstanceType.L2Npc;
  263.     }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment