use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.
the class EndemicPlagueEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Permanent permanent = null;
for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost && !((SacrificeTargetCost) cost).getPermanents().isEmpty()) {
permanent = ((SacrificeTargetCost) cost).getPermanents().get(0);
break;
}
}
if (permanent == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new SharesCreatureTypePredicate(permanent));
return new DestroyAllEffect(filter, true).apply(game, source);
}
use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.
the class HarshMercyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Set<String> chosenTypes = new HashSet<>();
PlayerIteration: for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (player != null && !player.choose(Outcome.DestroyPermanent, typeChoice, game)) {
continue PlayerIteration;
}
String chosenType = typeChoice.getChoice();
if (chosenType != null) {
game.informPlayers(sourceObject.getIdName() + ": " + player.getLogName() + " has chosen " + chosenType);
chosenTypes.add(chosenType);
}
}
FilterPermanent filter = new FilterCreaturePermanent("creatures");
for (String type : chosenTypes) {
filter.add(Predicates.not(SubType.byDescription(type).getPredicate()));
}
return new DestroyAllEffect(filter, true).apply(game, source);
}
return false;
}
use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.
the class MagisterOfWorthEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Outcome.Benefit - AI will return from graveyard all the time (Grace choice)
// TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
TwoChoiceVote vote = new TwoChoiceVote("Grace (return from graveyard)", "Condemnation (destroy all)", Outcome.Benefit);
vote.doVotes(source, game);
int graceCount = vote.getVoteCount(true);
int condemnationCount = vote.getVoteCount(false);
if (condemnationCount >= graceCount) {
return new DestroyAllEffect(filter).apply(game, source);
}
// grace win - each player returns each creature card from their graveyard to the battlefield
Cards cards = new CardsImpl();
game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).map(g -> g.getCards(game)).flatMap(Collection::stream).filter(Objects::nonNull).filter(card -> card.isCreature(game)).forEach(cards::add);
return controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.
the class SteelHellkiteWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
SteelHellkiteWatcher watcher = game.getState().getWatcher(SteelHellkiteWatcher.class);
if (watcher == null || watcher.getDamagedPlayers(source.getSourceId()).isEmpty()) {
return false;
}
Set<Predicate<Permanent>> predicateSet = new HashSet<>();
for (UUID playerId : watcher.getDamagedPlayers(source.getSourceId())) {
predicateSet.add(new ControllerIdPredicate(playerId));
}
FilterPermanent filter = new FilterNonlandPermanent();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
filter.add(Predicates.or(predicateSet));
return new DestroyAllEffect(filter).apply(game, source);
}
use of mage.abilities.effects.common.DestroyAllEffect in project mage by magefree.
the class TimeWipeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (player.choose(outcome, target, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
player.moveCards(permanent, Zone.HAND, source, game);
}
}
return new DestroyAllEffect(StaticFilters.FILTER_PERMANENT_A_CREATURE).apply(game, source);
}
Aggregations