use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DwarvenCatapultEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int howMany = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getFirstTarget(), game).size();
int amount = source.getManaCostsToPay().getX() / howMany;
DamageAllControlledTargetEffect dmgEffect = new DamageAllControlledTargetEffect(amount, new FilterCreaturePermanent());
return dmgEffect.apply(game, source);
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class DuneblastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCreaturePermanent(0, 1, new FilterCreaturePermanent("creature to keep"), true);
target.setRequired(true);
Permanent creatureToKeep = null;
if (controller.choose(outcome, target, source.getSourceId(), game)) {
creatureToKeep = game.getPermanent(target.getFirstTarget());
}
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
if (!Objects.equals(creature, creatureToKeep)) {
creature.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class InfernalDenizenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
DynamicValue swamps = new PermanentsOnBattlefieldCount(filter);
boolean canSac = swamps.calculate(game, source, this) > 1;
Effect effect = new SacrificeControllerEffect(filter, 2, "Sacrifice two Swamps");
effect.apply(game, source);
if (!canSac) {
if (creature != null) {
creature.tap(source, game);
}
TargetOpponent targetOpp = new TargetOpponent(true);
if (targetOpp.canChoose(source.getSourceId(), player.getId(), game) && targetOpp.choose(Outcome.Detriment, player.getId(), source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpp.getFirstTarget());
if (opponent != null) {
FilterCreaturePermanent filter2 = new FilterCreaturePermanent("creature controlled by " + player.getLogName());
filter2.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent targetCreature = new TargetCreaturePermanent(1, 1, filter2, true);
targetCreature.setTargetController(opponent.getId());
if (targetCreature.canChoose(source.getSourceId(), id, game) && opponent.chooseUse(Outcome.GainControl, "Gain control of a creature?", source, game) && opponent.chooseTarget(Outcome.GainControl, targetCreature, source, game)) {
ConditionalContinuousEffect giveEffect = new ConditionalContinuousEffect(new GainControlTargetEffect(Duration.Custom, true, opponent.getId()), SourceOnBattlefieldCondition.instance, "");
giveEffect.setTargetPointer(new FixedTarget(targetCreature.getFirstTarget(), game));
game.addEffect(giveEffect, source);
return true;
}
}
}
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class LastOneStandingEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> creatureList = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game);
if (creatureList.size() < 2) {
return true;
}
int toSave = RandomUtil.nextInt(creatureList.size());
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.not(new PermanentIdPredicate(creatureList.get(toSave).getId())));
return new DestroyAllEffect(filter).apply(game, source);
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MisfortuneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player chosenOpponent = game.getPlayer(targetPointer.getFirst(game, source));
if (controller != null && chosenOpponent != null) {
if (chosenOpponent.chooseUse(Outcome.Neutral, "If you choose Yes, the controller puts a +1/+1 counter" + "on each creature they control and they gain 4 life. If no, the controller puts a -1/-1 counter" + "on each creature you control and {this} deals 4 damage to you.", source, game)) {
Effect putP1P1CounterOnEachControlledCreature = new AddCountersAllEffect(CounterType.P1P1.createInstance(), new FilterControlledCreaturePermanent());
putP1P1CounterOnEachControlledCreature.apply(game, source);
controller.gainLife(4, game, source);
} else {
FilterCreaturePermanent filterOpponentCreatures = new FilterCreaturePermanent();
filterOpponentCreatures.add(new ControllerIdPredicate(chosenOpponent.getId()));
Effect putM1M1CounterOnEachOpponentCreature = new AddCountersAllEffect(CounterType.M1M1.createInstance(), filterOpponentCreatures);
putM1M1CounterOnEachOpponentCreature.apply(game, source);
chosenOpponent.damage(4, source.getSourceId(), source, game);
}
return true;
}
return false;
}
Aggregations