use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class MutinyFirstTarget method addTarget.
@Override
public void addTarget(UUID id, Ability source, Game game, boolean skipEvent) {
super.addTarget(id, source, game, skipEvent);
// Update the second target
UUID firstController = game.getControllerId(id);
if (firstController != null && source.getTargets().size() > 1) {
Player controllingPlayer = game.getPlayer(firstController);
TargetCreaturePermanent targetCreaturePermanent = (TargetCreaturePermanent) source.getTargets().get(1);
// Set a new filter to the second target with the needed restrictions
FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature that player " + controllingPlayer.getName() + " controls");
filter.add(new ControllerIdPredicate(firstController));
filter.add(Predicates.not(new PermanentIdPredicate(id)));
targetCreaturePermanent.replaceFilter(filter);
}
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class PeerPressureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Choice choice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
if (controller != null && controller.choose(Outcome.GainControl, choice, game)) {
String chosenType = choice.getChoice();
game.informPlayers(controller.getLogName() + " has chosen " + chosenType);
UUID playerWithMost = null;
int maxControlled = 0;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
FilterPermanent filter = new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType);
filter.add(new ControllerIdPredicate(playerId));
int controlled = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
if (controlled > maxControlled) {
maxControlled = controlled;
playerWithMost = playerId;
} else if (controlled == maxControlled) {
// Do nothing in case of tie
playerWithMost = null;
}
}
if (playerWithMost != null && playerWithMost.equals(controller.getId())) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(SubType.byDescription(chosenType), chosenType), controller.getId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
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 PurgingScytheEffect 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 leastToughness = Integer.MAX_VALUE;
boolean multipleExist = false;
Permanent permanentToDamage = null;
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
if (permanent.getToughness().getValue() < leastToughness) {
permanentToDamage = permanent;
leastToughness = permanent.getToughness().getValue();
multipleExist = false;
} else {
if (permanent.getToughness().getValue() == leastToughness) {
multipleExist = true;
}
}
}
if (multipleExist) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
if (controller.choose(outcome, target, source.getSourceId(), game)) {
permanentToDamage = game.getPermanent(target.getFirstTarget());
}
}
}
if (permanentToDamage != null) {
game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
}
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class SkymarkRocAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls with toughness 2 or less");
UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
filter.add(new ControllerIdPredicate(defenderId));
filter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, 3));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
return false;
}
use of mage.filter.common.FilterCreaturePermanent in project mage by magefree.
the class TragicArroganceffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Permanent> choosenPermanent = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterArtifactPermanent filterArtifactPermanent = new FilterArtifactPermanent("an artifact of " + player.getName());
filterArtifactPermanent.add(new ControllerIdPredicate(playerId));
Target target1 = new TargetArtifactPermanent(1, 1, filterArtifactPermanent, true);
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent("a creature of " + player.getName());
filterCreaturePermanent.add(new ControllerIdPredicate(playerId));
Target target2 = new TargetPermanent(1, 1, filterCreaturePermanent, true);
FilterEnchantmentPermanent filterEnchantmentPermanent = new FilterEnchantmentPermanent("an enchantment of " + player.getName());
filterEnchantmentPermanent.add(new ControllerIdPredicate(playerId));
Target target3 = new TargetPermanent(1, 1, filterEnchantmentPermanent, true);
FilterPlaneswalkerPermanent filterPlaneswalkerPermanent = new FilterPlaneswalkerPermanent("a planeswalker of " + player.getName());
filterPlaneswalkerPermanent.add(new ControllerIdPredicate(playerId));
Target target4 = new TargetPermanent(1, 1, filterPlaneswalkerPermanent, true);
if (target1.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target1, source, game);
Permanent artifact = game.getPermanent(target1.getFirstTarget());
if (artifact != null) {
choosenPermanent.add(artifact);
}
target1.clearChosen();
}
if (target2.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target2, source, game);
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
choosenPermanent.add(creature);
}
target2.clearChosen();
}
if (target3.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target3, source, game);
Permanent enchantment = game.getPermanent(target3.getFirstTarget());
if (enchantment != null) {
choosenPermanent.add(enchantment);
}
target3.clearChosen();
}
if (target4.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Benefit, target4, source, game);
Permanent planeswalker = game.getPermanent(target4.getFirstTarget());
if (planeswalker != null) {
choosenPermanent.add(planeswalker);
}
target4.clearChosen();
}
}
}
// Then each player sacrifices all other nonland permanents they control
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENTS_NON_LAND, playerId, game)) {
if (!choosenPermanent.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
Aggregations