use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ReadTheRunesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int drawnCards = controller.drawCards(source.getManaCostsToPay().getX(), source, game);
Target target = new TargetControlledPermanent(0, drawnCards, new FilterControlledPermanent(), true);
controller.chooseTarget(Outcome.Sacrifice, target, source, game);
int sacrificedPermanents = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
sacrificedPermanents++;
}
}
}
controller.discard(drawnCards - sacrificedPermanents, false, false, source, game);
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class RustElementalEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (sourceObject != null) {
// create cost for sacrificing an artifact
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
// if they can pay the cost, then they must pay
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent artifactSacrifice = game.getPermanent(target.getFirstTarget());
if (artifactSacrifice != null) {
// sacrifice the chosen artifact
artifactSacrifice.sacrifice(source, game);
}
} else {
sourceObject.tap(source, game);
controller.damage(4, source.getSourceId(), source, game);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class SunkenHopeReturnToHandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean result = false;
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.ReturnToHand, target, source, game);
}
for (UUID targetId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
result |= player.moveCards(permanent, Zone.HAND, source, game);
}
}
}
return result;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class TangleWireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (player == null || permanent == null) {
return false;
}
int targetCount = game.getBattlefield().countAll(filter, player.getId(), game);
int counterCount = permanent.getCounters(game).getCount(CounterType.FADE);
int amount = Math.min(counterCount, targetCount);
Target target = new TargetControlledPermanent(amount, amount, filter, true);
target.setNotTarget(true);
if (amount > 0 && player.chooseTarget(Outcome.Tap, target, source, game)) {
boolean abilityApplied = false;
for (UUID uuid : target.getTargets()) {
Permanent selectedPermanent = game.getPermanent(uuid);
if (selectedPermanent != null) {
abilityApplied |= selectedPermanent.tap(source, game);
}
}
return abilityApplied;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class EntrapmentManeuverSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.add(AttackingPredicate.instance);
int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
if (realCount > 0) {
Target target = new TargetControlledPermanent(1, 1, filter, true);
while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
int amount = permanent.getToughness().getValue();
permanent.sacrifice(source, game);
new CreateTokenEffect(new SoldierToken(), amount).apply(game, source);
} else {
return false;
}
}
return true;
}
Aggregations