use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ShattergangBrothersEffect 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)) {
if (!Objects.equals(playerId, source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
TargetControlledPermanent target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class AetherbornMarauderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (controller != null && sourceObject != null) {
FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control to remove +1/+1 counters from");
filter.add(AnotherPredicate.instance);
filter.add(CounterType.P1P1.getPredicate());
boolean firstRun = true;
while (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
if (controller.chooseUse(outcome, "Move " + (firstRun ? "any" : "more") + " +1/+1 counters from other permanents you control to " + sourceObject.getLogName() + '?', source, game)) {
firstRun = false;
TargetControlledPermanent target = new TargetControlledPermanent(filter);
target.setNotTarget(true);
if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
Permanent fromPermanent = game.getPermanent(target.getFirstTarget());
if (fromPermanent != null) {
int numberOfCounters = fromPermanent.getCounters(game).getCount(CounterType.P1P1);
int numberToMove = 1;
if (numberOfCounters > 1) {
numberToMove = controller.getAmount(0, numberOfCounters, "Choose how many +1/+1 counters to move", game);
}
if (numberToMove > 0) {
fromPermanent.removeCounters(CounterType.P1P1.createInstance(numberToMove), source, game);
sourceObject.addCounters(CounterType.P1P1.createInstance(numberToMove), source.getControllerId(), source, game);
}
}
}
} else {
break;
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class BaneOfBalaGedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player defendingPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (defendingPlayer != null) {
Target target = new TargetControlledPermanent(2);
defendingPlayer.chooseTarget(outcome, target, source, game);
Set<Card> toExile = target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toSet());
defendingPlayer.moveCards(toExile, Zone.EXILED, source, game);
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class BurningOfXinyeEffect method playerDestroys.
public boolean playerDestroys(Game game, Ability source, Player player) {
boolean abilityApplied = false;
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
int amount = Math.min(4, realCount);
Target target = new TargetControlledPermanent(amount, amount, filter, true);
if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game) && player.canRespond()) {
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.destroy(source, game, false);
}
}
}
return abilityApplied;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ChainOfVaporEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
controller.moveCards(permanent, Zone.HAND, source, game);
Player player = game.getPlayer(permanent.getControllerId());
TargetControlledPermanent target = new TargetControlledPermanent(0, 1, new FilterControlledLandPermanent("a land to sacrifice (to be able to copy " + sourceObject.getName() + ')'), true);
if (player != null && player.chooseTarget(Outcome.Sacrifice, target, source, game)) {
Permanent land = game.getPermanent(target.getFirstTarget());
if (land != null && land.sacrifice(source, game)) {
if (player.chooseUse(outcome, "Copy the spell?", source, game)) {
Spell spell = game.getStack().getSpell(source.getSourceId());
if (spell != null) {
spell.createCopyOnStack(game, source, player.getId(), true);
}
}
}
}
return true;
}
return false;
}
Aggregations