Search in sources :

Example 31 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class JangoFettEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(source.getSourceId());
    if (creature == null) {
        return false;
    }
    // Count the number of creatures attacked opponent controls with a bounty counter
    UUID defenderId = game.getCombat().getDefendingPlayerId(creature.getId(), game);
    int count = 0;
    if (defenderId != null) {
        FilterCreaturePermanent bountyFilter = new FilterCreaturePermanent("creatures defending player controls with a bounty counter");
        bountyFilter.add(CounterType.BOUNTY.getPredicate());
        count = game.getBattlefield().countAll(bountyFilter, defenderId, game);
    }
    if (count == 0) {
        return false;
    }
    game.addEffect(new BoostSourceEffect(count, 0, Duration.WhileOnBattlefield), source);
    return true;
}
Also used : BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetOpponentsCreaturePermanent(mage.target.common.TargetOpponentsCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID)

Example 32 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent 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 33 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class MassDiminishEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new ControllerIdPredicate(source.getFirstTarget()));
    game.addEffect(new SetPowerToughnessAllEffect(1, 1, Duration.UntilYourNextTurn, filter, true), source);
    return true;
}
Also used : SetPowerToughnessAllEffect(mage.abilities.effects.common.continuous.SetPowerToughnessAllEffect) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 34 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent 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 35 with FilterCreaturePermanent

use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.

the class NecroplasmEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player != null && sourcePermanent != null) {
        int numCounters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numCounters));
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            if (permanent != null) {
                permanent.destroy(source, game, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Aggregations

FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)187 Player (mage.players.Player)125 Permanent (mage.game.permanent.Permanent)108 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)83 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)67 UUID (java.util.UUID)55 TargetPermanent (mage.target.TargetPermanent)32 Target (mage.target.Target)31 FilterPermanent (mage.filter.FilterPermanent)27 FixedTarget (mage.target.targetpointer.FixedTarget)25 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)23 ContinuousEffect (mage.abilities.effects.ContinuousEffect)22 MageObject (mage.MageObject)16 PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)16 OneShotEffect (mage.abilities.effects.OneShotEffect)14 Effect (mage.abilities.effects.Effect)13 Choice (mage.choices.Choice)13 TargetPlayer (mage.target.TargetPlayer)13 Card (mage.cards.Card)12 ChoiceCreatureType (mage.choices.ChoiceCreatureType)12