L2StaticObjectInstanceAction.java 3.2 KB

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