L2SkillCreateItem.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 com.l2jserver.gameserver.skills.l2skills;
  16. import com.l2jserver.gameserver.model.L2Object;
  17. import com.l2jserver.gameserver.model.L2Skill;
  18. import com.l2jserver.gameserver.model.actor.L2Character;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. import com.l2jserver.gameserver.templates.StatsSet;
  23. import com.l2jserver.util.Rnd;
  24. /**
  25. * @author Nemesiss
  26. *
  27. */
  28. public class L2SkillCreateItem extends L2Skill
  29. {
  30. private final int[] _createItemId;
  31. private final int _createItemCount;
  32. private final int _randomCount;
  33. public L2SkillCreateItem(StatsSet set)
  34. {
  35. super(set);
  36. _createItemId = set.getIntegerArray("create_item_id");
  37. _createItemCount = set.getInteger("create_item_count", 0);
  38. _randomCount = set.getInteger("random_count", 1);
  39. }
  40. /**
  41. * @see com.l2jserver.gameserver.model.L2Skill#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Object[])
  42. */
  43. @Override
  44. public void useSkill(L2Character activeChar, L2Object[] targets)
  45. {
  46. if (activeChar.isAlikeDead())
  47. return;
  48. if (activeChar instanceof L2PcInstance)
  49. {
  50. if (_createItemId == null || _createItemCount == 0)
  51. {
  52. SystemMessage sm = new SystemMessage(SystemMessageId.S1_PREPARED_FOR_REUSE);
  53. sm.addSkillName(this);
  54. activeChar.sendPacket(sm);
  55. return;
  56. }
  57. int count = _createItemCount + Rnd.nextInt(_randomCount);
  58. int rndid = Rnd.nextInt(_createItemId.length);
  59. ((L2PcInstance)activeChar).addItem("Skill", _createItemId[rndid], count, activeChar, true);
  60. }
  61. }
  62. }