Search in sources :

Example 51 with FilterCreaturePermanent

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

the class OverwhelmingStampedeInitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int maxPower = 0;
    for (Permanent perm : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
        if (perm.getPower().getValue() > maxPower) {
            maxPower = perm.getPower().getValue();
        }
    }
    ContinuousEffect effect = new GainAbilityControlledEffect(TrampleAbility.getInstance(), Duration.EndOfTurn, new FilterCreaturePermanent());
    game.addEffect(effect, source);
    if (maxPower != 0) {
        effect = new BoostControlledEffect(maxPower, maxPower, Duration.EndOfTurn);
        game.addEffect(effect, source);
    }
    return true;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GainAbilityControlledEffect(mage.abilities.effects.common.continuous.GainAbilityControlledEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect)

Example 52 with FilterCreaturePermanent

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

the class RetetherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<Card, Permanent> auraMap = new HashMap<>();
        auraCardsInGraveyard: for (Card aura : controller.getGraveyard().getCards(filterAura, source.getSourceId(), source.getControllerId(), game)) {
            if (aura != null) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent("creature to enchant (" + aura.getLogName() + ')');
                filter.add(new CanBeEnchantedByPredicate(aura));
                Target target = null;
                auraLegalitySearch: for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
                    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
                        if (permanent != null) {
                            for (Ability ability : aura.getAbilities()) {
                                if (ability instanceof SpellAbility) {
                                    for (Target abilityTarget : ability.getTargets()) {
                                        if (abilityTarget.possibleTargets(controller.getId(), game).contains(permanent.getId())) {
                                            target = abilityTarget.copy();
                                            break auraLegalitySearch;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (target != null) {
                    target.getFilter().add(CardType.CREATURE.getPredicate());
                    target.setNotTarget(true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                        target.setTargetName("creature to enchant (" + aura.getLogName() + ')');
                        if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                            Permanent permanent = game.getPermanent(target.getFirstTarget());
                            if (permanent != null && !permanent.cantBeAttachedBy(aura, source, game, true)) {
                                auraMap.put(aura, permanent);
                                game.getState().setValue("attachTo:" + aura.getId(), permanent);
                                continue auraCardsInGraveyard;
                            }
                        }
                    }
                }
                game.informPlayers("No valid creature targets for " + aura.getLogName());
            }
        }
        controller.moveCards(auraMap.keySet(), Zone.BATTLEFIELD, source, game);
        for (Entry<Card, Permanent> entry : auraMap.entrySet()) {
            Card aura = entry.getKey();
            Permanent permanent = entry.getValue();
            if (aura != null && permanent != null) {
                permanent.addAttachment(aura.getId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) HashMap(java.util.HashMap) SpellAbility(mage.abilities.SpellAbility) CanBeEnchantedByPredicate(mage.filter.predicate.permanent.CanBeEnchantedByPredicate) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 53 with FilterCreaturePermanent

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

the class SomnophoreTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        Player opponent = game.getPlayer(event.getPlayerId());
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
            filter.add(new ControllerIdPredicate(opponent.getId()));
            this.getTargets().clear();
            this.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)

Example 54 with FilterCreaturePermanent

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

the class WalkingDesecrationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player != null) {
        if (sourceObject != null) {
            Choice typeChoice = new ChoiceCreatureType(sourceObject);
            if (player.choose(outcome, typeChoice, game)) {
                game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
                FilterCreaturePermanent filter = new FilterCreaturePermanent();
                filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
                RequirementEffect effect = new AttacksIfAbleAllEffect(filter, Duration.EndOfTurn);
                game.addEffect(effect, source);
                return true;
            }
        }
    }
    return false;
}
Also used : RequirementEffect(mage.abilities.effects.RequirementEffect) Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) AttacksIfAbleAllEffect(mage.abilities.effects.common.combat.AttacksIfAbleAllEffect)

Example 55 with FilterCreaturePermanent

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

the class WallOfShadowsEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!event.getTargetId().equals(source.getSourceId())) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new BlockedByIdPredicate(source.getSourceId()));
    return permanent != null && filter.match(permanent, game);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

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