Search in sources :

Example 16 with TargetCreaturePermanent

use of mage.target.common.TargetCreaturePermanent 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)

Example 17 with TargetCreaturePermanent

use of mage.target.common.TargetCreaturePermanent in project mage by magefree.

the class MassMutinyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    for (Target target : source.getTargets()) {
        if (target instanceof TargetCreaturePermanent) {
            Permanent targetCreature = game.getPermanent(target.getFirstTarget());
            if (targetCreature != null) {
                ContinuousEffect effect1 = new GainControlTargetEffect(Duration.EndOfTurn);
                effect1.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
                game.addEffect(effect1, source);
                ContinuousEffect effect2 = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                effect2.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
                game.addEffect(effect2, source);
                targetCreature.untap(game);
                result = true;
            }
        }
    }
    return result;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 18 with TargetCreaturePermanent

use of mage.target.common.TargetCreaturePermanent in project mage by magefree.

the class MoltenPrimordialEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    for (Target target : source.getTargets()) {
        if (target instanceof TargetCreaturePermanent) {
            Permanent targetCreature = game.getPermanent(target.getFirstTarget());
            if (targetCreature != null) {
                ContinuousEffect effect1 = new GainControlTargetEffect(Duration.EndOfTurn);
                effect1.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
                game.addEffect(effect1, source);
                ContinuousEffect effect2 = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
                effect2.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
                game.addEffect(effect2, source);
                targetCreature.untap(game);
                result = true;
            }
        }
    }
    return result;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 19 with TargetCreaturePermanent

use of mage.target.common.TargetCreaturePermanent in project mage by magefree.

the class NecromancyChangeAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    Card cardInGraveyard = game.getCard(getTargetPointer().getFirst(game, source));
    if (controller != null && enchantment != null && cardInGraveyard != null) {
        controller.moveCards(cardInGraveyard, Zone.BATTLEFIELD, source, game);
        Permanent enchantedCreature = game.getPermanent(cardInGraveyard.getId());
        if (enchantedCreature != null) {
            enchantedCreature.addAttachment(enchantment.getId(), source, game);
            FilterCreaturePermanent filter = new FilterCreaturePermanent("enchant creature put onto the battlefield with " + enchantment.getIdName());
            filter.add(new PermanentIdPredicate(cardInGraveyard.getId()));
            Target target = new TargetCreaturePermanent(filter);
            target.addTarget(enchantedCreature.getId(), source, game);
            game.addEffect(new NecromancyChangeAbilityEffect(target), source);
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 20 with TargetCreaturePermanent

use of mage.target.common.TargetCreaturePermanent in project mage by magefree.

the class SkirkCommandoTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        Player player = game.getPlayer(event.getPlayerId());
        if (player != null) {
            getTargets().clear();
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature that player " + player.getName() + " controls");
            filter.add(new ControllerIdPredicate(event.getPlayerId()));
            addTarget(new TargetCreaturePermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Aggregations

TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)71 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)59 Player (mage.players.Player)49 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)37 Permanent (mage.game.permanent.Permanent)35 UUID (java.util.UUID)25 Target (mage.target.Target)18 FixedTarget (mage.target.targetpointer.FixedTarget)18 Effect (mage.abilities.effects.Effect)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)6 Card (mage.cards.Card)6 DamagedPlayerEvent (mage.game.events.DamagedPlayerEvent)6 ArrayList (java.util.ArrayList)5 Ability (mage.abilities.Ability)5 MageObject (mage.MageObject)4 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 RestrictionEffect (mage.abilities.effects.RestrictionEffect)3