Book.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.gameserver.cache.HtmCache;
  17. import net.sf.l2j.gameserver.handler.IItemHandler;
  18. import net.sf.l2j.gameserver.model.L2ItemInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  21. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  22. import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  23. public class Book implements IItemHandler
  24. {
  25. private static final int[] ITEM_IDS =
  26. {
  27. 5588, 6317, 7561, 7063, 7064, 7065,
  28. 7082, 7083, 7084, 7085, 7086, 7087,
  29. 7088, 7089, 7090, 7091, 7092, 7093,
  30. 7094, 7095, 7096, 7097, 7098, 7099,
  31. 7100, 7101, 7102, 7103, 7104, 7105,
  32. 7106, 7107, 7108, 7109, 7110, 7111,
  33. 7112, 8059
  34. };
  35. /**
  36. *
  37. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  38. */
  39. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  40. {
  41. if (!(playable instanceof L2PcInstance))
  42. return;
  43. L2PcInstance activeChar = (L2PcInstance) playable;
  44. final int itemId = item.getItemId();
  45. String filename = "data/html/help/" + itemId + ".htm";
  46. String content = HtmCache.getInstance().getHtm(filename);
  47. if (content == null)
  48. {
  49. NpcHtmlMessage html = new NpcHtmlMessage(1);
  50. html.setHtml("<html><body>My Text is missing:<br>" + filename + "</body></html>");
  51. activeChar.sendPacket(html);
  52. }
  53. else
  54. {
  55. NpcHtmlMessage itemReply = new NpcHtmlMessage(5, itemId);
  56. itemReply.setHtml(content);
  57. activeChar.sendPacket(itemReply);
  58. }
  59. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  60. }
  61. /**
  62. *
  63. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  64. */
  65. public int[] getItemIds()
  66. {
  67. return ITEM_IDS;
  68. }
  69. }