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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations