use of mage.filter.common.FilterControlledCreaturePermanent 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.common.FilterControlledCreaturePermanent in project mage by magefree.
the class SunkenHopeReturnToHandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.ReturnToHand, target, source, game);
}
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
result |= player.moveCards(permanent, Zone.HAND, source, game);
}
}
}
return result;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class VampirismBoostEnchantedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
int count = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) - 1;
if (count > 0) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (creature != null) {
creature.addPower(count);
creature.addToughness(count);
return true;
}
}
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class EmergeAbility method getMinimumCostToActivate.
@Override
public ManaOptions getMinimumCostToActivate(UUID playerId, Game game) {
int maxCMC = 0;
for (Permanent creature : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), playerId, this.getSourceId(), game)) {
int cmc = creature.getManaValue();
if (cmc > maxCMC) {
maxCMC = cmc;
}
}
ManaOptions manaOptions = super.getMinimumCostToActivate(playerId, game);
for (Mana mana : manaOptions) {
if (mana.getGeneric() > maxCMC) {
mana.setGeneric(mana.getGeneric() - maxCMC);
} else {
mana.setGeneric(0);
}
}
return manaOptions;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class ConvokeEffect method getManaOptions.
@Override
public ManaOptions getManaOptions(Ability source, Game game, ManaCost unpaid) {
ManaOptions options = new ManaOptions();
FilterControlledCreaturePermanent filterBasic = new FilterControlledCreaturePermanent();
// each creature can give {1} or color mana
game.getBattlefield().getActivePermanents(filterBasic, source.getControllerId(), source.getSourceId(), game).stream().filter(permanent -> !permanent.isTapped()).forEach(permanent -> {
ManaOptions permMana = new ManaOptions();
permMana.add(Mana.GenericMana(1));
for (ObjectColor color : permanent.getColor(game).getColors()) {
if (color.isBlack())
permMana.add(Mana.BlackMana(1));
if (color.isBlue())
permMana.add(Mana.BlueMana(1));
if (color.isGreen())
permMana.add(Mana.GreenMana(1));
if (color.isRed())
permMana.add(Mana.RedMana(1));
if (color.isWhite())
permMana.add(Mana.WhiteMana(1));
}
options.addMana(permMana);
});
options.removeDuplicated();
return options;
}
Aggregations