Search in sources :

Example 76 with Target

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

the class DescentOfTheDragonsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Map<UUID, Integer> playersWithTargets = new HashMap<>();
        for (Target target : source.getTargets()) {
            for (UUID permanentId : target.getTargets()) {
                Permanent permanent = game.getPermanent(permanentId);
                if (permanent != null) {
                    UUID controllerOfTargetId = permanent.getControllerId();
                    if (permanent.destroy(source, game, false)) {
                        int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0);
                        playersWithTargets.put(controllerOfTargetId, count + 1);
                    }
                }
            }
        }
        DragonToken dragonToken = new DragonToken();
        for (Map.Entry<UUID, Integer> amountTokensPerPlayer : playersWithTargets.entrySet()) {
            dragonToken.putOntoBattlefield(amountTokensPerPlayer.getValue(), game, source, amountTokensPerPlayer.getKey());
        }
        return true;
    }
    return false;
}
Also used : DragonToken(mage.game.permanent.token.DragonToken) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HashMap(java.util.HashMap) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 77 with Target

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

the class EurekaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        PlayerList playerList = game.getState().getPlayerList().copy();
        while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
            playerList.getNext();
        }
        Player currentPlayer = game.getPlayer(playerList.get());
        UUID firstInactivePlayer = null;
        Target target = new TargetCardInHand(new FilterPermanentCard());
        while (controller.canRespond()) {
            if (firstInactivePlayer == null) {
                firstInactivePlayer = currentPlayer.getId();
            }
            if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
                target.clearChosen();
                if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
                    if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
                        Card card = game.getCard(target.getFirstTarget());
                        if (card != null) {
                            currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
                            firstInactivePlayer = null;
                        }
                    }
                }
            }
            // get next player
            playerList.getNext();
            currentPlayer = game.getPlayer(playerList.get());
            // if all player since this player didn't put permanent in play finish the process
            if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
                break;
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterPermanentCard(mage.filter.common.FilterPermanentCard) PlayerList(mage.players.PlayerList) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 78 with Target

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

the class EvolutionaryEscalationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Counter counter = CounterType.P1P1.createInstance(3);
    boolean addedCounters = false;
    for (Target target : source.getTargets()) {
        Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
        if (targetPermanent != null) {
            targetPermanent.addCounters(counter.copy(), source.getControllerId(), source, game);
            addedCounters = true;
        }
    }
    return addedCounters;
}
Also used : Target(mage.target.Target) Counter(mage.counters.Counter) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 79 with Target

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

the class FumbleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (player == null || permanent == null) {
        return false;
    }
    List<Permanent> attachments = new ArrayList<>();
    for (UUID permId : permanent.getAttachments()) {
        Permanent attachment = game.getPermanent(permId);
        if (attachment != null) {
            if (attachment.hasSubtype(SubType.AURA, game) || attachment.hasSubtype(SubType.EQUIPMENT, game)) {
                attachments.add(attachment);
            }
        }
    }
    new ReturnToHandTargetEffect().apply(game, source);
    if (!attachments.isEmpty()) {
        Target target = new TargetCreaturePermanent(1, 1, StaticFilters.FILTER_PERMANENT_CREATURE, true);
        Permanent newCreature = null;
        if (player.choose(Outcome.BoostCreature, target, source.getSourceId(), game)) {
            newCreature = game.getPermanent(target.getFirstTarget());
        }
        for (Permanent attachment : attachments) {
            if (!attachment.hasSubtype(SubType.AURA, game) && !attachment.hasSubtype(SubType.EQUIPMENT, game)) {
                continue;
            }
            ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, player.getId());
            effect.setTargetPointer(new FixedTarget(attachment, game));
            game.addEffect(effect, source);
            if (newCreature != null) {
                attachment.attachTo(newCreature.getId(), source, game);
            }
        }
    }
    return true;
}
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) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ArrayList(java.util.ArrayList) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 80 with Target

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

the class GoblinVandalTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent sourcePermanent = game.getPermanent(getSourceId());
    if (sourcePermanent.isAttacking()) {
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
                UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
                FilterPermanent filter = new FilterArtifactPermanent();
                filter.add(new ControllerIdPredicate(defendingPlayerId));
                Target target = new TargetPermanent(filter);
                this.addTarget(target);
                return true;
            }
        }
    }
    return false;
}
Also used : FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterArtifactPermanent(mage.filter.common.FilterArtifactPermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup)

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