use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class ShowOfDominanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int highestPower = Integer.MIN_VALUE;
Permanent selectedCreature = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game)) {
if (highestPower < permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = permanent;
} else if (highestPower == permanent.getPower().getValue()) {
highestPower = permanent.getPower().getValue();
selectedCreature = null;
}
}
if (highestPower != Integer.MIN_VALUE) {
if (selectedCreature == null) {
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + highestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, highestPower));
Target target = new TargetPermanent(1, 1, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
selectedCreature = game.getPermanent(target.getFirstTarget());
}
}
if (selectedCreature != null) {
FixedTarget target = new FixedTarget(selectedCreature.getId(), game);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(4));
effect.setTargetPointer(target);
effect.apply(game, source);
ContinuousEffect continuousEffect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
continuousEffect.setTargetPointer(target);
game.addEffect(continuousEffect, source);
return true;
}
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class ConsumeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(source.getFirstTarget());
if (player == null || controller == null) {
return false;
}
int greatestPower = 0;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(player.getId())) {
if (permanent != null && permanent.isCreature(game)) {
greatestPower = Math.max(permanent.getPower().getValue(), greatestPower);
}
}
FilterPermanent filter = new FilterCreaturePermanent("creature with power " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
new SacrificeEffect(filter, 1, "").apply(game, source);
controller.gainLife(greatestPower, game, source);
return true;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class DropOfHoneyStateTriggeredAbility 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) {
int leastPower = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDestroy = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getPower().getValue() < leastPower) {
permanentToDestroy = permanent;
leastPower = permanent.getPower().getValue();
multipleExist = false;
} else {
if (permanent.getPower().getValue() == leastPower) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least power");
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, leastPower));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDestroy = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDestroy != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDestroy.getName());
return permanentToDestroy.destroy(source, game, true);
}
return true;
}
return false;
}
use of mage.filter.predicate.mageobject.PowerPredicate 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.predicate.mageobject.PowerPredicate 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;
}
Aggregations