Search in sources :

Example 46 with Target

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

the class GripOfChaosEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(this.getTargetPointer().getFirst(game, source));
    if (stackObject != null) {
        for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
            Mode mode = stackObject.getStackAbility().getModes().get(modeId);
            for (Target target : mode.getTargets()) {
                UUID oldTargetId = target.getFirstTarget();
                Set<UUID> possibleTargets = target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game);
                if (possibleTargets.contains(stackObject.getId())) {
                    // The stackObject can't target itself
                    possibleTargets.remove(stackObject.getId());
                }
                if (!possibleTargets.isEmpty()) {
                    int i = 0;
                    int rnd = RandomUtil.nextInt(possibleTargets.size());
                    Iterator<UUID> it = possibleTargets.iterator();
                    while (i < rnd) {
                        it.next();
                        i++;
                    }
                    UUID newTargetId = it.next();
                    target.remove(oldTargetId);
                    target.add(newTargetId, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Mode(mage.abilities.Mode) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID)

Example 47 with Target

use of mage.target.Target 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 48 with Target

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

the class IwamoriOfTheOpenFistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl();
        for (UUID playerId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(playerId);
            Target target = new TargetCardInHand(filter);
            if (opponent != null && target.canChoose(source.getSourceId(), opponent.getId(), game)) {
                if (opponent.chooseUse(Outcome.PutCreatureInPlay, "Put a legendary creature card from your hand onto the battlefield?", source, game)) {
                    if (target.chooseTarget(Outcome.PutCreatureInPlay, opponent.getId(), source, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            cards.add(card);
                        }
                    }
                }
            }
        }
        controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard)

Example 49 with Target

use of mage.target.Target 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 50 with Target

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

the class MindBombEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Map<UUID, Cards> cardsToDiscard = new HashMap<>();
    // choose
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cards = new CardsImpl();
        Target target = new TargetDiscard(0, 3, new FilterCard(), playerId);
        player.chooseTarget(Outcome.Discard, target, source, game);
        cards.addAll(target.getTargets());
        cardsToDiscard.put(playerId, cards);
    }
    // discard
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            Cards cardsPlayer = cardsToDiscard.get(playerId);
            cardsToDiscard.put(playerId, player.discard(cardsPlayer, false, source, game));
        }
    }
    // damage
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Cards cardsPlayer = cardsToDiscard.get(playerId);
        if (cardsPlayer != null) {
            player.damage(3 - cardsPlayer.size(), source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) HashMap(java.util.HashMap) MageObject(mage.MageObject) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30