use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class BloodClockEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
if (player.getLife() > 2 && player.chooseUse(Outcome.Neutral, "Pay 2 life? If you don't, return a permanent you control to its owner's hand.", source, game)) {
player.loseLife(2, game, source, false);
game.informPlayers(player.getLogName() + " pays 2 life. They will not return a permanent they control.");
return true;
} else {
Target target = new TargetControlledPermanent();
if (target.canChoose(source.getSourceId(), player.getId(), game) && player.chooseTarget(outcome, target, source, game)) {
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
game.informPlayers(player.getLogName() + " returns " + permanent.getName() + " to hand.");
return player.moveCards(permanent, Zone.HAND, source, game);
}
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class WormsOfTheEarthDestroyEffect 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) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent("two lands"), false));
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.chooseUse(outcome, "Do you want to destroy " + sourcePermanent.getLogName() + "? (sacrifice two lands or have it deal 5 damage to you)", source, game)) {
cost.clearPaid();
if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Sacrifice, "Will you sacrifice two lands? (otherwise you'll be dealt 5 damage)", source, game)) {
if (!cost.pay(source, game, source, player.getId(), false, null)) {
player.damage(5, source.getSourceId(), source, game);
}
} else {
player.damage(5, source.getSourceId(), source, game);
}
sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
sourcePermanent.destroy(source, game, false);
}
break;
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent 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.target.common.TargetControlledPermanent in project mage by magefree.
the class NahiriTheLithomancerSecondAbilityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Token token = new KorSoldierToken();
if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
// TODO: Make sure the Equipment can legally enchant the token, preferably on targetting.
Target target = new TargetControlledPermanent(0, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Attach an Equipment you control to the created " + tokenPermanent.getIdName() + '?', source, game)) {
if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
Permanent equipmentPermanent = game.getPermanent(target.getFirstTarget());
if (equipmentPermanent != null) {
Permanent attachedTo = game.getPermanent(equipmentPermanent.getAttachedTo());
if (attachedTo != null) {
attachedTo.removeAttachment(equipmentPermanent.getId(), source, game);
}
tokenPermanent.addAttachment(equipmentPermanent.getId(), source, game);
}
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent 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;
}
Aggregations