ChristmasTree.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 5560, /* x-mas tree */
  30. 5561 /* Special x-mas tree*/
  31. };
  32. private static final int[] NPC_IDS = {
  33. 13006, /* Christmas tree w. flashing lights and snow */
  34. 13007
  35. };
  36. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  37. {
  38. L2PcInstance activeChar = (L2PcInstance)playable;
  39. L2NpcTemplate template1 = null;
  40. int itemId = item.getItemId();
  41. for (int i = 0; i < ITEM_IDS.length; i++)
  42. {
  43. if (ITEM_IDS[i] == itemId)
  44. {
  45. template1 = NpcTable.getInstance().getTemplate(NPC_IDS[i]);
  46. break;
  47. }
  48. }
  49. if (template1 == null)
  50. return;
  51. L2Object target = activeChar.getTarget();
  52. if (target == null)
  53. target = activeChar;
  54. try
  55. {
  56. L2Spawn spawn = new L2Spawn(template1);
  57. spawn.setId(IdFactory.getInstance().getNextId());
  58. spawn.setLocx(target.getX());
  59. spawn.setLocy(target.getY());
  60. spawn.setLocz(target.getZ());
  61. L2World.getInstance().storeObject(spawn.spawnOne(false));
  62. activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false);
  63. activeChar.sendMessage("Created " + template1.name + " at x: " + spawn.getLocx() + " y: " + spawn.getLocy() + " z: " + spawn.getLocz());
  64. }
  65. catch (Exception e)
  66. {
  67. activeChar.sendMessage("Target is not ingame.");
  68. }
  69. }
  70. public int[] getItemIds()
  71. {
  72. return ITEM_IDS;
  73. }
  74. }