Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Datapack -> handlers.skillhandlers.StealBuffs.java
- /*
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later
- * version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
- * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.skillhandlers;
- /*
- * This class is called when 'steal divinity' skill is used.
- * Each buff have its own chance to be stealed defined by the 'chance' variable
- * Buffs are chosen randomly from now, no more staling last buffs or dances
- * */
- import java.util.ArrayList;
- import java.util.logging.Level;
- import com.l2jserver.gameserver.handler.ISkillHandler;
- import com.l2jserver.gameserver.model.L2Effect;
- import com.l2jserver.gameserver.model.L2ItemInstance;
- import com.l2jserver.gameserver.model.L2Object;
- import com.l2jserver.gameserver.model.L2Skill;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.actor.L2Npc;
- import com.l2jserver.gameserver.model.actor.L2Summon;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.skills.Env;
- import com.l2jserver.gameserver.skills.Formulas;
- import com.l2jserver.gameserver.templates.skills.L2SkillType;
- import com.l2jserver.util.Rnd;
- public class StealBuffs implements ISkillHandler
- {
- private static final L2SkillType[] SKILL_IDS = { L2SkillType.STEAL_BUFF };
- /**
- *
- * @see com.l2jserver.gameserver.handler.ISkillHandler#useSkill(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.L2Skill, com.l2jserver.gameserver.model.L2Object[])
- */
- public void useSkill(L2Character activeChar, L2Skill skill, L2Object[] targets)
- {
- // discharge shots
- final L2ItemInstance weaponInst = activeChar.getActiveWeaponInstance();
- if (weaponInst != null)
- {
- if (skill.isMagic())
- {
- if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
- weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
- else if (weaponInst.getChargedSpiritshot() == L2ItemInstance.CHARGED_SPIRITSHOT)
- weaponInst.setChargedSpiritshot(L2ItemInstance.CHARGED_NONE);
- }
- }
- else if (activeChar instanceof L2Summon)
- {
- final L2Summon activeSummon = (L2Summon) activeChar;
- if (skill.isMagic())
- {
- if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_BLESSED_SPIRITSHOT)
- activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
- else if (activeSummon.getChargedSpiritShot() == L2ItemInstance.CHARGED_SPIRITSHOT)
- activeSummon.setChargedSpiritShot(L2ItemInstance.CHARGED_NONE);
- }
- }
- else if (activeChar instanceof L2Npc)
- ((L2Npc) activeChar)._spiritshotcharged = false;
- L2Character target;
- L2Effect effect;
- int count = (int) skill.getPower();
- // Chance for each buff to be stealed
- int chance = 70;
- for (L2Object obj : targets)
- {
- if (!(obj instanceof L2Character))
- continue;
- target = (L2Character) obj;
- if (target.isDead())
- continue;
- if (!(target instanceof L2PcInstance))
- continue;
- Env env;
- int lastSkillId = 0;
- final ArrayList<L2Effect> toSteal = new ArrayList<L2Effect>(count);
- final ArrayList<L2Effect> effects = new ArrayList<L2Effect>(target.getAllEffects().length);
- for (L2Effect eff : target.getAllEffects())
- {
- if (eff == null)
- continue;
- if (!eff.canBeStolen()) // Do not add effect if can't be stolen
- continue;
- // if eff time is smaller than 5 sec, will not be stolen, just to save CPU,
- // avoid synchronization(?) problems and NPEs
- if (eff.getAbnormalTime() - eff.getTime() < 5)
- continue;
- effects.add(eff);
- }
- while (count >= 0 && effects.size() > 0)
- {
- if (Rnd.get(1, 100) >= 100 - chance)
- {
- if (effects.size() >= (int) skill.getPower() - 1)
- {
- effect = effects.get(Rnd.get(1, effects.size() - 1));
- if (effect.getSkill().getId() != lastSkillId)
- {
- lastSkillId = effect.getSkill().getId();
- count--;
- toSteal.add(effect);
- }
- }
- else
- {
- if (effects.size() > 0)
- {
- for (L2Effect eff : effects)
- {
- toSteal.add(eff);
- count--;
- }
- }
- }
- }
- else
- count--;
- }
- if (toSteal.size() == 0)
- continue;
- // stealing effects
- for (L2Effect eff : toSteal)
- {
- env = new Env();
- env.player = target;
- env.target = activeChar;
- env.skill = eff.getSkill();
- try
- {
- effect = eff.getEffectTemplate().getStolenEffect(env, eff);
- if (effect != null)
- {
- effect.scheduleEffect();
- if (effect.getShowIcon() && activeChar instanceof L2PcInstance)
- {
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
- sm.addSkillName(effect);
- activeChar.sendPacket(sm);
- }
- }
- // Finishing stolen effect
- eff.exit();
- }
- catch (RuntimeException e)
- {
- _log.log(Level.WARNING, "Cannot steal effect: " + eff + " Stealer: " + activeChar + " Stolen: " + target, e);
- }
- }
- //Possibility of a lethal strike
- Formulas.calcLethalHit(activeChar, target, skill);
- }
- if (skill.hasSelfEffects())
- {
- // Applying self-effects
- effect = activeChar.getFirstEffect(skill.getId());
- if (effect != null && effect.isSelfEffect())
- {
- //Replace old effect with new one.
- effect.exit();
- }
- skill.getEffectsSelf(activeChar);
- }
- }
- /**
- *
- * @see com.l2jserver.gameserver.handler.ISkillHandler#getSkillIds()
- */
- public L2SkillType[] getSkillIds()
- {
- return SKILL_IDS;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement