Search in sources :

Example 41 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class MausoleumTurnkeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        UUID opponentId = null;
        if (game.getOpponents(controller.getId()).size() > 1) {
            Target target = new TargetOpponent(true);
            if (controller.chooseTarget(outcome, target, source, game)) {
                opponentId = target.getFirstTarget();
            }
        } else {
            opponentId = game.getOpponents(controller.getId()).iterator().next();
        }
        if (opponentId != null) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterCreatureCard filter = new FilterCreatureCard("creature card from " + controller.getLogName() + " graveyard");
                filter.add(new OwnerIdPredicate(controller.getId()));
                Target target = new TargetCardInGraveyard(filter);
                opponent.chooseTarget(outcome, target, source, game);
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    controller.moveCards(card, Zone.HAND, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterCreatureCard(mage.filter.common.FilterCreatureCard) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) TargetCardInGraveyard(mage.target.common.TargetCardInGraveyard) UUID(java.util.UUID) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 42 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class RogueSkycaptainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && permanent != null) {
        new AddCountersSourceEffect(CounterType.WAGE.createInstance(), true).apply(game, source);
        Cost cost = ManaUtil.createManaCost(2 * permanent.getCounters(game).getCount(CounterType.WAGE), false);
        if (!cost.pay(source, game, source, controller.getId(), false)) {
            new RemoveAllCountersSourceEffect(CounterType.WAGE).apply(game, source);
            Player opponent;
            Set<UUID> opponents = game.getOpponents(controller.getId());
            if (opponents.size() == 1) {
                opponent = game.getPlayer(opponents.iterator().next());
            } else {
                Target target = new TargetOpponent(true);
                target.setNotTarget(true);
                target.choose(Outcome.GainControl, source.getControllerId(), source.getSourceId(), game);
                opponent = game.getPlayer(target.getFirstTarget());
            }
            if (opponent != null) {
                permanent.changeControllerId(opponent.getId(), game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) RemoveAllCountersSourceEffect(mage.abilities.effects.common.RemoveAllCountersSourceEffect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost)

Example 43 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class SlithermuseEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (player != null && permanent != null) {
        TargetOpponent target = new TargetOpponent();
        target.setNotTarget(true);
        if (player.choose(this.outcome, target, source.getSourceId(), game)) {
            Player chosenPlayer = game.getPlayer(target.getFirstTarget());
            if (chosenPlayer != null) {
                game.informPlayers(permanent.getName() + ": " + player.getLogName() + " has chosen " + chosenPlayer.getLogName());
                int diff = chosenPlayer.getHand().size() - player.getHand().size();
                if (diff > 0) {
                    player.drawCards(diff, source, game);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent)

Example 44 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class SylvanOfferingEffect2 method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetOpponent(true);
        target.choose(Outcome.Sacrifice, source.getControllerId(), source.getSourceId(), game);
        Player opponent = game.getPlayer(target.getFirstTarget());
        if (opponent != null) {
            int xValue = source.getManaCostsToPay().getX();
            Effect effect = new CreateTokenTargetEffect(new ElfWarriorToken(), xValue);
            effect.setTargetPointer(new FixedTarget(controller.getId()));
            effect.apply(game, source);
            effect.setTargetPointer(new FixedTarget(opponent.getId()));
            effect.apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) TargetOpponent(mage.target.common.TargetOpponent) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) CreateTokenTargetEffect(mage.abilities.effects.common.CreateTokenTargetEffect) Effect(mage.abilities.effects.Effect) ElfWarriorToken(mage.game.permanent.token.ElfWarriorToken)

Example 45 with TargetOpponent

use of mage.target.common.TargetOpponent in project mage by magefree.

the class WishclawTalismanEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    effect.apply(game, source);
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPlayer target = new TargetOpponent();
    target.setNotTarget(true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    ContinuousEffect continuousEffect = new GainControlTargetEffect(Duration.Custom, true, target.getFirstTarget());
    continuousEffect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
    game.addEffect(continuousEffect, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) TargetOpponent(mage.target.common.TargetOpponent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetPlayer(mage.target.TargetPlayer)

Aggregations

Player (mage.players.Player)67 TargetOpponent (mage.target.common.TargetOpponent)67 Target (mage.target.Target)35 UUID (java.util.UUID)25 MageObject (mage.MageObject)22 TargetCard (mage.target.TargetCard)22 FilterCard (mage.filter.FilterCard)21 Permanent (mage.game.permanent.Permanent)20 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 ArrayList (java.util.ArrayList)8 CardsImpl (mage.cards.CardsImpl)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 Zone (mage.constants.Zone)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 Effect (mage.abilities.effects.Effect)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)4