Search in sources :

Example 71 with TargetPlayer

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

the class SingeMindOgreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null && !targetPlayer.getHand().isEmpty()) {
        Cards revealed = new CardsImpl();
        Card card = targetPlayer.getHand().getRandom(game);
        if (card != null) {
            revealed.add(card);
            targetPlayer.revealCards("Singe-Mind Ogre", revealed, game);
            targetPlayer.loseLife(card.getManaValue(), game, source, false);
            return true;
        }
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 72 with TargetPlayer

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

the class SinsOfTheFatherEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player you = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (you != null && targetPlayer != null) {
        int exiledCards = 0;
        for (Card card : targetPlayer.getGraveyard().getCards(game)) {
            if (filter.match(card, game)) {
                if (card.moveToExile(null, "", source, game)) {
                    exiledCards++;
                }
            }
        }
        targetPlayer.loseLife(exiledCards, game, source, false);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 73 with TargetPlayer

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

the class ThrullSurgeonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player you = game.getPlayer(source.getControllerId());
    if (targetPlayer != null && you != null) {
        you.lookAtCards("Discard", targetPlayer.getHand(), game);
        TargetCard target = new TargetCard(Zone.HAND, new FilterCard());
        target.setNotTarget(true);
        if (you.choose(Outcome.Benefit, targetPlayer.getHand(), target, game)) {
            Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
            return targetPlayer.discard(card, false, source, game);
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 74 with TargetPlayer

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

the class TunnelVisionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (targetPlayer == null || cardName == null || cardName.isEmpty()) {
        return false;
    }
    Cards cardsToReveal = new CardsImpl();
    Card namedCard = null;
    for (Card card : targetPlayer.getLibrary().getCards(game)) {
        cardsToReveal.add(card);
        if (CardUtil.haveSameNames(card, cardName, game)) {
            namedCard = card;
            break;
        }
    }
    targetPlayer.revealCards(source, cardsToReveal, game);
    if (namedCard != null) {
        cardsToReveal.remove(namedCard);
        targetPlayer.moveCards(cardsToReveal, Zone.GRAVEYARD, source, game);
        targetPlayer.putCardsOnTopOfLibrary(new CardsImpl(namedCard), game, source, true);
    } else {
        targetPlayer.shuffleLibrary(source, game);
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 75 with TargetPlayer

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

the class GameImpl method preventDamage.

@Override
public PreventionEffectData preventDamage(GameEvent event, Ability source, Game game, int amountToPrevent) {
    PreventionEffectData result = new PreventionEffectData(amountToPrevent);
    if (!event.getFlag()) {
        // damage is not preventable
        return result;
    }
    if (!(event instanceof DamageEvent)) {
        result.setError(true);
        return result;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    GameEvent preventEvent = new PreventDamageEvent(damageEvent.getTargetId(), damageEvent.getSourceId(), source, source.getControllerId(), damageEvent.getAmount(), damageEvent.isCombatDamage());
    if (game.replaceEvent(preventEvent)) {
        result.setReplaced(true);
        return result;
    }
    if (event.getAmount() > amountToPrevent) {
        result.setPreventedDamage(amountToPrevent);
        damageEvent.setAmount(event.getAmount() - amountToPrevent);
    } else {
        result.setPreventedDamage(event.getAmount());
        damageEvent.setAmount(0);
    }
    if (amountToPrevent != Integer.MAX_VALUE) {
        // set remaining amount
        result.setRemainingAmount(amountToPrevent - result.getPreventedDamage());
    }
    MageObject damageSource = game.getObject(damageEvent.getSourceId());
    MageObject preventionSource = game.getObject(source.getSourceId());
    if (damageSource != null && preventionSource != null) {
        MageObject targetObject = game.getObject(event.getTargetId());
        String targetName = "";
        if (targetObject == null) {
            Player targetPlayer = game.getPlayer(event.getTargetId());
            if (targetPlayer != null) {
                targetName = targetPlayer.getLogName();
            }
        } else {
            targetName = targetObject.getLogName();
        }
        if (!game.isSimulation()) {
            StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
            message.append(result.getPreventedDamage()).append(" damage from ").append(damageSource.getLogName());
            if (!targetName.isEmpty()) {
                message.append(" to ").append(targetName);
            }
            game.informPlayers(message.toString());
        }
    }
    game.fireEvent(new PreventedDamageEvent(damageEvent.getTargetId(), source.getSourceId(), source, source.getControllerId(), result.getPreventedDamage()));
    return result;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) MageObject(mage.MageObject)

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