L2NpcActionShift.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.actionshifthandlers;
  20. import handlers.bypasshandlers.NpcViewMod;
  21. import java.util.Set;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.enums.InstanceType;
  24. import com.l2jserver.gameserver.handler.IActionShiftHandler;
  25. import com.l2jserver.gameserver.instancemanager.WalkingManager;
  26. import com.l2jserver.gameserver.model.Elementals;
  27. import com.l2jserver.gameserver.model.L2Object;
  28. import com.l2jserver.gameserver.model.Location;
  29. import com.l2jserver.gameserver.model.actor.L2Attackable;
  30. import com.l2jserver.gameserver.model.actor.L2Character;
  31. import com.l2jserver.gameserver.model.actor.L2Npc;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  34. import com.l2jserver.gameserver.util.Util;
  35. public class L2NpcActionShift implements IActionShiftHandler
  36. {
  37. /**
  38. * Manage and Display the GM console to modify the L2NpcInstance (GM only).<BR>
  39. * <BR>
  40. * <B><U> Actions (If the L2PcInstance is a GM only)</U> :</B><BR>
  41. * <BR>
  42. * <li>Set the L2NpcInstance as target of the L2PcInstance player (if necessary)</li> <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li> <li>If L2NpcInstance is autoAttackable, send a Server->Client packet StatusUpdate to the
  43. * L2PcInstance in order to update L2NpcInstance HP bar</li> <li>Send a Server->Client NpcHtmlMessage() containing the GM console about this L2NpcInstance</li><BR>
  44. * <BR>
  45. * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid that client wait an other packet</B></FONT><BR>
  46. * <BR>
  47. * <B><U> Example of use </U> :</B><BR>
  48. * <BR>
  49. * <li>Client packet : Action</li><BR>
  50. * <BR>
  51. */
  52. @Override
  53. public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
  54. {
  55. // Check if the L2PcInstance is a GM
  56. if (activeChar.getAccessLevel().isGm())
  57. {
  58. // Set the target of the L2PcInstance activeChar
  59. activeChar.setTarget(target);
  60. final NpcHtmlMessage html = new NpcHtmlMessage();
  61. html.setFile(activeChar.getHtmlPrefix(), "data/html/admin/npcinfo.htm");
  62. html.replace("%objid%", String.valueOf(target.getObjectId()));
  63. html.replace("%class%", target.getClass().getSimpleName());
  64. html.replace("%race%", ((L2Npc) target).getTemplate().getRace().toString());
  65. html.replace("%id%", String.valueOf(((L2Npc) target).getTemplate().getId()));
  66. html.replace("%lvl%", String.valueOf(((L2Npc) target).getTemplate().getLevel()));
  67. html.replace("%name%", String.valueOf(((L2Npc) target).getTemplate().getName()));
  68. html.replace("%tmplid%", String.valueOf(((L2Npc) target).getTemplate().getId()));
  69. html.replace("%aggro%", String.valueOf((target instanceof L2Attackable) ? ((L2Attackable) target).getAggroRange() : 0));
  70. html.replace("%hp%", String.valueOf((int) ((L2Character) target).getCurrentHp()));
  71. html.replace("%hpmax%", String.valueOf(((L2Character) target).getMaxHp()));
  72. html.replace("%mp%", String.valueOf((int) ((L2Character) target).getCurrentMp()));
  73. html.replace("%mpmax%", String.valueOf(((L2Character) target).getMaxMp()));
  74. html.replace("%patk%", String.valueOf(((L2Character) target).getPAtk(null)));
  75. html.replace("%matk%", String.valueOf(((L2Character) target).getMAtk(null, null)));
  76. html.replace("%pdef%", String.valueOf(((L2Character) target).getPDef(null)));
  77. html.replace("%mdef%", String.valueOf(((L2Character) target).getMDef(null, null)));
  78. html.replace("%accu%", String.valueOf(((L2Character) target).getAccuracy()));
  79. html.replace("%evas%", String.valueOf(((L2Character) target).getEvasionRate(null)));
  80. html.replace("%crit%", String.valueOf(((L2Character) target).getCriticalHit(null, null)));
  81. html.replace("%rspd%", String.valueOf((int) ((L2Character) target).getRunSpeed()));
  82. html.replace("%aspd%", String.valueOf(((L2Character) target).getPAtkSpd()));
  83. html.replace("%cspd%", String.valueOf(((L2Character) target).getMAtkSpd()));
  84. html.replace("%atkType%", String.valueOf(((L2Character) target).getTemplate().getBaseAttackType()));
  85. html.replace("%atkRng%", String.valueOf(((L2Character) target).getTemplate().getBaseAttackRange()));
  86. html.replace("%str%", String.valueOf(((L2Character) target).getSTR()));
  87. html.replace("%dex%", String.valueOf(((L2Character) target).getDEX()));
  88. html.replace("%con%", String.valueOf(((L2Character) target).getCON()));
  89. html.replace("%int%", String.valueOf(((L2Character) target).getINT()));
  90. html.replace("%wit%", String.valueOf(((L2Character) target).getWIT()));
  91. html.replace("%men%", String.valueOf(((L2Character) target).getMEN()));
  92. html.replace("%loc%", String.valueOf(target.getX() + " " + target.getY() + " " + target.getZ()));
  93. html.replace("%heading%", String.valueOf(((L2Character) target).getHeading()));
  94. html.replace("%collision_radius%", String.valueOf(((L2Character) target).getTemplate().getfCollisionRadius()));
  95. html.replace("%collision_height%", String.valueOf(((L2Character) target).getTemplate().getfCollisionHeight()));
  96. html.replace("%dist%", String.valueOf((int) activeChar.calculateDistance(target, true, false)));
  97. byte attackAttribute = ((L2Character) target).getAttackElement();
  98. html.replace("%ele_atk%", Elementals.getElementName(attackAttribute));
  99. html.replace("%ele_atk_value%", String.valueOf(((L2Character) target).getAttackElementValue(attackAttribute)));
  100. html.replace("%ele_dfire%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.FIRE)));
  101. html.replace("%ele_dwater%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.WATER)));
  102. html.replace("%ele_dwind%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.WIND)));
  103. html.replace("%ele_dearth%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.EARTH)));
  104. html.replace("%ele_dholy%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.HOLY)));
  105. html.replace("%ele_ddark%", String.valueOf(((L2Character) target).getDefenseElementValue(Elementals.DARK)));
  106. if (((L2Npc) target).getSpawn() != null)
  107. {
  108. html.replace("%territory%", ((L2Npc) target).getSpawn().getSpawnTerritory() == null ? "None" : ((L2Npc) target).getSpawn().getSpawnTerritory().getName());
  109. if (((L2Npc) target).getSpawn().isTerritoryBased())
  110. {
  111. html.replace("%spawntype%", "Random");
  112. final Location spawnLoc = ((L2Npc) target).getSpawn().getLocation(target);
  113. html.replace("%spawn%", spawnLoc.getX() + " " + spawnLoc.getY() + " " + spawnLoc.getZ());
  114. }
  115. else
  116. {
  117. html.replace("%spawntype%", "Fixed");
  118. html.replace("%spawn%", ((L2Npc) target).getSpawn().getX() + " " + ((L2Npc) target).getSpawn().getY() + " " + ((L2Npc) target).getSpawn().getZ());
  119. }
  120. html.replace("%loc2d%", String.valueOf((int) target.calculateDistance(((L2Npc) target).getSpawn().getLocation(target), false, false)));
  121. html.replace("%loc3d%", String.valueOf((int) target.calculateDistance(((L2Npc) target).getSpawn().getLocation(target), true, false)));
  122. if (((L2Npc) target).getSpawn().getRespawnMinDelay() == 0)
  123. {
  124. html.replace("%resp%", "None");
  125. }
  126. else if (((L2Npc) target).getSpawn().hasRespawnRandom())
  127. {
  128. html.replace("%resp%", String.valueOf(((L2Npc) target).getSpawn().getRespawnMinDelay() / 1000) + "-" + String.valueOf((((L2Npc) target).getSpawn().getRespawnMaxDelay() / 1000) + " sec"));
  129. }
  130. else
  131. {
  132. html.replace("%resp%", String.valueOf(((L2Npc) target).getSpawn().getRespawnMinDelay() / 1000) + " sec");
  133. }
  134. }
  135. else
  136. {
  137. html.replace("%territory%", "<font color=FF0000>--</font>");
  138. html.replace("%spawntype%", "<font color=FF0000>--</font>");
  139. html.replace("%spawn%", "<font color=FF0000>null</font>");
  140. html.replace("%loc2d%", "<font color=FF0000>--</font>");
  141. html.replace("%loc3d%", "<font color=FF0000>--</font>");
  142. html.replace("%resp%", "<font color=FF0000>--</font>");
  143. }
  144. if (((L2Npc) target).hasAI())
  145. {
  146. Set<Integer> clans = ((L2Npc) target).getTemplate().getClans();
  147. Set<Integer> ignoreClanNpcIds = ((L2Npc) target).getTemplate().getIgnoreClanNpcIds();
  148. String clansString = clans != null ? Util.implode(clans.toArray(), ", ") : "";
  149. String ignoreClanNpcIdsString = ignoreClanNpcIds != null ? Util.implode(ignoreClanNpcIds.toArray(), ", ") : "";
  150. 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>");
  151. 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>");
  152. 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>");
  153. 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>" + clansString + " " + String.valueOf(((L2Npc) target).getTemplate().getClanHelpRange()) + "</td></tr></table></td></tr>");
  154. html.replace("%ai_enemy_clan%", "<tr><td><table width=270 border=0 bgcolor=131210><tr><td width=100><font color=FFAA00>Ignore & Range:</font></td><td align=right width=170>" + ignoreClanNpcIdsString + " " + String.valueOf(((L2Npc) target).getTemplate().getAggroRange()) + "</td></tr></table></td></tr>");
  155. }
  156. else
  157. {
  158. html.replace("%ai_intention%", "");
  159. html.replace("%ai%", "");
  160. html.replace("%ai_type%", "");
  161. html.replace("%ai_clan%", "");
  162. html.replace("%ai_enemy_clan%", "");
  163. }
  164. final String routeName = WalkingManager.getInstance().getRouteName((L2Npc) target);
  165. if (!routeName.isEmpty())
  166. {
  167. html.replace("%route%", "<tr><td><table width=270 border=0><tr><td width=100><font color=LEVEL>Route:</font></td><td align=right width=170>" + routeName + "</td></tr></table></td></tr>");
  168. }
  169. else
  170. {
  171. html.replace("%route%", "");
  172. }
  173. activeChar.sendPacket(html);
  174. }
  175. else if (Config.ALT_GAME_VIEWNPC)
  176. {
  177. if (!target.isNpc())
  178. {
  179. return false;
  180. }
  181. activeChar.setTarget(target);
  182. NpcViewMod.sendNpcView(activeChar, (L2Npc) target);
  183. }
  184. return true;
  185. }
  186. @Override
  187. public InstanceType getInstanceType()
  188. {
  189. return InstanceType.L2Npc;
  190. }
  191. }