use of mage.filter.FilterPermanent in project mage by magefree.
the class ZombieApocalypseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
controller.moveCards(controller.getGraveyard().getCards(filterZombie, game), Zone.BATTLEFIELD, source, game, true, false, false, null);
game.getState().processAction(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterPermanent(SubType.HUMAN, "Humans"), source.getControllerId(), game)) {
permanent.destroy(source, game, false);
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class MostCommonColorCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent[] colorFilters = new FilterPermanent[6];
int i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i] = new FilterPermanent();
colorFilters[i].add(new ColorPredicate(color));
if (predicate != null) {
colorFilters[i].add(predicate);
}
i++;
}
int[] colorCounts = new int[6];
i = 0;
for (ObjectColor color : ObjectColor.getAllColors()) {
colorFilters[i].add(new ColorPredicate(color));
colorCounts[i] = game.getBattlefield().count(colorFilters[i], source.getId(), source.getControllerId(), game);
i++;
}
int max = 0;
for (i = 0; i < 5; i++) {
if (colorCounts[i] > max) {
max = colorCounts[i] * 1;
}
}
i = 0;
ObjectColor commonest = new ObjectColor();
for (ObjectColor color : ObjectColor.getAllColors()) {
if (colorCounts[i] == max) {
commonest.addColor(color);
}
i++;
}
if (compareColor.shares(commonest)) {
if (isMono) {
return !commonest.isMulticolored();
} else {
return true;
}
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class PermanentsOnTheBattlefieldCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterPermanent localFilter;
if (onlyControlled) {
localFilter = filter.copy();
localFilter.add(new ControllerIdPredicate(source.getControllerId()));
} else {
localFilter = filter;
}
return ComparisonType.compare(game.getBattlefield().count(localFilter, source.getSourceId(), source.getControllerId(), game), type, count);
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class AlpineMoonEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
if (cardName == null) {
return false;
}
FilterPermanent filter2 = filter.copy();
filter2.add(new NamePredicate(cardName));
for (Permanent land : game.getBattlefield().getActivePermanents(filter2, source.getControllerId(), game)) {
switch(layer) {
case TypeChangingEffects_4:
// 305.7 Note that this doesn't remove any abilities that were granted to the land by other effects
// So the ability removing has to be done before Layer 6
land.removeAllAbilities(source.getSourceId(), game);
land.removeAllSubTypes(game, SubTypeSet.NonBasicLandType);
break;
case AbilityAddingRemovingEffects_6:
land.addAbility(new AnyColorManaAbility(), source.getSourceId(), game);
break;
}
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class CelestialJudgmentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
a1.addAll(a2);
return a1;
}));
Set<UUID> toKeep = new HashSet<>();
for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
if (entry.getValue().size() == 1) {
toKeep.add(entry.getValue().get(0).getId());
continue;
}
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
toKeep.add(target.getFirstTarget());
}
for (Permanent permanent : permanents) {
if (!toKeep.contains(permanent.getId())) {
permanent.destroy(source, game);
}
}
return true;
}
Aggregations