Search in sources :

Example 71 with TargetControlledCreaturePermanent

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

the class AcererakTheArchlichEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int tokens = 0;
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        tokens++;
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        TargetPermanent target = new TargetControlledCreaturePermanent(0, 1);
        target.setNotTarget(true);
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null && permanent.sacrifice(source, game)) {
            tokens--;
        }
    }
    if (tokens > 0) {
        new ZombieToken().putOntoBattlefield(tokens, game, source, source.getControllerId());
    }
    return true;
}
Also used : Player(mage.players.Player) ZombieToken(mage.game.permanent.token.ZombieToken) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 72 with TargetControlledCreaturePermanent

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

the class BreathOfFuryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (enchantment == null) {
        return false;
    }
    Permanent enchantedCreature = game.getPermanent((UUID) getValue("TriggeringCreatureId"));
    Player controller = game.getPlayer(source.getControllerId());
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature you control that could be enchanted by " + enchantment.getName());
    filter.add(new CanBeEnchantedByPredicate(enchantment));
    Target target = new TargetControlledCreaturePermanent(filter);
    target.setNotTarget(true);
    // Commanders going to the command zone and Rest in Peace style replacement effects don't make Permanent.sacrifice return false.
    if (enchantedCreature != null && controller != null && enchantedCreature.sacrifice(source, game) && target.canChoose(source.getSourceId(), controller.getId(), game)) {
        controller.choose(outcome, target, source.getSourceId(), game);
        Permanent newCreature = game.getPermanent(target.getFirstTarget());
        boolean success = false;
        if (newCreature != null) {
            Permanent oldCreature = game.getPermanent(enchantment.getAttachedTo());
            if (oldCreature != null) {
                if (oldCreature.getId().equals(newCreature.getId())) {
                    success = true;
                } else {
                    if (oldCreature.removeAttachment(enchantment.getId(), source, game) && newCreature.addAttachment(enchantment.getId(), source, game)) {
                        game.informPlayers(enchantment.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + newCreature.getLogName());
                        success = true;
                    }
                }
            } else if (newCreature.addAttachment(enchantment.getId(), source, game)) {
                game.informPlayers(enchantment.getLogName() + " was attached to " + newCreature.getLogName());
                success = true;
            }
        }
        if (success) {
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), controller.getId(), game)) {
                permanent.untap(game);
            }
            game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), TurnPhase.COMBAT, null, false));
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TurnMod(mage.game.turn.TurnMod) CanBeEnchantedByPredicate(mage.filter.predicate.permanent.CanBeEnchantedByPredicate) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 73 with TargetControlledCreaturePermanent

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

the class BreenaTheDemagogueEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    return permanent != null && permanent.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 74 with TargetControlledCreaturePermanent

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

the class CrashingBoarsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player defendingPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (defendingPlayer != null) {
        Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
        if (target.choose(Outcome.Neutral, defendingPlayer.getId(), source.getSourceId(), game)) {
            RequirementEffect effect = new MustBeBlockedByTargetSourceEffect();
            effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) RequirementEffect(mage.abilities.effects.RequirementEffect) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) MustBeBlockedByTargetSourceEffect(mage.abilities.effects.common.combat.MustBeBlockedByTargetSourceEffect)

Example 75 with TargetControlledCreaturePermanent

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

the class BrainGorgersCounterSourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null) {
        SacrificeTargetCost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent(FILTER_CONTROLLED_CREATURE_SHORT_TEXT));
        for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) {
            cost.clearPaid();
            Player player = game.getPlayer(playerId);
            if (player != null && cost.canPay(source, source, player.getId(), game) && player.chooseUse(outcome, "Sacrifice a creature to counter " + sourceObject.getIdName() + '?', source, game)) {
                if (cost.pay(source, game, source, player.getId(), false, null)) {
                    game.informPlayers(player.getLogName() + " sacrifices a creature to counter " + sourceObject.getIdName() + '.');
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        game.getStack().counter(spell.getId(), source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Spell(mage.game.stack.Spell)

Aggregations

TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)78 Player (mage.players.Player)73 Permanent (mage.game.permanent.Permanent)64 Target (mage.target.Target)41 UUID (java.util.UUID)29 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)27 TargetPermanent (mage.target.TargetPermanent)18 ArrayList (java.util.ArrayList)14 Cost (mage.abilities.costs.Cost)10 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)8 FixedTarget (mage.target.targetpointer.FixedTarget)8 Ability (mage.abilities.Ability)6 FilterPermanent (mage.filter.FilterPermanent)6 MageObject (mage.MageObject)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)5 OneShotEffect (mage.abilities.effects.OneShotEffect)4 Card (mage.cards.Card)4 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3