Search in sources :

Example 26 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class CephalidConstableTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.sourceId) && ((DamagedPlayerEvent) event).isCombatDamage()) {
        FilterPermanent filter = new FilterPermanent("permanent" + (event.getAmount() > 1 ? "s" : "") + " damaged player control");
        filter.add(new ControllerIdPredicate(event.getPlayerId()));
        Target target = new TargetPermanent(0, event.getAmount(), filter, false);
        this.getTargets().clear();
        this.getTargets().add(target);
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 27 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DarkIntimationsReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> perms = new ArrayList<>();
    filter.add(TargetController.YOU.getControllerPredicate());
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            TargetPermanent target = new TargetPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Sacrifice, target, source, game);
                perms.addAll(target.getTargets());
            }
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            player.discardOne(false, false, source, game);
        }
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filterCard);
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && controller.choose(Outcome.ReturnToHand, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card == null) {
            return false;
        }
        controller.moveCards(card, Zone.HAND, source, game);
    }
    controller.drawCards(1, source, game);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 28 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class DoomForetoldEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(game.getActivePlayerId());
    if (controller == null || player == null) {
        return false;
    }
    FilterPermanent filter2 = filter.copy();
    filter2.add(new ControllerIdPredicate(player.getId()));
    if (game.getBattlefield().contains(filter2, source, game, 1)) {
        TargetPermanent target = new TargetPermanent(filter2);
        target.setNotTarget(true);
        if (player.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null && permanent.sacrifice(source, game)) {
                return true;
            }
        }
    }
    player.discard(1, false, false, source, game);
    player.loseLife(2, game, source, false);
    controller.drawCards(1, source, game);
    controller.gainLife(2, game, source);
    effect1.apply(game, source);
    effect2.apply(game, source);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent)

Example 29 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class EnigmaticIncarnationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Sacrifice an enchantment?", source, game)) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, filter, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    game.getState().processAction(game);
    int cmc = permanent.getManaValue();
    if (!permanent.sacrifice(source, game)) {
        return false;
    }
    FilterCard filterCard = new FilterCreatureCard("creature card with mana value " + (cmc + 1));
    filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc + 1));
    return new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(filterCard)).apply(game, source);
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) SearchLibraryPutInPlayEffect(mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect)

Example 30 with TargetPermanent

use of mage.target.TargetPermanent in project mage by magefree.

the class FaerieImpostorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Return another creature you control to its owner's hand?", source, game)) {
        controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            controller.moveCards(permanent, Zone.HAND, source, game);
            return true;
        }
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    return permanent != null && permanent.sacrifice(source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Aggregations

TargetPermanent (mage.target.TargetPermanent)222 Player (mage.players.Player)173 Permanent (mage.game.permanent.Permanent)167 FilterPermanent (mage.filter.FilterPermanent)108 UUID (java.util.UUID)65 Target (mage.target.Target)58 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)47 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)36 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)32 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)24 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)19 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)19 FixedTarget (mage.target.targetpointer.FixedTarget)19 MageObject (mage.MageObject)18 Ability (mage.abilities.Ability)18 Card (mage.cards.Card)17 ArrayList (java.util.ArrayList)15 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)14 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13