Spoil.java 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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.gameserver.ai.CtrlEvent;
  17. import net.sf.l2j.gameserver.handler.ISkillHandler;
  18. import net.sf.l2j.gameserver.model.L2Character;
  19. import net.sf.l2j.gameserver.model.L2Object;
  20. import net.sf.l2j.gameserver.model.L2Skill;
  21. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  22. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  23. import net.sf.l2j.gameserver.network.SystemMessageId;
  24. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  25. import net.sf.l2j.gameserver.skills.Formulas;
  26. import net.sf.l2j.gameserver.templates.L2SkillType;
  27. /**
  28. * @author _drunk_
  29. *
  30. */
  31. public class Spoil implements ISkillHandler
  32. {
  33. private static final L2SkillType[] SKILL_IDS =
  34. {
  35. L2SkillType.SPOIL
  36. };
  37. /**
  38. *
  39. * @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[])
  40. */
  41. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  42. {
  43. if (!(activeChar instanceof L2PcInstance))
  44. return;
  45. if (targets == null)
  46. return;
  47. for (int index = 0; index < targets.length; index++)
  48. {
  49. if (!(targets[index] instanceof L2MonsterInstance))
  50. continue;
  51. L2MonsterInstance target = (L2MonsterInstance) targets[index];
  52. if (target.isSpoil())
  53. {
  54. activeChar.sendPacket(new SystemMessage(SystemMessageId.ALREADY_SPOILED));
  55. continue;
  56. }
  57. // SPOIL SYSTEM by Lbaldi
  58. boolean spoil = false;
  59. if (target.isDead() == false)
  60. {
  61. spoil = Formulas.getInstance().calcMagicSuccess(activeChar, (L2Character) targets[index], skill);
  62. if (spoil)
  63. {
  64. target.setSpoil(true);
  65. target.setIsSpoiledBy(activeChar.getObjectId());
  66. activeChar.sendPacket(new SystemMessage(SystemMessageId.SPOIL_SUCCESS));
  67. }
  68. else
  69. {
  70. SystemMessage sm = new SystemMessage(SystemMessageId.S1_WAS_UNAFFECTED_BY_S2);
  71. sm.addCharName(target);
  72. sm.addSkillName(skill);
  73. activeChar.sendPacket(sm);
  74. }
  75. target.getAI().notifyEvent(CtrlEvent.EVT_ATTACKED, activeChar);
  76. }
  77. }
  78. }
  79. /**
  80. *
  81. * @see net.sf.l2j.gameserver.handler.ISkillHandler#getSkillIds()
  82. */
  83. public L2SkillType[] getSkillIds()
  84. {
  85. return SKILL_IDS;
  86. }
  87. }