Search in sources :

Example 1 with TargetPlayerOrPlaneswalker

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

the class HansErikssonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Card card = player.getLibrary().getFromTop(game);
    if (card == null) {
        return false;
    }
    player.revealCards(source, new CardsImpl(card), game);
    if (!card.isCreature(game)) {
        return player.moveCards(card, Zone.HAND, source, game);
    }
    player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return true;
    }
    UUID defendingPlayerId = getTargetPointer().getFirst(game, source);
    UUID defenderId;
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), defendingPlayerId, game) < 1) {
        defenderId = defendingPlayerId;
    } else {
        FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker("defending player or a planeswalker they control");
        filter.getPlayerFilter().add(new PlayerIdPredicate(defendingPlayerId));
        filter.getPermanentFilter().add(new ControllerIdPredicate(defendingPlayerId));
        TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        defenderId = target.getFirstTarget();
    }
    if (defenderId != null) {
        game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
    }
    Effect fightEffect = new FightTargetSourceEffect();
    fightEffect.setTargetPointer(new FixedTarget(permanent, game));
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(fightEffect, false, "When you put a creature card onto the battlefield this way, it fights {this}");
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) FilterPlayerOrPlaneswalker(mage.filter.common.FilterPlayerOrPlaneswalker) Card(mage.cards.Card) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) FightTargetSourceEffect(mage.abilities.effects.common.FightTargetSourceEffect) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

Example 2 with TargetPlayerOrPlaneswalker

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

the class TahngarthFirstMateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller == null || player == null || permanent == null) {
        return false;
    }
    TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
    target.setNotTarget(true);
    if (!controller.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfCombat, player.getId());
    effect.setTargetPointer(new FixedTarget(permanent, game));
    game.addEffect(effect, source);
    game.getState().processAction(game);
    return game.getCombat().addAttackerToCombat(permanent.getId(), target.getFirstTarget(), game);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

Example 3 with TargetPlayerOrPlaneswalker

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

the class ZaraRenegadeRecruiterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller == null || player == null || player.getHand().isEmpty()) {
        return false;
    }
    TargetCardInHand targetCard = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_CREATURE);
    controller.choose(outcome, player.getHand(), targetCard, game);
    Card card = game.getCard(targetCard.getFirstTarget());
    if (card == null) {
        return false;
    }
    controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
    Permanent permanent = game.getPermanent(card.getId());
    if (permanent == null) {
        return false;
    }
    UUID defenderId;
    if (game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER, source.getSourceId(), player.getId(), game) < 1) {
        defenderId = player.getId();
    } else {
        FilterPlayerOrPlaneswalker filter = new FilterPlayerOrPlaneswalker(player.getName() + " or a planeswalker controlled by " + player.getName());
        filter.getPlayerFilter().add(new PlayerIdPredicate(player.getId()));
        filter.getPermanentFilter().add(new ControllerIdPredicate(player.getId()));
        TargetPlayerOrPlaneswalker target = new TargetPlayerOrPlaneswalker(filter);
        target.setNotTarget(true);
        controller.choose(outcome, target, source.getSourceId(), game);
        defenderId = target.getFirstTarget();
    }
    game.getCombat().addAttackerToCombat(permanent.getId(), defenderId, game);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToHandTargetEffect().setTargetPointer(new FixedTarget(permanent, game))), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) UUID(java.util.UUID) FilterPlayerOrPlaneswalker(mage.filter.common.FilterPlayerOrPlaneswalker) Card(mage.cards.Card) TargetPlayerOrPlaneswalker(mage.target.common.TargetPlayerOrPlaneswalker)

Aggregations

Permanent (mage.game.permanent.Permanent)3 Player (mage.players.Player)3 TargetPlayerOrPlaneswalker (mage.target.common.TargetPlayerOrPlaneswalker)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 UUID (java.util.UUID)2 Card (mage.cards.Card)2 FilterPlayerOrPlaneswalker (mage.filter.common.FilterPlayerOrPlaneswalker)2 PlayerIdPredicate (mage.filter.predicate.other.PlayerIdPredicate)2 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)2 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)1 ContinuousEffect (mage.abilities.effects.ContinuousEffect)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 FightTargetSourceEffect (mage.abilities.effects.common.FightTargetSourceEffect)1 ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 CardsImpl (mage.cards.CardsImpl)1 TargetCardInHand (mage.target.common.TargetCardInHand)1