L2StaticObjectInstanceAction.java 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. import com.l2jserver.gameserver.ai.CtrlIntention;
  17. import com.l2jserver.gameserver.cache.HtmCache;
  18. import com.l2jserver.gameserver.handler.IActionHandler;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Object.InstanceType;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2StaticObjectInstance;
  24. import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
  25. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  26. public class L2StaticObjectInstanceAction implements IActionHandler
  27. {
  28. @Override
  29. public boolean action(final L2PcInstance activeChar, final L2Object target, final boolean interact)
  30. {
  31. final L2StaticObjectInstance staticObject = (L2StaticObjectInstance) target;
  32. if (staticObject.getType() < 0)
  33. {
  34. _log.info("L2StaticObjectInstance: StaticObject with invalid type! StaticObjectId: " + staticObject.getStaticObjectId());
  35. }
  36. // Check if the L2PcInstance already target the L2NpcInstance
  37. if (activeChar.getTarget() != staticObject)
  38. {
  39. // Set the target of the L2PcInstance activeChar
  40. activeChar.setTarget(staticObject);
  41. activeChar.sendPacket(new MyTargetSelected(staticObject.getObjectId(), 0));
  42. }
  43. else if (interact)
  44. {
  45. activeChar.sendPacket(new MyTargetSelected(staticObject.getObjectId(), 0));
  46. // Calculate the distance between the L2PcInstance and the L2NpcInstance
  47. if (!activeChar.isInsideRadius(staticObject, L2Npc.INTERACTION_DISTANCE, false, false))
  48. {
  49. // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
  50. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, staticObject);
  51. }
  52. else
  53. {
  54. if (staticObject.getType() == 2)
  55. {
  56. final String filename = (staticObject.getStaticObjectId() == 24230101) ? "data/html/signboards/tomb_of_crystalgolem.htm" : "data/html/signboards/pvp_signboard.htm";
  57. final String content = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), filename);
  58. final NpcHtmlMessage html = new NpcHtmlMessage(staticObject.getObjectId());
  59. if (content == null)
  60. {
  61. html.setHtml("<html><body>Signboard is missing:<br>" + filename + "</body></html>");
  62. }
  63. else
  64. {
  65. html.setHtml(content);
  66. }
  67. activeChar.sendPacket(html);
  68. }
  69. else if (staticObject.getType() == 0)
  70. {
  71. activeChar.sendPacket(staticObject.getMap());
  72. }
  73. }
  74. }
  75. return true;
  76. }
  77. @Override
  78. public InstanceType getInstanceType()
  79. {
  80. return InstanceType.L2StaticObjectInstance;
  81. }
  82. }