StealBuffs.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.skillhandlers;
  20. import java.util.List;
  21. import java.util.logging.Level;
  22. import com.l2jserver.gameserver.handler.ISkillHandler;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.ShotType;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.model.effects.L2Effect;
  27. import com.l2jserver.gameserver.model.skills.L2Skill;
  28. import com.l2jserver.gameserver.model.skills.L2SkillType;
  29. import com.l2jserver.gameserver.model.stats.Env;
  30. import com.l2jserver.gameserver.model.stats.Formulas;
  31. import com.l2jserver.gameserver.network.SystemMessageId;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. public class StealBuffs implements ISkillHandler
  34. {
  35. private static final L2SkillType[] SKILL_IDS =
  36. {
  37. L2SkillType.STEAL_BUFF
  38. };
  39. @Override
  40. public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
  41. {
  42. L2Character target;
  43. L2Effect effect;
  44. for (L2Object obj : targets)
  45. {
  46. if (!(obj instanceof L2Character))
  47. {
  48. continue;
  49. }
  50. target = (L2Character) obj;
  51. if (target.isDead())
  52. {
  53. continue;
  54. }
  55. if (!target.isPlayer())
  56. {
  57. continue;
  58. }
  59. Env env;
  60. final List<L2Effect> toSteal = Formulas.calcCancelStealEffects(activeChar, target, skill, skill.getPower());
  61. if (toSteal.size() == 0)
  62. {
  63. continue;
  64. }
  65. // stealing effects
  66. for (L2Effect eff : toSteal)
  67. {
  68. env = new Env();
  69. env.setCharacter(target);
  70. env.setTarget(activeChar);
  71. env.setSkill(eff.getSkill());
  72. try
  73. {
  74. effect = eff.getEffectTemplate().getStolenEffect(env, eff);
  75. if (effect != null)
  76. {
  77. effect.scheduleEffect();
  78. if (effect.isIconDisplay() && activeChar.isPlayer())
  79. {
  80. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  81. sm.addSkillName(effect);
  82. activeChar.sendPacket(sm);
  83. }
  84. }
  85. // Finishing stolen effect
  86. eff.exit();
  87. }
  88. catch (RuntimeException e)
  89. {
  90. _log.log(Level.WARNING, "Cannot steal effect: " + eff + " Stealer: " + activeChar + " Stolen: " + target, e);
  91. }
  92. }
  93. }
  94. if (skill.hasSelfEffects())
  95. {
  96. // Applying self-effects
  97. effect = activeChar.getFirstEffect(skill.getId());
  98. if ((effect != null) && effect.isSelfEffect())
  99. {
  100. // Replace old effect with new one.
  101. effect.exit();
  102. }
  103. skill.getEffectsSelf(activeChar);
  104. }
  105. activeChar.setChargedShot(activeChar.isChargedShot(ShotType.BLESSED_SPIRITSHOTS) ? ShotType.BLESSED_SPIRITSHOTS : ShotType.SPIRITSHOTS, false);
  106. }
  107. @Override
  108. public L2SkillType[] getSkillIds()
  109. {
  110. return SKILL_IDS;
  111. }
  112. }