Search in sources :

Example 6 with TargetOpponent

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

the class ViashinoBeyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    TargetOpponent targetDefender = new TargetOpponent();
    if (controller != null) {
        game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game).stream().filter((permanent) -> (filter.match(permanent, source.getSourceId(), source.getControllerId(), game))).forEachOrdered((permanent) -> {
            if (game.getOpponents(controller.getId()).size() > 1) {
                controller.choose(outcome.Benefit, targetDefender, source.getSourceId(), game);
            } else {
                targetDefender.add(game.getOpponents(controller.getId()).iterator().next(), game);
            }
            if (permanent.canAttack(targetDefender.getFirstTarget(), game)) {
                controller.declareAttacker(permanent.getId(), targetDefender.getFirstTarget(), game, false);
            }
        });
    }
    return false;
}
Also used : TargetOpponent(mage.target.common.TargetOpponent) AttacksTriggeredAbility(mage.abilities.common.AttacksTriggeredAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) TargetController(mage.constants.TargetController) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent)

Example 7 with TargetOpponent

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

the class ChooseSecretOpponentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller == null || mageObject == null) {
        return false;
    }
    TargetOpponent targetOpponent = new TargetOpponent(true);
    targetOpponent.setTargetName("opponent (secretly)");
    controller.choose(outcome, targetOpponent, source.getSourceId(), game);
    if (targetOpponent.getFirstTarget() == null) {
        return false;
    }
    game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has secretly chosen an opponent.");
    setChosenPlayer(targetOpponent.getFirstTarget(), source, game);
    setSecretOwner(controller.getId(), source, game);
    if (!(mageObject instanceof Permanent)) {
        return true;
    }
    ((Permanent) mageObject).addInfo(SECRET_OPPONENT, CardUtil.addToolTipMarkTags(controller.getLogName() + " has secretly chosen an opponent."), game);
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject)

Example 8 with TargetOpponent

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

the class RohgahhOfKherKeepEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null) {
        return false;
    }
    Cost cost = new ManaCostsImpl("{R}{R}{R}");
    if (!cost.canPay(source, source, player.getId(), game) || !player.chooseUse(Outcome.Benefit, "Pay {R}{R}{R}?", source, game) || !cost.pay(source, game, source, player.getId(), false)) {
        TargetOpponent target = new TargetOpponent();
        Player opponent = null;
        if (target.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
            opponent = game.getPlayer(target.getFirstTarget());
        }
        new TapAllEffect(filter).apply(game, source);
        if (permanent != null) {
            permanent.tap(source, game);
        }
        if (opponent != null) {
            new GainControlAllEffect(Duration.Custom, filter, opponent.getId()).apply(game, source);
            if (permanent != null) {
                ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : TapAllEffect(mage.abilities.effects.common.TapAllEffect) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) GainControlAllEffect(mage.abilities.effects.common.continuous.GainControlAllEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 9 with TargetOpponent

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

the class SandstoneOracleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetOpponent target = new TargetOpponent(true);
        if (controller.choose(Outcome.DrawCard, target, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
                int cardsDiff = opponent.getHand().size() - controller.getHand().size();
                if (cardsDiff > 0) {
                    controller.drawCards(cardsDiff, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject)

Example 10 with TargetOpponent

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

the class SkullwinderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        TargetOpponent targetOpponent = new TargetOpponent(true);
        if (controller.choose(Outcome.Detriment, targetOpponent, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
            if (opponent != null) {
                game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " has chosen " + opponent.getLogName());
                // That player returns a card from their graveyard to their hand
                TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(new FilterCard("a card from your graveyard to return to your hand"));
                targetCard.setNotTarget(true);
                if (opponent.choose(outcome, targetCard, source.getSourceId(), game)) {
                    Card card = game.getCard(targetCard.getFirstTarget());
                    if (card != null) {
                        opponent.moveCards(card, Zone.HAND, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

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