use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class PorphyryNodesStateTriggeredAbility 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(PorphyryNodes.filter, 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 ShadowgrangeArchfiendEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<Permanent> toSacrifice = new ArrayList<>();
// Iterate through each opponent
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (!controller.hasOpponent(playerId, game)) {
continue;
}
Player opponent = game.getPlayer(playerId);
if (opponent == null) {
continue;
}
int greatestPower = Integer.MIN_VALUE;
int numberOfCreatures = 0;
Permanent creatureToSacrifice = null;
// Iterature through each creature
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (permanent.getPower().getValue() > greatestPower) {
greatestPower = permanent.getPower().getValue();
numberOfCreatures = 1;
creatureToSacrifice = permanent;
} else if (permanent.getPower().getValue() == greatestPower) {
numberOfCreatures++;
}
}
// If multiple creatures are tied for having the greatest power
if (numberOfCreatures > 1) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature to sacrifice with power equal to " + greatestPower);
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, greatestPower));
Target target = new TargetControlledCreaturePermanent(filter);
if (opponent.choose(outcome, target, playerId, game)) {
creatureToSacrifice = game.getPermanent(target.getFirstTarget());
}
}
if (creatureToSacrifice != null) {
toSacrifice.add(creatureToSacrifice);
}
}
int greatestPowerAmongAllCreaturesSacked = Integer.MIN_VALUE;
int powerOfCurrentCreature;
// Sack the creatures and save the greaterest power amoung those which were sacked
for (Permanent permanent : toSacrifice) {
powerOfCurrentCreature = permanent.getPower().getValue();
// Try to sack it
if (permanent.sacrifice(source, game)) {
if (powerOfCurrentCreature > greatestPowerAmongAllCreaturesSacked) {
greatestPowerAmongAllCreaturesSacked = powerOfCurrentCreature;
}
}
}
// Gain life equal to the power of greatest creature sacked, if it is positive
if (greatestPowerAmongAllCreaturesSacked > 0) {
new GainLifeEffect(greatestPowerAmongAllCreaturesSacked).apply(game, source);
}
return true;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class LenaSelflessChampionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (permanent == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.FEWER_THAN, permanent.getPower().getValue()));
game.addEffect(new GainAbilityControlledEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn, filter), source);
return true;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class PuppetsVerdictEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.flipCoin(source, game, true)) {
FilterCreaturePermanent filterPower2OrLess = new FilterCreaturePermanent("all creatures power 2 or less");
filterPower2OrLess.add(new PowerPredicate(ComparisonType.FEWER_THAN, 3));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPower2OrLess, game)) {
permanent.destroy(source, game, false);
}
return true;
} else {
FilterCreaturePermanent filterPower3OrGreater = new FilterCreaturePermanent("all creatures power 3 or greater");
filterPower3OrGreater.add(new PowerPredicate(ComparisonType.MORE_THAN, 2));
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPower3OrGreater, game)) {
permanent.destroy(source, game, false);
}
return true;
}
}
return false;
}
use of mage.filter.predicate.mageobject.PowerPredicate in project mage by magefree.
the class RhonasTheIndomitableRestrictionEffect method applies.
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 3));
filter.add(AnotherPredicate.instance);
if (permanent.getId().equals(source.getSourceId())) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int permanentsOnBattlefield = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
// is this correct?
return permanentsOnBattlefield < 1;
}
return true;
}
// do not apply to other creatures.
return false;
}
Aggregations