ChristmasTree.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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.datatables.NpcTable;
  17. import net.sf.l2j.gameserver.handler.IItemHandler;
  18. import net.sf.l2j.gameserver.idfactory.IdFactory;
  19. import net.sf.l2j.gameserver.model.L2ItemInstance;
  20. import net.sf.l2j.gameserver.model.L2Object;
  21. import net.sf.l2j.gameserver.model.L2Spawn;
  22. import net.sf.l2j.gameserver.model.L2World;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  25. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  26. public class ChristmasTree implements IItemHandler
  27. {
  28. private static final int[] ITEM_IDS =
  29. {
  30. 5560, /* x-mas tree */
  31. 5561 /* Special x-mas tree*/
  32. };
  33. private static final int[] NPC_IDS =
  34. {
  35. 13006, /* Christmas tree w. flashing lights and snow */
  36. 13007
  37. };
  38. /**
  39. *
  40. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  41. */
  42. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  43. {
  44. L2PcInstance activeChar = (L2PcInstance) playable;
  45. L2NpcTemplate template1 = null;
  46. int itemId = item.getItemId();
  47. for (int i = 0; i < ITEM_IDS.length; i++)
  48. {
  49. if (ITEM_IDS[i] == itemId)
  50. {
  51. template1 = NpcTable.getInstance().getTemplate(NPC_IDS[i]);
  52. break;
  53. }
  54. }
  55. if (template1 == null)
  56. return;
  57. L2Object target = activeChar.getTarget();
  58. if (target == null)
  59. target = activeChar;
  60. try
  61. {
  62. L2Spawn spawn = new L2Spawn(template1);
  63. spawn.setId(IdFactory.getInstance().getNextId());
  64. spawn.setLocx(target.getX());
  65. spawn.setLocy(target.getY());
  66. spawn.setLocz(target.getZ());
  67. L2World.getInstance().storeObject(spawn.spawnOne(false));
  68. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  69. activeChar.sendMessage("Created " + template1.name + " at x: " + spawn.getLocx() + " y: " + spawn.getLocy() + " z: " + spawn.getLocz());
  70. }
  71. catch (Exception e)
  72. {
  73. activeChar.sendMessage("Target is not ingame.");
  74. }
  75. }
  76. /**
  77. *
  78. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  79. */
  80. public int[] getItemIds()
  81. {
  82. return ITEM_IDS;
  83. }
  84. }