use of mage.target.TargetPermanent in project mage by magefree.
the class GryffsBoonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card aura = game.getCard(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (aura != null && controller != null && game.getState().getZone(aura.getId()) == Zone.GRAVEYARD) {
Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (!targetPermanent.cantBeAttachedBy(aura, source, game, false)) {
game.getState().setValue("attachTo:" + aura.getId(), targetPermanent);
controller.moveCards(aura, Zone.BATTLEFIELD, source, game);
return targetPermanent.addAttachment(aura.getId(), source, game);
}
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class HeraldOfLeshracLeavesEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Target target = new TargetPermanent(filter);
if (target.choose(Outcome.GainControl, controllerId, source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame);
effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
game.addEffect(effect, ability);
game.getState().processAction(game);
paid = true;
}
return paid;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class HexParasiteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
TargetPermanent target = (TargetPermanent) source.getTargets().get(0);
Permanent permanent = game.getPermanent(target.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (permanent != null && controller != null) {
int toRemove = source.getManaCostsToPay().getX();
int removed = 0;
String[] counterNames = permanent.getCounters(game).keySet().toArray(new String[0]);
for (String counterName : counterNames) {
if (controller.chooseUse(Outcome.Neutral, "Remove " + counterName + " counters?", source, game)) {
if (permanent.getCounters(game).get(counterName).getCount() == 1 || (toRemove - removed == 1)) {
permanent.removeCounters(counterName, 1, source, game);
removed++;
} else {
int amount = controller.getAmount(1, Math.min(permanent.getCounters(game).get(counterName).getCount(), toRemove - removed), "How many?", game);
if (amount > 0) {
removed += amount;
permanent.removeCounters(counterName, amount, source, game);
}
}
}
if (removed >= toRemove) {
break;
}
}
if (removed > 0) {
game.addEffect(new BoostSourceEffect(removed, 0, Duration.EndOfTurn), source);
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class HighcliffFelidarEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<UUID> toDestroy = new HashSet();
game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
if (maxPower > Integer.MIN_VALUE) {
FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
filter.add(new ControllerIdPredicate(opponent.getId()));
filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (controller.choose(outcome, target, source.getSourceId(), game)) {
toDestroy.add(target.getFirstTarget());
}
}
});
toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class LilianaOfTheVeilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (player != null && targetPlayer != null) {
int count = game.getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
TargetPermanent target = new TargetPermanent(0, count, new FilterPermanent("permanents to put in the first pile"), true);
List<Permanent> pile1 = new ArrayList<>();
target.setRequired(false);
if (player.choose(Outcome.Neutral, target, source.getSourceId(), game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Permanent p = game.getPermanent(targetId);
if (p != null) {
pile1.add(p);
}
}
}
List<Permanent> pile2 = new ArrayList<>();
for (Permanent p : game.getBattlefield().getAllActivePermanents(targetPlayer.getId())) {
if (!pile1.contains(p)) {
pile2.add(p);
}
}
boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to sacrifice.", pile1, pile2, game);
if (choice) {
sacrificePermanents(pile1, game, source);
} else {
sacrificePermanents(pile2, game, source);
}
return true;
}
return false;
}
Aggregations