Search in sources :

Example 81 with TargetPlayer

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

the class PsychicSpiralEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (controller != null && targetPlayer != null) {
        int cardsInGraveyard = controller.getGraveyard().size();
        controller.shuffleCardsToLibrary(controller.getGraveyard(), game, source);
        if (cardsInGraveyard > 0) {
            targetPlayer.millCards(cardsInGraveyard, source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 82 with TargetPlayer

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

the class SupremeInquisitorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player player = game.getPlayer(source.getControllerId());
    if (player != null && targetPlayer != null) {
        TargetCardInLibrary target = new TargetCardInLibrary(0, 5, filter);
        if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
            List<UUID> targetId = target.getTargets();
            for (UUID targetCard : targetId) {
                Card card = targetPlayer.getLibrary().remove(targetCard, game);
                if (card != null) {
                    player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
                }
            }
        }
        targetPlayer.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 83 with TargetPlayer

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

the class TormentedThoughtsDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        int power = 0;
        COSTS: for (Cost cost : source.getCosts()) {
            if (cost instanceof SacrificeTargetCost) {
                SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
                for (Permanent permanent : sacCost.getPermanents()) {
                    power = permanent.getPower().getValue();
                    break COSTS;
                }
            }
        }
        if (power > 0) {
            targetPlayer.discard(power, false, false, source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost)

Example 84 with TargetPlayer

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

the class TsabosDecreeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player == null) {
        return false;
    }
    if (sourceObject == null) {
        return false;
    }
    Choice typeChoice = new ChoiceCreatureType(sourceObject);
    if (!player.choose(outcome, typeChoice, game)) {
        return false;
    }
    game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
    targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
    FilterCard filterCard = new FilterCard();
    filterCard.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
    targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
    FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
    filterCreaturePermanent.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
    for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
        if (creature.isControlledBy(targetPlayer.getId())) {
            creature.destroy(source, game, true);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) MageObject(mage.MageObject) ChoiceCreatureType(mage.choices.ChoiceCreatureType) CardsImpl(mage.cards.CardsImpl)

Example 85 with TargetPlayer

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

the class DrainPowerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        List<Permanent> ignorePermanents = new ArrayList<>();
        Map<Permanent, List<ActivatedManaAbilityImpl>> manaAbilitiesMap = new HashMap<>();
        TargetPermanent target = null;
        while (true) {
            targetPlayer.setPayManaMode(true);
            manaAbilitiesMap.clear();
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, targetPlayer.getId(), game)) {
                if (!ignorePermanents.contains(permanent)) {
                    List<ActivatedManaAbilityImpl> manaAbilities = new ArrayList<>();
                    abilitySearch: for (Ability ability : permanent.getAbilities()) {
                        if (ability instanceof ActivatedAbility && ability.getAbilityType() == AbilityType.MANA) {
                            ActivatedManaAbilityImpl manaAbility = (ActivatedManaAbilityImpl) ability;
                            if (manaAbility.canActivate(targetPlayer.getId(), game).canActivate()) {
                                // so it's necessary to filter them out manually - might be buggy in some fringe cases
                                for (ManaCost manaCost : manaAbility.getManaCosts()) {
                                    if (!targetPlayer.getManaPool().getMana().includesMana(manaCost.getMana())) {
                                        continue abilitySearch;
                                    }
                                }
                                manaAbilities.add(manaAbility);
                            }
                        }
                    }
                    if (!manaAbilities.isEmpty()) {
                        manaAbilitiesMap.put(permanent, manaAbilities);
                    }
                }
            }
            if (manaAbilitiesMap.isEmpty()) {
                break;
            }
            List<Permanent> permList = new ArrayList<>(manaAbilitiesMap.keySet());
            Permanent permanent;
            if (permList.size() > 1 || target != null) {
                FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
                filter2.add(new PermanentInListPredicate(permList));
                target = new TargetPermanent(1, 1, filter2, true);
                while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
                    targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);
                }
                permanent = game.getPermanent(target.getFirstTarget());
            } else {
                permanent = permList.get(0);
            }
            if (permanent != null) {
                int i = 0;
                for (ActivatedManaAbilityImpl manaAbility : manaAbilitiesMap.get(permanent)) {
                    i++;
                    if (manaAbilitiesMap.get(permanent).size() <= i || targetPlayer.chooseUse(Outcome.Neutral, "Activate mana ability \"" + manaAbility.getRule() + "\" of " + permanent.getLogName() + "? (Choose \"no\" to activate next mana ability)", source, game)) {
                        boolean originalCanUndo = manaAbility.isUndoPossible();
                        // prevents being able to undo Drain Power
                        manaAbility.setUndoPossible(false);
                        if (targetPlayer.activateAbility(manaAbility, game)) {
                            ignorePermanents.add(permanent);
                        }
                        // resets undoPossible to its original state
                        manaAbility.setUndoPossible(originalCanUndo);
                        break;
                    }
                }
            }
        }
        targetPlayer.setPayManaMode(false);
        // 106.12. One card (Drain Power) causes one player to lose unspent mana and another to add “the mana lost this way.” (Note that these may be the same player.)
        // This empties the former player's mana pool and causes the mana emptied this way to be put into the latter player's mana pool. Which permanents, spells, and/or
        // abilities produced that mana are unchanged, as are any restrictions or additional effects associated with any of that mana.
        List<ManaPoolItem> manaItems = targetPlayer.getManaPool().getManaItems();
        targetPlayer.getManaPool().emptyPool(game);
        for (ManaPoolItem manaPoolItem : manaItems) {
            controller.getManaPool().addMana(manaPoolItem.isConditional() ? manaPoolItem.getConditionalMana() : manaPoolItem.getMana(), game, source, Duration.EndOfTurn.equals(manaPoolItem.getDuration()));
        }
        return true;
    }
    return false;
}
Also used : ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ActivatedManaAbilityImpl(mage.abilities.mana.ActivatedManaAbilityImpl) ActivatedAbility(mage.abilities.ActivatedAbility) FilterLandPermanent(mage.filter.common.FilterLandPermanent) ManaPoolItem(mage.players.ManaPoolItem) ManaCost(mage.abilities.costs.mana.ManaCost) ArrayList(java.util.ArrayList) List(java.util.List) TargetPermanent(mage.target.TargetPermanent)

Aggregations

TargetPlayer (mage.target.TargetPlayer)134 Player (mage.players.Player)129 Card (mage.cards.Card)38 Permanent (mage.game.permanent.Permanent)32 FilterCard (mage.filter.FilterCard)27 UUID (java.util.UUID)25 MageObject (mage.MageObject)16 CardsImpl (mage.cards.CardsImpl)16 FilterPlayer (mage.filter.FilterPlayer)16 TargetCard (mage.target.TargetCard)13 Cards (mage.cards.Cards)12 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)12 ObjectSourcePlayer (mage.filter.predicate.ObjectSourcePlayer)10 Target (mage.target.Target)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 Spell (mage.game.stack.Spell)9 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 TargetPermanent (mage.target.TargetPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)5