use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.
the class FettergeistUnlessPaysEffect method apply.
@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)) {
Cost cost = ManaUtil.createManaCost(count, false);
if (cost.pay(source, game, source, source.getControllerId(), false)) {
return true;
}
}
permanent.sacrifice(source, game);
return true;
}
return false;
}
use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.
the class PacksDisdainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (player != null && player.choose(Outcome.UnboostCreature, typeChoice, game)) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
DynamicValue negativePermanentsCount = new PermanentsOnBattlefieldCount(filter, -1);
ContinuousEffect effect = new BoostTargetEffect(negativePermanentsCount, negativePermanentsCount, Duration.EndOfTurn, true);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.
the class NessianGameWardenEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (controller == null || sourcePermanent == null) {
return false;
}
int count = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
Cards cards = new CardsImpl();
cards.addAll(controller.getLibrary().getTopCards(game, count));
controller.lookAtCards(sourcePermanent.getIdName(), cards, game);
if (!cards.isEmpty()) {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DrawCard, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
controller.revealCards(sourcePermanent.getName(), new CardsImpl(card), game);
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
return true;
}
use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.
the class PulseOfTheTangleReturnToHandEffect method apply.
@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;
}
use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.
the class DesertInGYorBFCondition method apply.
@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;
}
Aggregations