use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ArgothianWurmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean costPaid = false;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
Player player = game.getPlayer(playerId);
if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
costPaid = true;
}
}
if (costPaid) {
super.apply(game, source);
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ChainOfSilenceEffect 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) {
ContinuousEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn);
game.addEffect(effect, source);
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;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ChoiceOfDamnationsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (targetPlayer != null) {
int numberPermanents = game.getState().getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
// AI hint
int amount;
if (targetPlayer.isComputer()) {
// AI as defender
int safeLifeToLost = Math.max(0, targetPlayer.getLife() / 2);
amount = Math.min(numberPermanents, safeLifeToLost);
} else {
// Human must choose
amount = targetPlayer.getAmount(0, Integer.MAX_VALUE, "Chooses a number", game);
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// AI hint
boolean chooseLoseLife;
if (targetPlayer.isComputer()) {
// AI as attacker
chooseLoseLife = (numberPermanents == 0 || amount <= numberPermanents || targetPlayer.getLife() < amount);
} else {
// Human must choose
chooseLoseLife = controller.chooseUse(outcome, "Shall " + targetPlayer.getLogName() + " lose " + amount + " life?", source, game);
}
if (chooseLoseLife) {
targetPlayer.loseLife(amount, game, source, false);
} else {
// (2005-06-01)
if (numberPermanents > amount) {
int numberToSacrifice = numberPermanents - amount;
Target target = new TargetControlledPermanent(numberToSacrifice, numberToSacrifice, new FilterControlledPermanent("permanent you control to sacrifice"), false);
targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
for (UUID uuid : target.getTargets()) {
Permanent permanent = game.getPermanent(uuid);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
}
}
return true;
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class ConsumingVaporsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
FilterControlledPermanent filter = new FilterControlledPermanent("creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (player != null && target.canChoose(source.getSourceId(), player.getId(), game)) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
permanent.sacrifice(source, game);
controller.gainLife(permanent.getToughness().getValue(), game, source);
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DarettiSacrificeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Target target = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
if (!target.canChoose(source.getSourceId(), controller.getId(), game) || !controller.chooseTarget(outcome, target, source, game)) {
return true;
}
Permanent artifact = game.getPermanent(target.getFirstTarget());
if (artifact == null || !artifact.sacrifice(source, game)) {
return true;
}
Card card = game.getCard(getTargetPointer().getFirst(game, source));
return card == null || controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
Aggregations