Sweep.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.actor.instance.L2PcInstance;
  24. import net.sf.l2j.gameserver.network.SystemMessageId;
  25. import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
  26. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  27. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  28. import net.sf.l2j.gameserver.templates.L2SkillType;
  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 L2SkillType[] SKILL_IDS =
  39. {
  40. L2SkillType.SWEEP
  41. };
  42. /**
  43. *
  44. * @see net.sf.l2j.gameserver.handler.ISkillHandler#useSkill(net.sf.l2j.gameserver.model.L2Character, net.sf.l2j.gameserver.model.L2Skill, net.sf.l2j.gameserver.model.L2Object[])
  45. */
  46. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  47. {
  48. if (!(activeChar instanceof L2PcInstance))
  49. {
  50. return;
  51. }
  52. L2PcInstance player = (L2PcInstance) activeChar;
  53. InventoryUpdate iu = Config.FORCE_INVENTORY_UPDATE ? null : new InventoryUpdate();
  54. boolean send = false;
  55. for (int index = 0; index < targets.length; index++)
  56. {
  57. if (!(targets[index] instanceof L2Attackable))
  58. continue;
  59. L2Attackable target = (L2Attackable) targets[index];
  60. L2Attackable.RewardItem[] items = null;
  61. boolean isSweeping = false;
  62. synchronized (target)
  63. {
  64. if (target.isSweepActive())
  65. {
  66. items = target.takeSweep();
  67. isSweeping = true;
  68. }
  69. }
  70. if (isSweeping)
  71. {
  72. if (items == null || items.length == 0)
  73. continue;
  74. for (L2Attackable.RewardItem ritem : items)
  75. {
  76. if (player.isInParty())
  77. player.getParty().distributeItem(player, ritem, true, target);
  78. else
  79. {
  80. L2ItemInstance item = player.getInventory().addItem("Sweep", ritem.getItemId(), ritem.getCount(), player, target);
  81. if (iu != null)
  82. iu.addItem(item);
  83. send = true;
  84. SystemMessage smsg;
  85. if (ritem.getCount() > 1)
  86. {
  87. smsg = new SystemMessage(SystemMessageId.EARNED_S2_S1_S); // earned $s2$s1
  88. smsg.addItemName(ritem.getItemId());
  89. smsg.addNumber(ritem.getCount());
  90. }
  91. else
  92. {
  93. smsg = new SystemMessage(SystemMessageId.EARNED_ITEM); // earned $s1
  94. smsg.addItemName(ritem.getItemId());
  95. }
  96. player.sendPacket(smsg);
  97. }
  98. }
  99. }
  100. target.endDecayTask();
  101. if (send)
  102. {
  103. if (iu != null)
  104. player.sendPacket(iu);
  105. else
  106. player.sendPacket(new ItemList(player, false));
  107. }
  108. }
  109. }
  110. /**
  111. *
  112. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  113. */
  114. public L2SkillType[] getSkillIds()
  115. {
  116. return SKILL_IDS;
  117. }
  118. }