Search in sources :

Example 1 with AttacksIfAbleTargetEffect

use of mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect in project mage by magefree.

the class BorosBattleshaperEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature1 = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (creature1 != null) {
        if (game.getOpponents(creature1.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new BlocksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(BlocksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
            effect = new GainAbilityTargetEffect(AttacksThisTurnMarkerAbility.getInstance(), Duration.EndOfTurn, "");
            effect.setTargetPointer(new FixedTarget(creature1.getId(), game));
            game.addEffect(effect, source);
        }
    }
    Permanent creature2 = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (creature2 != null) {
        if (game.getOpponents(creature2.getControllerId()).contains(game.getActivePlayerId())) {
            // Blocks
            ContinuousEffectImpl effect = new CantBlockTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        } else {
            // Attacks
            ContinuousEffectImpl effect = new CantAttackTargetEffect(Duration.EndOfTurn);
            effect.setTargetPointer(new FixedTarget(creature2.getId(), game));
            game.addEffect(effect, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) CantAttackTargetEffect(mage.abilities.effects.common.combat.CantAttackTargetEffect) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BlocksIfAbleTargetEffect(mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect) CantBlockTargetEffect(mage.abilities.effects.common.combat.CantBlockTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffectImpl(mage.abilities.effects.ContinuousEffectImpl) AttacksIfAbleTargetEffect(mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)

Example 2 with AttacksIfAbleTargetEffect

use of mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect in project mage by magefree.

the class ChemistersTrickEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_CREATURE_YOU_DONT_CONTROL, source.getControllerId(), source.getSourceId(), game)) {
        AttacksIfAbleTargetEffect effect = new AttacksIfAbleTargetEffect(Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) AttacksIfAbleTargetEffect(mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)

Example 3 with AttacksIfAbleTargetEffect

use of mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect in project mage by magefree.

the class MasterWarcraftChooseAttackersEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!ControlCombatRedundancyWatcher.checkAttackingController(source.getControllerId(), game)) {
        game.informPlayers(source.getSourceObject(game).getIdName() + " didn't apply");
        return false;
    }
    Player controller = game.getPlayer(source.getControllerId());
    Player attackingPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
    if (controller == null || attackingPlayer == null || attackingPlayer.getAvailableAttackers(game).isEmpty()) {
        // the attack declaration resumes for the active player as normal
        return false;
    }
    Target target = new TargetCreaturePermanent(0, Integer.MAX_VALUE, filter, true);
    if (!controller.chooseTarget(Outcome.Benefit, target, source, game)) {
        // the attack declaration resumes for the active player as normal
        return false;
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game)) {
        // Choose creatures that will be attacking this combat
        if (target.getTargets().contains(permanent.getId())) {
            RequirementEffect effect = new AttacksIfAbleTargetEffect(Duration.EndOfCombat);
            effect.setText("");
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
            game.informPlayers(controller.getLogName() + " has decided that " + permanent.getLogName() + " attacks this combat if able");
        // All other creatures can't attack (unless they must attack)
        } else {
            boolean hasToAttack = false;
            for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(permanent, false, game).entrySet()) {
                RequirementEffect effect2 = entry.getKey();
                if (effect2.mustAttack(game)) {
                    hasToAttack = true;
                }
            }
            if (!hasToAttack) {
                RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfCombat);
                effect.setText("");
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
    }
    // the attack declaration resumes for the active player as normal
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Set(java.util.Set) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) AttacksIfAbleTargetEffect(mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect) CantAttackTargetEffect(mage.abilities.effects.common.combat.CantAttackTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) RequirementEffect(mage.abilities.effects.RequirementEffect) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Map(java.util.Map) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Aggregations

AttacksIfAbleTargetEffect (mage.abilities.effects.common.combat.AttacksIfAbleTargetEffect)3 Permanent (mage.game.permanent.Permanent)3 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 CantAttackTargetEffect (mage.abilities.effects.common.combat.CantAttackTargetEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 Map (java.util.Map)1 Set (java.util.Set)1 ContinuousEffectImpl (mage.abilities.effects.ContinuousEffectImpl)1 RequirementEffect (mage.abilities.effects.RequirementEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 BlocksIfAbleTargetEffect (mage.abilities.effects.common.combat.BlocksIfAbleTargetEffect)1 CantBlockTargetEffect (mage.abilities.effects.common.combat.CantBlockTargetEffect)1 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)1 Player (mage.players.Player)1 Target (mage.target.Target)1