use of mage.target.Target in project mage by magefree.
the class SlaughterTheStrongEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
boolean selectionDone = false;
Set<UUID> selectedCreatures = new HashSet<>();
while (player.canRespond() && selectionDone == false) {
int powerSum = 0;
for (UUID creatureId : selectedCreatures) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
powerSum += creature.getPower().getValue();
}
}
FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
if (!selectedCreatures.isEmpty()) {
for (UUID creatureId : selectedCreatures) {
alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
}
currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
} else {
currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
}
// human can de-select targets, but AI must choose only one time
Target target;
if (player.isComputer()) {
// AI settings
FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
selectedCreatures.stream().forEach(id -> {
strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
});
target = new TargetPermanent(0, 1, strictFilter, true);
} else {
// Human settings
target = new TargetPermanent(0, 1, currentFilter, true);
}
player.chooseTarget(Outcome.BoostCreature, target, source, game);
if (target.getFirstTarget() != null) {
if (selectedCreatures.contains(target.getFirstTarget())) {
selectedCreatures.remove(target.getFirstTarget());
} else {
selectedCreatures.add(target.getFirstTarget());
}
} else {
if (player.isComputer()) {
// AI stops
selectionDone = true;
} else {
// Human can continue
String selected = "Selected: ";
for (UUID creatureId : selectedCreatures) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
selected += creature.getLogName() + " ";
}
}
selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
}
}
}
for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (!selectedCreatures.contains(creature.getId())) {
creature.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class SkyfireKirinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent targetCreature = null;
for (Target target : source.getTargets()) {
if (target instanceof TargetPermanent) {
targetCreature = game.getPermanent(target.getFirstTarget());
}
}
if (targetCreature != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
game.addEffect(effect, source);
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class SuddenReclamationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cardsToHand = new CardsImpl();
Target target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToHand.add(card);
}
}
target = new TargetCardInYourGraveyard(new FilterLandCard("land card from your graveyard"));
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
cardsToHand.add(card);
}
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class SunderingTitanDestroyLandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Set<UUID> lands = new HashSet<>();
if (controller != null && sourcePermanent != null) {
for (SubType landName : SubType.getBasicLands()) {
FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
filter.add(landName.getPredicate());
Target target = new TargetLandPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.chooseTarget(outcome, target, source, game);
lands.add(target.getFirstTarget());
}
}
if (!lands.isEmpty()) {
int destroyedLands = 0;
for (UUID landId : lands) {
Permanent land = game.getPermanent(landId);
if (land != null) {
if (land.destroy(source, game, false)) {
destroyedLands++;
}
}
}
game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class TheFirstEruptionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Target target = new TargetControlledPermanent(1, 1, filter, false);
boolean sacrificed = false;
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (controller.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.chooseTarget(Outcome.Sacrifice, target, source, game);
}
for (int idx = 0; idx < target.getTargets().size(); idx++) {
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
if (permanent != null) {
sacrificed |= permanent.sacrifice(source, game);
}
}
}
if (sacrificed) {
return new DamageAllEffect(3, StaticFilters.FILTER_PERMANENT_CREATURE).apply(game, source);
}
return false;
}
Aggregations