use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class BeamsplitterMageApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) getValue("spellCast");
if (player == null || spell == null) {
return false;
}
FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
filter.add(AnotherPredicate.instance);
filter.add(new BeamsplitterMagePredicate(spell));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
return true;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class CracklingDoomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> toSacrifice = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
if (controller.hasOpponent(playerId, game)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
int greatestPower = Integer.MIN_VALUE;
int numberOfCreatures = 0;
Permanent permanentToSacrifice = null;
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (permanent.getPower().getValue() > greatestPower) {
greatestPower = permanent.getPower().getValue();
numberOfCreatures = 1;
permanentToSacrifice = permanent;
} else if (permanent.getPower().getValue() == greatestPower) {
numberOfCreatures++;
}
}
if (numberOfCreatures == 1) {
if (permanentToSacrifice != null) {
toSacrifice.add(permanentToSacrifice);
}
} else if (greatestPower != Integer.MIN_VALUE) {
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)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
toSacrifice.add(permanent);
}
}
}
}
}
}
for (Permanent permanent : toSacrifice) {
permanent.sacrifice(source, game);
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DefilerOfSoulsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("monocolored creature");
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
filter.add(MonocoloredPredicate.instance);
int amount;
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
amount = Math.min(1, realCount);
Target target = new TargetControlledPermanent(amount, amount, filter, false);
target.setNotTarget(true);
// had, if thats the case this ability should fizzle.
if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
boolean abilityApplied = false;
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
for (int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
if (permanent != null) {
abilityApplied |= permanent.sacrifice(source, game);
}
}
return abilityApplied;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DinOfTheFireherdEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean applied;
Token token = new DinOfTheFireherdToken();
applied = token.putOntoBattlefield(1, game, source, source.getControllerId());
int blackCreaturesControllerControls = game.getBattlefield().countAll(blackCreatureFilter, source.getControllerId(), game);
int redCreaturesControllerControls = game.getBattlefield().countAll(redCreatureFilter, source.getControllerId(), game);
Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
if (targetOpponent != null) {
Effect effect = new SacrificeEffect(new FilterControlledCreaturePermanent(), blackCreaturesControllerControls, "Target Opponent");
effect.setTargetPointer(new FixedTarget(targetOpponent.getId()));
effect.apply(game, source);
Effect effect2 = new SacrificeEffect(new FilterControlledLandPermanent(), redCreaturesControllerControls, "Target Opponent");
effect2.setTargetPointer(new FixedTarget(targetOpponent.getId()));
effect2.apply(game, source);
applied = true;
}
return applied;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class LordOfThePitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (player == null || sourcePermanent == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
filter.add(AnotherPredicate.instance);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
return true;
}
} else {
player.damage(7, source.getSourceId(), source, game);
return true;
}
return false;
}
Aggregations