Search in sources :

Example 66 with TargetCreaturePermanent

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

the class ColossalWhaleExileEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defenderId = game.getCombat().getDefenderId(sourceId);
        filter.add(new ControllerIdPredicate(defenderId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 67 with TargetCreaturePermanent

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

the class ArmWithAetherTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player opponent = game.getPlayer(event.getPlayerId());
    if (opponent != null && event.getSourceId().equals(this.sourceId)) {
        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 68 with TargetCreaturePermanent

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

the class CulturalExchangeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player1 = game.getPlayer(targetPointer.getTargets(game, source).get(0));
    Player player2 = game.getPlayer(targetPointer.getTargets(game, source).get(1));
    Player controller = game.getPlayer(source.getControllerId());
    if (player1 == null || player2 == null || controller == null) {
        return false;
    }
    FilterCreaturePermanent filter1 = new FilterCreaturePermanent("creatures " + player1.getLogName() + " controls");
    FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creatures " + player2.getLogName() + " controls");
    filter1.add(new ControllerIdPredicate(player1.getId()));
    filter2.add(new ControllerIdPredicate(player2.getId()));
    int creatureCount1 = game.getBattlefield().count(filter1, source.getSourceId(), source.getControllerId(), game);
    int creatureCount2 = game.getBattlefield().count(filter2, source.getSourceId(), source.getControllerId(), game);
    int creaturesToSwitch = Math.min(creatureCount1, creatureCount2);
    if (creaturesToSwitch == 0) {
        return true;
    }
    TargetCreaturePermanent target1 = new TargetCreaturePermanent(0, creaturesToSwitch, filter1, true);
    if (target1.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
        int otherToSwitch = target1.getTargets().size();
        TargetCreaturePermanent target2 = new TargetCreaturePermanent(otherToSwitch, otherToSwitch, filter2, true);
        if (target2.choose(Outcome.Benefit, controller.getId(), source.getSourceId(), game)) {
            for (UUID creatureId : target1.getTargets()) {
                Permanent creature = game.getPermanent(creatureId);
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player2.getId());
                    game.informPlayers(player2.getLogName() + " gains control of " + creature.getLogName());
                    effect.setTargetPointer(new FixedTarget(creature, game));
                    game.addEffect(effect, source);
                }
            }
            for (UUID creatureId : target2.getTargets()) {
                Permanent creature = game.getPermanent(creatureId);
                if (creature != null) {
                    ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, player1.getId());
                    game.informPlayers(player1.getLogName() + " gains control of " + creature.getLogName());
                    effect.setTargetPointer(new FixedTarget(creature, game));
                    game.addEffect(effect, source);
                }
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) 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) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 69 with TargetCreaturePermanent

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

the class AzraOddsmakerDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Permanent permanent = null;
    TargetCreaturePermanent target = new TargetCreaturePermanent();
    target.setNotTarget(true);
    if (player.choose(Outcome.DrawCard, target, source.getSourceId(), game)) {
        permanent = game.getPermanent(target.getFirstTarget());
    }
    if (permanent == null) {
        return false;
    }
    game.addDelayedTriggeredAbility(new AzraOddsmakerDelayedTriggeredAbility(new MageObjectReference(permanent, game), permanent.getName()), source);
    return true;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObjectReference(mage.MageObjectReference)

Example 70 with TargetCreaturePermanent

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

the class CherishedHatchlingTriggeredAbility method getEffectToAdd.

private static Effect getEffectToAdd() {
    Ability abilityToAdd = new EntersBattlefieldTriggeredAbility(new FightTargetSourceEffect().setText("you may have it fight another target creature"), true);
    abilityToAdd.addTarget(new TargetCreaturePermanent(filter));
    Effect effect = new GainAbilityTargetEffect(abilityToAdd, Duration.EndOfTurn, "it gains \"When this creature enters the battlefield, you may have it fight another target creature.\"", true);
    return effect;
}
Also used : EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) DiesSourceTriggeredAbility(mage.abilities.common.DiesSourceTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) CastAsThoughItHadFlashAllEffect(mage.abilities.effects.common.continuous.CastAsThoughItHadFlashAllEffect) Effect(mage.abilities.effects.Effect) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect)

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