Sweep.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.skillhandlers;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.handler.ISkillHandler;
  18. import net.sf.l2j.gameserver.model.L2Attackable;
  19. import net.sf.l2j.gameserver.model.L2Character;
  20. import net.sf.l2j.gameserver.model.L2ItemInstance;
  21. import net.sf.l2j.gameserver.model.L2Object;
  22. import net.sf.l2j.gameserver.model.L2Skill;
  23. import net.sf.l2j.gameserver.model.L2Skill.SkillType;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  25. import net.sf.l2j.gameserver.network.SystemMessageId;
  26. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  27. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  28. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  29. /**
  30. * @author _drunk_
  31. *
  32. * TODO To change the template for this generated type comment go to
  33. * Window - Preferences - Java - Code Style - Code Templates
  34. */
  35. public class Sweep implements ISkillHandler
  36. {
  37. //private static Logger _log = Logger.getLogger(Sweep.class.getName());
  38. private static final SkillType[] SKILL_IDS = {SkillType.SWEEP};
  39. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  40. {
  41. if (!(activeChar instanceof L2PcInstance))
  42. {
  43. return;
  44. }
  45. L2PcInstance player = (L2PcInstance)activeChar;
  46. InventoryUpdate iu = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
  47. boolean send = false;
  48. for(int index = 0;index < targets.length;index++)
  49. {
  50. if (!(targets[index] instanceof L2Attackable))
  51. continue;
  52. L2Attackable target = (L2Attackable)targets[index];
  53. L2Attackable.RewardItem[] items = null;
  54. boolean isSweeping = false;
  55. synchronized (target) {
  56. if (target.isSweepActive())
  57. {
  58. items = target.takeSweep();
  59. isSweeping = true;
  60. }
  61. }
  62. if (isSweeping)
  63. {
  64. if (items == null || items.length == 0)
  65. continue;
  66. for (L2Attackable.RewardItem ritem : items)
  67. {
  68. if (player.isInParty())
  69. player.getParty().distributeItem(player, ritem, true, target);
  70. else
  71. {
  72. L2ItemInstance item = player.getInventory().addItem("Sweep", ritem.getItemId(), ritem.getCount(), player, target);
  73. if (iu != null) iu.addItem(item);
  74. send = true;
  75. SystemMessage smsg;
  76. if (ritem.getCount() > 1)
  77. {
  78. smsg = new SystemMessage(SystemMessageId.EARNED_S2_S1_S); // earned $s2$s1
  79. smsg.addItemName(ritem.getItemId());
  80. smsg.addNumber(ritem.getCount());
  81. }
  82. else
  83. {
  84. smsg = new SystemMessage(SystemMessageId.EARNED_ITEM); // earned $s1
  85. smsg.addItemName(ritem.getItemId());
  86. }
  87. player.sendPacket(smsg);
  88. }
  89. }
  90. }
  91. target.endDecayTask();
  92. if (send)
  93. {
  94. if (iu != null)
  95. player.sendPacket(iu);
  96. else
  97. player.sendPacket(new ItemList(player, false));
  98. }
  99. }
  100. }
  101. public SkillType[] getSkillIds()
  102. {
  103. return SKILL_IDS;
  104. }
  105. }