Search in sources :

Example 31 with TargetPermanent

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

the class HeavenlyBlademasterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (sourcePermanent == null || player == null) {
        return false;
    }
    Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    target.getTargets().stream().map(attachmentId -> game.getPermanent(attachmentId)).filter(attachment -> attachment != null).forEachOrdered((attachment) -> {
        if (!sourcePermanent.cantBeAttachedBy(attachment, source, game, true)) {
            if (attachment.getAttachedTo() != sourcePermanent.getId()) {
                if (attachment.getAttachedTo() != null) {
                    Permanent fromPermanent = game.getPermanent(attachment.getAttachedTo());
                    if (fromPermanent != null) {
                        fromPermanent.removeAttachment(attachment.getId(), source, game);
                    }
                }
            }
            sourcePermanent.addAttachment(attachment.getId(), source, game);
            game.informPlayers(attachment.getLogName() + " was attached to " + sourcePermanent.getLogName());
        }
    });
    return true;
}
Also used : Target(mage.target.Target) SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) AuraAttachedCount(mage.abilities.dynamicvalue.common.AuraAttachedCount) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) DynamicValue(mage.abilities.dynamicvalue.DynamicValue) FlyingAbility(mage.abilities.keyword.FlyingAbility) mage.constants(mage.constants) StaticFilters(mage.filter.StaticFilters) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) DoubleStrikeAbility(mage.abilities.keyword.DoubleStrikeAbility) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) BoostControlledEffect(mage.abilities.effects.common.continuous.BoostControlledEffect) AdditiveDynamicValue(mage.abilities.dynamicvalue.AdditiveDynamicValue) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) EquipmentAttachedCount(mage.abilities.dynamicvalue.common.EquipmentAttachedCount) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 32 with TargetPermanent

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

the class LumberingBattlementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePerm = source.getSourcePermanentIfItStillExists(game);
    if (player == null || sourcePerm == null) {
        return false;
    }
    Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    if (!player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
        return false;
    }
    Set<Card> cards = new HashSet<>();
    for (UUID targetId : target.getTargets()) {
        Permanent permanent = game.getPermanent(targetId);
        if (permanent != null) {
            cards.add(permanent);
        }
    }
    return player.moveCardsToExile(cards, source, game, true, CardUtil.getCardExileZoneId(game, source), sourcePerm.getIdName());
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 33 with TargetPermanent

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

the class MultipleChoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    if (xValue == 1 || xValue >= 4) {
        controller.scry(1, source, game);
        controller.drawCards(1, source, game);
    }
    if (xValue == 3 || xValue >= 4) {
        new Elemental44Token().putOntoBattlefield(1, game, source, source.getControllerId());
    }
    if (xValue != 2 && xValue < 4) {
        return true;
    }
    TargetPlayer targetPlayer = new TargetPlayer(0, 1, true);
    controller.choose(Outcome.Detriment, targetPlayer, source.getSourceId(), game);
    Player player = game.getPlayer(targetPlayer.getFirstTarget());
    if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), player.getId(), game) <= 0) {
        return true;
    }
    TargetPermanent targetPermanent = new TargetControlledCreaturePermanent();
    targetPermanent.setNotTarget(true);
    player.choose(Outcome.ReturnToHand, targetPermanent, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
    return permanent == null || player.moveCards(permanent, Zone.HAND, source, game);
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) Elemental44Token(mage.game.permanent.token.Elemental44Token) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPlayer(mage.target.TargetPlayer)

Example 34 with TargetPermanent

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

the class OKagachiVengefulKamiWatcher method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player player = game.getPlayer(event.getTargetId());
    if (player == null || !((DamagedPlayerEvent) event).isCombatDamage() || !event.getSourceId().equals(getSourceId())) {
        return false;
    }
    this.getEffects().setValue("damagedPlayer", event.getTargetId());
    FilterPermanent filter = new FilterNonlandPermanent("nonland permanent controlled by " + player.getName());
    filter.add(new ControllerIdPredicate(event.getTargetId()));
    this.getTargets().clear();
    this.addTarget(new TargetPermanent(filter));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 35 with TargetPermanent

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

the class PrimordialMistCastFromExileEffect method pay.

@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
    Player controller = game.getPlayer(controllerId);
    if (controller != null) {
        if (target.choose(Outcome.Exile, controllerId, source.getSourceId(), game)) {
            Card card = game.getCard(source.getSourceId());
            if (card != null) {
                Permanent sourcePermanent = game.getPermanent(source.getSourceId());
                if (sourcePermanent != null) {
                    Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
                    Card targetCard = game.getCard(target.getFirstTarget());
                    if (targetPermanent != null && targetCard != null) {
                        String exileName = sourcePermanent.getIdName() + " <this card may be played the turn it was exiled>";
                        controller.moveCardsToExile(targetPermanent, source, game, true, source.getSourceId(), exileName);
                        targetPermanent.setFaceDown(false, game);
                        PrimordialMistCastFromExileEffect effect = new PrimordialMistCastFromExileEffect();
                        effect.setTargetPointer(new FixedTarget(targetCard.getId()));
                        game.addEffect(effect, ability);
                        this.setPaid();
                    }
                }
            }
            this.setPaid();
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) Card(mage.cards.Card)

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