@Override public final boolean apply(Game game, Ability source) { PermanentsOnBattlefieldCount amount = new PermanentsOnBattlefieldCount(filter); int count = amount.calculate(game, source, null); return count > value; } }
@Override public ManaCosts getManaCostToPay(GameEvent event, Ability source, Game game) { Permanent sourceObject = game.getPermanent(source.getSourceId()); if (sourceObject != null) { int payment = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); if (payment > 0) { return new ManaCostsImpl<>("{" + payment + '}'); } } return null; }
@Override public boolean apply(Game game, Ability source) { int islandCount = new PermanentsOnBattlefieldCount(filter2).calculate(game, source, this); islandCount = Math.floorDiv(islandCount, 2); return new DamageAllEffect(islandCount, filter).apply(game, source); } }
@Override public boolean apply(Game game, Ability source) { int xValue = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); ContinuousEffect effect = new BecomesCreatureTargetEffect(new ElvishBranchbenderToken(xValue), false, false, Duration.EndOfTurn); // fix effect.setTargetPointer(targetPointer); game.addEffect(effect, source); return false; } }
@Override public boolean apply(Game game, Ability source) { int amount = new PermanentsOnBattlefieldCount(filterAllies).calculate(game, source, this); ContinuousEffect effect = new BecomesCreatureTargetEffect(new VastwoodAnimistElementalToken(amount), false, true, Duration.EndOfTurn); effect.setTargetPointer(targetPointer); game.addEffect(effect, source); return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { for (Card card : player.getGraveyard().getCards(game)) { if (filter.match(card, game)) { return true; } } } PermanentsOnBattlefieldCount count = new PermanentsOnBattlefieldCount(filter2); return count.calculate(game, source, null) >= 1; } }
@Override public boolean apply(Game game, Ability source) { Permanent creature = game.getPermanent(source.getFirstTarget()); if (creature == null || creature.getPower().getValue() > new PermanentsOnBattlefieldCount(filter).calculate(game, source, this)) { return false; } return new ReturnToHandTargetEffect().apply(game, source); } }
@Override public boolean apply(Game game, Ability source) { int otherCreatures = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); if (otherCreatures > 0) { new SacrificeControllerEffect(filter, 1, "").apply(game, source); } else { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { controller.damage(6, source.getSourceId(), game, false, true); } } return true; } }
@Override public boolean apply(Game game, Ability source) { Permanent target = game.getPermanent(source.getFirstTarget()); if(target != null) { FilterPermanent filter = new FilterPermanent(); filter.add(new NamePredicate(target.getName())); if(new PermanentsOnBattlefieldCount(filter).calculate(game, source, this) > 1) { super.apply(game, source); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { int count = new PermanentsOnBattlefieldCount(StaticFilters.FILTER_CONTROLLED_PERMANENT_ARTIFACT).calculate(game, source, this) * 2; if (count > 0) { Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source)); if (targetPlayer != null) { targetPlayer.loseLife(count, game, false); } Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { controller.gainLife(count, game, source); } } return true; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); FilterControlledCreaturePermanent controllerFilter = new FilterControlledCreaturePermanent(); PermanentsOnBattlefieldCount controllerCount = new PermanentsOnBattlefieldCount(controllerFilter); int controllerAmount = controllerCount.calculate(game, source, this); boolean check = false; if (controller != null) { for (UUID opponentID : game.getOpponents(controller.getId())) { if (opponentID != null) { FilterCreaturePermanent opponentFilter = new FilterCreaturePermanent(); opponentFilter.add(new ControllerIdPredicate(opponentID)); PermanentsOnBattlefieldCount opponentCreatureCount = new PermanentsOnBattlefieldCount(opponentFilter); check = opponentCreatureCount.calculate(game, source, this) > controllerAmount; if (check) { break; } } } if (check) { Card card = game.getCard(source.getSourceId()); controller.moveCards(card, Zone.HAND, source, game); return true; } } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { TargetCardInLibrary target = new TargetCardInLibrary(0, new PermanentsOnBattlefieldCount(filter).calculate(game, source, this), StaticFilters.FILTER_CARD_BASIC_LAND); if (controller.searchLibrary(target, game)) { controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null); } controller.shuffleLibrary(source, game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { MageObject target = game.getObject(source.getSourceId()); if (target != null) { UUID playerId = (UUID) game.getState().getValue(source.getSourceId().toString() + ChooseOpponentEffect.VALUE_KEY); FilterLandPermanent filter = FilterLandPermanent.nonbasicLand(); filter.add(new ControllerIdPredicate(playerId)); int number = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); target.getPower().setValue(number); target.getToughness().setValue(number); return true; } } return false; } }
@Override public boolean applies(GameEvent event, Ability source, Game game) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { if (controller.getHand().isEmpty()) { int numberPerms = new PermanentsOnBattlefieldCount(new FilterControlledPermanent()).calculate(game, source, this); if (numberPerms == 1) { if (game.getBattlefield().contains(filter, source.getControllerId(), 1, game)) { if (!wonAlready) { wonAlready = true; controller.won(game); } } } } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller == null) { return false; } FilterLandPermanent filter = new FilterLandPermanent(); filter.add(new ControllerPredicate(TargetController.YOU)); int amount = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD_BASIC_LAND); if (controller.searchLibrary(target, game)) { controller.moveCards(new CardsImpl(target.getTargets()).getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null); } controller.shuffleLibrary(source, game); return true; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Player opponent = game.getPlayerOrPlaneswalkerController(getTargetPointer().getFirst(game, source)); if (controller != null) { if (controller.flipCoin(source, game, true)) { int damage = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent()).calculate(game, source, this); if (opponent != null) { return game.damagePlayerOrPlaneswalker(source.getFirstTarget(), damage, source.getSourceId(), game, false, true) > 0; } } else { int damage = game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), opponent.getId(), game).size(); return controller.damage(damage, source.getSourceId(), game, false, true) > 0; } } return false; } }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); if (player != null && permanent != null) { PermanentsOnBattlefieldCount amount = new PermanentsOnBattlefieldCount(filter, 1); int count = amount.calculate(game, source, this); if (player.chooseUse(Outcome.Benefit, "Pay " + count + "? Or " + permanent.getName() + " will be sacrificed.", source, game)) { GenericManaCost cost = new GenericManaCost(count); if (cost.pay(source, game, source.getSourceId(), source.getControllerId(), false)) { return true; } } permanent.sacrifice(source.getSourceId(), game); return true; } return false; }
@Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); if (player != null) { int permanentsInPlay = new PermanentsOnBattlefieldCount().calculate(game, source, null); // Odd if (permanentsInPlay % 2 != 0) { game.addEffect(new BoostAllEffect(1, 1, Duration.EndOfTurn, filter, false), source); new CreateDelayedTriggeredAbilityEffect(new ChaosMoonOddTriggeredAbility()).apply(game, source); } // Even else { game.addEffect(new BoostAllEffect(-1, -1, Duration.EndOfTurn, filter, false), source); game.addEffect(new ChaosMoonEvenReplacementEffect(), source); } return true; } return false; } }
@Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { boolean result = false; Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { int numberOfCreaturesControlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); int toPrevent = Math.min(numberOfCreaturesControlled, event.getAmount()); GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), toPrevent, false); if (!game.replaceEvent(preventEvent)) { if (event.getAmount() >= toPrevent) { event.setAmount(event.getAmount() - toPrevent); } else { event.setAmount(0); result = true; } if (toPrevent > 0) { game.informPlayers("Shield of the Avatar " + "prevented " + toPrevent + " damage to " + game.getPermanent(equipment.getAttachedTo()).getName()); game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, equipment.getAttachedTo(), source.getSourceId(), source.getControllerId(), toPrevent)); } } } return result; }
@Override public boolean apply(Game game, Ability source) { boolean result = false; Player controller = game.getPlayer(source.getControllerId()); Player targetPlayer = game.getPlayer(source.getFirstTarget()); if (controller != null && targetPlayer != null) { int amount = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this); TargetCardInLibrary target = new TargetCardInLibrary(0, amount, new FilterCard()); if (controller.searchLibrary(target, game, targetPlayer.getId())) { List<UUID> targetId = target.getTargets(); for (UUID targetCard : targetId) { Card card = targetPlayer.getLibrary().remove(targetCard, game); if (card != null) { controller.moveCardToExileWithInfo(card, null, null, source.getSourceId(), game, Zone.LIBRARY, true); result = true; } } } } if (targetPlayer != null) { targetPlayer.shuffleLibrary(source, game); } return result; } }