use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class LinessaZephyrMageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
// Target player returns a creature they control to its owner's hand,
Target target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// then repeats this process for an artifact,
FilterControlledPermanent filter = new FilterControlledPermanent("artifact you control");
filter.add(CardType.ARTIFACT.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// an enchantment,
filter = new FilterControlledPermanent("enchantment you control");
filter.add(CardType.ENCHANTMENT.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
// and a land.
filter = new FilterControlledPermanent("land you control");
filter.add(CardType.LAND.getPredicate());
target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.ReturnToHand, targetPlayer.getId(), source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
targetPlayer.moveCards(permanent, Zone.HAND, source, game);
}
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class AnnihilatorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID defendingPlayerId = (UUID) getValue("defendingPlayerId");
Player player = null;
if (defendingPlayerId != null) {
player = game.getPlayer(defendingPlayerId);
}
if (player != null) {
int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), player.getId(), game));
if (amount > 0) {
Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && target.canChoose(source.getSourceId(), player.getId(), game) && !target.isChosen()) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> permanent.sacrifice(source, game));
}
return true;
}
}
return false;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class ArmedAndArmoredEquipEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterControlledPermanent dwarfFilter = new FilterControlledPermanent(SubType.DWARF);
List<Permanent> dwarves = game.getBattlefield().getAllActivePermanents(dwarfFilter, controller.getId(), game);
FilterControlledPermanent equipmentFilter = new FilterControlledPermanent(SubType.EQUIPMENT);
List<Permanent> equipment = game.getBattlefield().getAllActivePermanents(equipmentFilter, controller.getId(), game);
if (!dwarves.isEmpty() && !equipment.isEmpty()) {
TargetPermanent target = new TargetPermanent(0, 1, dwarfFilter, true);
target.withChooseHint("dwarf to be equipped");
controller.choose(outcome, target, source.getId(), game);
Permanent dwarf = game.getPermanent(target.getFirstTarget());
if (dwarf != null) {
target = new TargetPermanent(0, Integer.MAX_VALUE, equipmentFilter, true);
target.withChooseHint("equip to " + dwarf.getLogName());
controller.choose(outcome, target, source.getId(), game);
for (UUID targetId : target.getTargets()) {
dwarf.addAttachment(targetId, source, game);
game.informPlayers(game.getPermanent(targetId).getLogName() + " was attached to " + dwarf.getLogName());
}
}
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class PlaguecrafterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
List<UUID> perms = new ArrayList<>();
List<UUID> cantSac = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
FilterControlledPermanent filter = new FilterControlledPermanent("creature or planeswalker");
filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.PLANESWALKER.getPredicate()));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (!target.isChosen() && player.canRespond()) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
}
perms.addAll(target.getTargets());
} else {
cantSac.add(playerId);
}
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
for (UUID playerId : cantSac) {
Effect discardEffect = new DiscardTargetEffect(1);
discardEffect.setTargetPointer(new FixedTarget(playerId, game));
discardEffect.apply(game, source);
}
return true;
}
use of mage.filter.common.FilterControlledPermanent in project mage by magefree.
the class RiteOfRuinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<String> choices = new HashSet<>();
choices.add("Artifacts");
choices.add("Creatures");
choices.add("Lands");
LinkedList<CardType> order = new LinkedList<>();
ChoiceImpl choice = new ChoiceImpl(true);
choice.setMessage("Choose a card type");
choice.setChoices(choices);
while (choices.size() > 1) {
if (!controller.choose(Outcome.Sacrifice, choice, game)) {
return false;
}
order.add(getCardType(choice.getChoice()));
choices.remove(choice.getChoice());
choice.clearChoice();
}
order.add(getCardType(choices.iterator().next()));
int count = 1;
for (CardType cardType : order) {
FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " you control");
filter.add(cardType.getPredicate());
new SacrificeAllEffect(count, filter).apply(game, source);
count++;
}
return true;
}
Aggregations