use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class AvalancheTuskerAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
filter.add(new ControllerIdPredicate(defenderId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class ElementalAppealEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
CreateTokenEffect effect = new CreateTokenEffect(new RedElementalWithTrampleAndHaste());
if (effect.apply(game, source)) {
effect.exileTokensCreatedAtNextEndStep(game, source);
if (KickedCondition.instance.apply(game, source)) {
List<Predicate<MageObject>> predList = new ArrayList<>();
for (UUID tokenId : effect.getLastAddedTokenIds()) {
predList.add(new CardIdPredicate(tokenId));
}
if (!predList.isEmpty()) {
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(Predicates.or(predList));
game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class FightOrFlightEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
creatures.setRequired(false);
if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
List<UUID> targets = creatures.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can attack this turn.", pile1, pile2, game);
List<Permanent> chosenPile = choice ? pile2 : pile1;
List<Permanent> otherPile = choice ? pile1 : pile2;
for (Permanent permanent : chosenPile) {
if (permanent != null) {
RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfTurn);
effect.setText("");
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class HeartPiercerBowAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
Permanent equipment = game.getPermanent(getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game);
if (defenderId != null) {
filter.add(new ControllerIdPredicate(defenderId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MayaelsAriaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// put a +1/+1 counter on each creature you control if you control a creature with power 5 or greater.
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 4));
if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
}
}
// needed because otehrwise the +1/+1 counters wouldn't be taken into account
game.getState().processAction(game);
// Then you gain 10 life if you control a creature with power 10 or greater.
filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 9));
if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
controller.gainLife(10, game, source);
}
// Then you win the game if you control a creature with power 20 or greater.
filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 19));
if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
controller.won(game);
}
return true;
}
Aggregations