use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class FavorOfTheMightyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int maxCMC = Integer.MIN_VALUE;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
if (permanent != null && permanent.getManaValue() > maxCMC) {
maxCMC = permanent.getManaValue();
}
}
FilterPermanent filterMaxCMC = new FilterCreaturePermanent();
filterMaxCMC.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, maxCMC));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filterMaxCMC, source.getControllerId(), game)) {
if (permanent != null) {
permanent.addAbility(new ProtectionAbility(filter), source.getSourceId(), game);
}
}
return true;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class HighcliffFelidarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<UUID> toDestroy = new HashSet();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
if (maxPower > Integer.MIN_VALUE) {
FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (controller.choose(outcome, target, source.getSourceId(), game)) {
toDestroy.add(target.getFirstTarget());
}
}
});
toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
return true;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class BecomesChosenCreatureTypeControlledEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(source.getSourceId());
String chosenType = "";
if (player != null && card != null) {
Choice typeChoice = new ChoiceCreatureType();
String msg = "Choose a creature type";
typeChoice.setMessage(msg);
while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
if (!player.canRespond()) {
return false;
}
}
game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
chosenType = typeChoice.getChoice();
if (chosenType != null && !chosenType.isEmpty()) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), player.getId(), game)) {
ContinuousEffect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, SubType.byDescription(chosenType));
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MobRuleControlAllEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean applied = false;
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(type, power));
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(filter, game);
for (Permanent creature : creatures) {
ContinuousEffect effect = new MobRuleControlAllEffect(source.getControllerId());
effect.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(effect, source);
applied = true;
}
for (Permanent creature : creatures) {
creature.untap(game);
applied = true;
}
for (Permanent creature : creatures) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature.getId(), game));
game.addEffect(effect, source);
applied = true;
}
return applied;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MistbladeShinobiTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
Player opponent = game.getPlayer(event.getPlayerId());
if (opponent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
return true;
}
}
return false;
}
Aggregations