use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class RoarOfTheCrowdEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (!player.choose(Outcome.LoseLife, typeChoice, game)) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent();
filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
return new DamageTargetEffect(new PermanentsOnBattlefieldCount(filter)).apply(game, source);
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ShimatsuTheBloodcloakedEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.chooseTarget(Outcome.Detriment, target, source, game);
if (!target.getTargets().isEmpty()) {
int sacrificedCreatures = target.getTargets().size();
game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedCreatures + " creatures for " + creature.getLogName());
for (UUID targetId : target.getTargets()) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature == null || !targetCreature.sacrifice(source, game)) {
return false;
}
}
creature.addCounters(CounterType.P1P1.createInstance(sacrificedCreatures), source.getControllerId(), source, game);
}
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class SmokestackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player activePlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (activePlayer != null && sourcePermanent != null) {
int count = sourcePermanent.getCounters(game).getCount(CounterType.SOOT);
if (count > 0) {
int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), activePlayer.getId(), game));
Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
// had, if thats the case this ability should fizzle.
if (target.canChoose(source.getSourceId(), activePlayer.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), activePlayer.getId(), game) && activePlayer.canRespond()) {
activePlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
for (int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class SpiritSistersCallPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = source.getFirstTarget();
Card card = game.getCard(targetId);
if (card == null || game.getState().getZone(targetId) != Zone.GRAVEYARD) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a permanent that shares a card type with the chosen card");
filter.add(new SpiritSistersCallPredicate(new HashSet<CardType>(card.getCardType(game))));
return new DoIfCostPaid(new SpiritSistersCallReturnToBattlefieldEffect(), new SacrificeTargetCost(filter)).apply(game, source);
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class CheeseStandsAloneContinuousEffect method applies.
@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().containsControlled(filter, source, game, 1)) {
if (!wonAlready) {
wonAlready = true;
controller.won(game);
}
}
}
}
}
return false;
}
Aggregations