Search in sources :

Example 56 with TargetCreaturePermanent

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

the class GrenzoHavocRaiserEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    this.damagedPlayerName = null;
    this.getEffects().get(0).setText(GrenzoHavocRaiser.goadEffectName);
    Player damagedPlayer = game.getPlayer(event.getPlayerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
    Permanent abilitySourcePermanent = this.getSourcePermanentIfItStillExists(game);
    if (damagedPlayer == null || permanent == null || abilitySourcePermanent == null) {
        return false;
    }
    if (((DamagedEvent) event).isCombatDamage() && isControlledBy(permanent.getControllerId())) {
        this.damagedPlayerName = damagedPlayer.getLogName();
        this.getEffects().get(0).setText(GrenzoHavocRaiser.goadEffectName + " (" + this.damagedPlayerName + ")");
        game.informPlayers(abilitySourcePermanent.getLogName() + " triggered for damaged " + this.damagedPlayerName);
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + damagedPlayer.getLogName() + " controls");
        filter.add(new ControllerIdPredicate(damagedPlayer.getId()));
        this.getTargets().clear();
        this.addTarget(new TargetCreaturePermanent(filter));
        for (Effect effect : this.getAllEffects()) {
            if (effect instanceof GrenzoHavocRaiserEffect) {
                effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
                effect.setValue("damage", event.getAmount());
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) GoadTargetEffect(mage.abilities.effects.common.combat.GoadTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect)

Example 57 with TargetCreaturePermanent

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

the class MordantDragonEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    Player opponent = game.getPlayer(event.getPlayerId());
    if (!damageEvent.isCombatDamage() || !event.getSourceId().equals(this.getSourceId()) || opponent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
    filter.add(new ControllerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCreaturePermanent(filter));
    for (Effect effect : this.getAllEffects()) {
        effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
        effect.setValue("damage", event.getAmount());
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) BoostSourceEffect(mage.abilities.effects.common.continuous.BoostSourceEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 58 with TargetCreaturePermanent

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

the class SereneMasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceCreature = game.getPermanent(source.getSourceId());
    if (controller != null && sourceCreature != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature it's blocking");
        filter.add(new BlockedByIdPredicate((source.getSourceId())));
        Target target = new TargetCreaturePermanent(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            if (controller.chooseTarget(outcome, target, source, game)) {
                Permanent attackingCreature = game.getPermanent(target.getFirstTarget());
                if (attackingCreature != null) {
                    int newSourcePower = attackingCreature.getPower().getValue();
                    int newAttackerPower = sourceCreature.getPower().getValue();
                    ContinuousEffect effect = new SetPowerToughnessTargetEffect(newSourcePower, sourceCreature.getToughness().getValue(), Duration.EndOfCombat);
                    effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
                    game.addEffect(effect, source);
                    effect = new SetPowerToughnessTargetEffect(newAttackerPower, attackingCreature.getToughness().getValue(), Duration.EndOfCombat);
                    effect.setTargetPointer(new FixedTarget(attackingCreature.getId(), game));
                    game.addEffect(effect, source);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SetPowerToughnessTargetEffect(mage.abilities.effects.common.continuous.SetPowerToughnessTargetEffect) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

Example 59 with TargetCreaturePermanent

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

the class SpyNetworkFaceDownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller != null && player != null && mageObject != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("face down creature controlled by " + player.getLogName());
        filter.add(FaceDownPredicate.instance);
        filter.add(new ControllerIdPredicate(player.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (controller.chooseUse(outcome, "Look at a face down creature controlled by " + player.getLogName() + "?", source, game)) {
                target.clearChosen();
                while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                    controller.chooseTarget(outcome, target, source, game);
                }
                Permanent faceDownCreature = game.getPermanent(target.getFirstTarget());
                if (faceDownCreature != null) {
                    Permanent copyFaceDown = faceDownCreature.copy();
                    copyFaceDown.setFaceDown(false, game);
                    Cards cards = new CardsImpl(copyFaceDown);
                    controller.lookAtCards("face down card - " + mageObject.getName(), cards, game);
                    game.informPlayers(controller.getLogName() + " looks at a face down creature controlled by " + player.getLogName());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 60 with TargetCreaturePermanent

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

the class SplitThePartyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || targetPlayer == null) {
        return false;
    }
    int numCreatures = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game);
    if (numCreatures > 0) {
        int halfCreatures = (numCreatures / 2) + (numCreatures % 2);
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures controlled by " + targetPlayer.getName());
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        TargetCreaturePermanent target = new TargetCreaturePermanent(halfCreatures, halfCreatures, filter, true);
        if (controller.chooseTarget(outcome, target, source, game)) {
            Set<Card> cardsToHand = new HashSet<>();
            for (UUID creatureId : target.getTargets()) {
                Card card = game.getPermanent(creatureId);
                if (card != null) {
                    cardsToHand.add(card);
                }
            }
            controller.moveCards(cardsToHand, Zone.HAND, source, game);
        }
    }
    return true;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID) Card(mage.cards.Card) HashSet(java.util.HashSet)

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