Search in sources :

Example 16 with ReflexiveTriggeredAbility

use of mage.abilities.common.delayed.ReflexiveTriggeredAbility in project mage by magefree.

the class NihiloorLoseLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    for (UUID playerId : game.getOpponents(source.getControllerId())) {
        Player opponent = game.getPlayer(playerId);
        if (opponent == null) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(0, 1, filter, true);
        target.withChooseHint("tapping a creature controlled by " + opponent.getName());
        controller.choose(outcome, target, source.getControllerId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null || !permanent.tap(source, game)) {
            continue;
        }
        FilterPermanent filter2 = new FilterPermanent("creature controlled by " + opponent.getName() + " with power " + permanent.getPower().getValue() + " or less");
        filter2.add(new NihiloorPredicate(permanent, playerId));
        ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new GainControlTargetEffect(Duration.Custom, true), false, "gain control of target creature that player controls with " + "power less than or equal to the tapped creature's power for as long as you control {this}");
        ability.addTarget(new TargetPermanent(filter2));
        game.fireReflexiveTriggeredAbility(ability, source);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 17 with ReflexiveTriggeredAbility

use of mage.abilities.common.delayed.ReflexiveTriggeredAbility in project mage by magefree.

the class YannikScavengingSentinelEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (player == null || sourcePermanent == null || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    int power = permanent.getPower().getValue();
    new ExileTargetEffect(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), permanent.getIdName()).setTargetPointer(new FixedTarget(permanent, game)).apply(game, source);
    game.addDelayedTriggeredAbility(new OnLeaveReturnExiledToBattlefieldAbility(), source);
    if (game.getState().getZone(permanent.getId()) != Zone.BATTLEFIELD) {
        ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, power, false, ""), false, "distribute X +1/+1 counters among any number of target creatures, " + "where X is the exiled creature's power");
        ability.addTarget(new TargetCreaturePermanentAmount(power));
        game.fireReflexiveTriggeredAbility(ability, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetCreaturePermanentAmount(mage.target.common.TargetCreaturePermanentAmount) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) DistributeCountersEffect(mage.abilities.effects.common.counter.DistributeCountersEffect) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 18 with ReflexiveTriggeredAbility

use of mage.abilities.common.delayed.ReflexiveTriggeredAbility 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 19 with ReflexiveTriggeredAbility

use of mage.abilities.common.delayed.ReflexiveTriggeredAbility in project mage by magefree.

the class SpectralAdversaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Integer timesPaid = (Integer) getValue("timesPaid");
    if (timesPaid == null || timesPaid <= 0) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new AddCountersSourceEffect(CounterType.P1P1.createInstance(timesPaid)), false, staticText);
    ability.addEffect(new PhaseOutTargetEffect());
    ability.addTarget(new TargetPermanent(0, timesPaid, filter));
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) PhaseOutTargetEffect(mage.abilities.effects.common.PhaseOutTargetEffect) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent)

Example 20 with ReflexiveTriggeredAbility

use of mage.abilities.common.delayed.ReflexiveTriggeredAbility in project mage by magefree.

the class SurtlandFlingerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, 1, StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, true);
    player.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null) {
        return false;
    }
    int power = permanent.getPower().getValue();
    if (permanent.hasSubtype(SubType.GIANT, game)) {
        power *= 2;
    }
    power = Math.max(power, 0);
    if (!permanent.sacrifice(source, game)) {
        return false;
    }
    ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DamageTargetEffect(power), false, rule);
    ability.addTarget(new TargetAnyTarget());
    game.fireReflexiveTriggeredAbility(ability, source);
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ReflexiveTriggeredAbility(mage.abilities.common.delayed.ReflexiveTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) TargetAnyTarget(mage.target.common.TargetAnyTarget)

Aggregations

ReflexiveTriggeredAbility (mage.abilities.common.delayed.ReflexiveTriggeredAbility)37 Player (mage.players.Player)23 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)15 Permanent (mage.game.permanent.Permanent)13 TargetPermanent (mage.target.TargetPermanent)12 TargetAnyTarget (mage.target.common.TargetAnyTarget)11 UUID (java.util.UUID)6 Card (mage.cards.Card)6 FilterPermanent (mage.filter.FilterPermanent)6 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)5 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)4 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)4 CreateTokenEffect (mage.abilities.effects.common.CreateTokenEffect)3 DoWhenCostPaid (mage.abilities.effects.common.DoWhenCostPaid)3 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)3 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)3 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Mode (mage.abilities.Mode)2 ManaCosts (mage.abilities.costs.mana.ManaCosts)2