L2SkillCreateItem.java 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.skills.l2skills;
  16. import net.sf.l2j.gameserver.idfactory.IdFactory;
  17. import net.sf.l2j.gameserver.model.L2ItemInstance;
  18. import net.sf.l2j.gameserver.model.L2Object;
  19. import net.sf.l2j.gameserver.model.L2Skill;
  20. import net.sf.l2j.gameserver.model.actor.L2Character;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  22. import net.sf.l2j.gameserver.network.SystemMessageId;
  23. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  24. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.templates.StatsSet;
  26. import net.sf.l2j.util.Rnd;
  27. /**
  28. * @author Nemesiss
  29. *
  30. */
  31. public class L2SkillCreateItem extends L2Skill
  32. {
  33. private final int[] _createItemId;
  34. private final int _createItemCount;
  35. private final int _randomCount;
  36. public L2SkillCreateItem(StatsSet set)
  37. {
  38. super(set);
  39. _createItemId = set.getIntegerArray("create_item_id");
  40. _createItemCount = set.getInteger("create_item_count", 0);
  41. _randomCount = set.getInteger("random_count", 1);
  42. }
  43. /**
  44. * @see net.sf.l2j.gameserver.model.L2Skill#useSkill(net.sf.l2j.gameserver.model.actor.L2Character, net.sf.l2j.gameserver.model.L2Object[])
  45. */
  46. @Override
  47. public void useSkill(L2Character activeChar, L2Object[] targets)
  48. {
  49. if (activeChar.isAlikeDead()) return;
  50. if (_createItemId == null || _createItemCount == 0)
  51. {
  52. SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
  53. activeChar.sendPacket(sm);
  54. return;
  55. }
  56. L2PcInstance player = (L2PcInstance) activeChar;
  57. if (activeChar instanceof L2PcInstance)
  58. {
  59. int rnd = Rnd.nextInt(_randomCount) + 1;
  60. int count = _createItemCount * rnd;
  61. int rndid = Rnd.nextInt(_createItemId.length);
  62. giveItems(player, _createItemId[rndid], count);
  63. }
  64. }
  65. /**
  66. * @param activeChar
  67. * @param itemId
  68. * @param count
  69. */
  70. public void giveItems(L2PcInstance activeChar, int itemId, int count)
  71. {
  72. L2ItemInstance item = new L2ItemInstance(IdFactory.getInstance().getNextId(), itemId);
  73. if (item == null) return;
  74. item.setCount(count);
  75. activeChar.getInventory().addItem("Skill", item, activeChar, activeChar);
  76. if (count > 1)
  77. {
  78. SystemMessage smsg = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
  79. smsg.addItemName(item);
  80. smsg.addItemNumber(count);
  81. activeChar.sendPacket(smsg);
  82. }
  83. else
  84. {
  85. SystemMessage smsg = new SystemMessage(SystemMessageId.EARNED_ITEM);
  86. smsg.addItemName(item);
  87. activeChar.sendPacket(smsg);
  88. }
  89. ItemList il = new ItemList(activeChar, false);
  90. activeChar.sendPacket(il);
  91. }
  92. }