L2StaticObjectInstanceAction.java 3.4 KB

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