Search in sources :

Example 41 with Player

use of mage.players.Player in project mage by magefree.

the class CosmicHorrorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent cosmicHorror = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && cosmicHorror != null) {
        StringBuilder sb = new StringBuilder(cost.getText()).append('?');
        if (!sb.toString().toLowerCase(Locale.ENGLISH).startsWith("exile ") && !sb.toString().toLowerCase(Locale.ENGLISH).startsWith("return ")) {
            sb.insert(0, "Pay ");
        }
        if (controller.chooseUse(Outcome.Benefit, sb.toString(), source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                return true;
            }
        }
        if (cosmicHorror.destroy(source, game, false)) {
            controller.damage(7, source.getSourceId(), source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 42 with Player

use of mage.players.Player in project mage by magefree.

the class CreamOfTheCropEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
    if (controller != null && permanent != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, permanent.getPower().getValue()));
        if (!cards.isEmpty()) {
            TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put on top of your library"));
            target.setNotTarget(true);
            controller.chooseTarget(Outcome.Benefit, cards, target, source, game);
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                cards.remove(card);
                controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, true);
            }
            controller.putCardsOnBottomOfLibrary(cards, game, source, true);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 43 with Player

use of mage.players.Player in project mage by magefree.

the class CranialArchiveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (targetPlayer != null) {
            for (Card card : targetPlayer.getGraveyard().getCards(game)) {
                targetPlayer.moveCardToLibraryWithInfo(card, source, game, Zone.GRAVEYARD, true, true);
            }
            targetPlayer.shuffleLibrary(source, game);
        }
        controller.drawCards(1, source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Card(mage.cards.Card)

Example 44 with Player

use of mage.players.Player in project mage by magefree.

the class CranialExtractionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (player == null) {
        return true;
    }
    String cardName = ChooseACardNameEffect.TypeOfName.NON_LAND_NAME.getChoice(player, game, source, false);
    if (cardName == null) {
        return false;
    }
    super.applySearchAndExile(game, source, cardName, player.getId());
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 45 with Player

use of mage.players.Player in project mage by magefree.

the class DefilerOfSoulsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("monocolored creature");
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    filter.add(MonocoloredPredicate.instance);
    int amount;
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    amount = Math.min(1, realCount);
    Target target = new TargetControlledPermanent(amount, amount, filter, false);
    target.setNotTarget(true);
    // had, if thats the case this ability should fizzle.
    if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
        boolean abilityApplied = false;
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        }
        for (int idx = 0; idx < target.getTargets().size(); idx++) {
            Permanent permanent = game.getPermanent(target.getTargets().get(idx));
            if (permanent != null) {
                abilityApplied |= permanent.sacrifice(source, game);
            }
        }
        return abilityApplied;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Aggregations

Player (mage.players.Player)3909 Permanent (mage.game.permanent.Permanent)1705 Card (mage.cards.Card)1099 UUID (java.util.UUID)962 MageObject (mage.MageObject)556 FilterCard (mage.filter.FilterCard)515 CardsImpl (mage.cards.CardsImpl)498 FixedTarget (mage.target.targetpointer.FixedTarget)387 TargetPermanent (mage.target.TargetPermanent)353 Cards (mage.cards.Cards)345 TargetCard (mage.target.TargetCard)328 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)317 TargetPlayer (mage.target.TargetPlayer)312 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)301 FilterPermanent (mage.filter.FilterPermanent)292 Target (mage.target.Target)289 OneShotEffect (mage.abilities.effects.OneShotEffect)230 ContinuousEffect (mage.abilities.effects.ContinuousEffect)227 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)207 Effect (mage.abilities.effects.Effect)170