use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DivineReckoningEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
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.Benefit, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
}
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), source.getSourceId(), game)) {
if (!chosen.contains(permanent)) {
permanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class DragonsFireEffect method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
this.targets.clear();
dragonZone = DragonZone.NONE;
selectedCardId = null;
Player controller = game.getPlayer(controllerId);
if (controller != null) {
boolean dragonInHand = false;
boolean dragonOnBattlefield = false;
DragonZone chosenZone = DragonZone.NONE;
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card != null && card.hasSubtype(SubType.DRAGON, game)) {
dragonInHand = true;
break;
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controllerId)) {
if (permanent != null && permanent.hasSubtype(SubType.DRAGON, game)) {
dragonOnBattlefield = true;
break;
}
}
if (dragonInHand && dragonOnBattlefield) {
if (controller.chooseUse(Outcome.Benefit, "Reveal a Dragon card from your hand or choose a Dragon you control?", source, game)) {
if (controller.chooseUse(Outcome.Benefit, "Choose Dragon from hand or Dragon on battlefield", null, "Hand", "Battlefield", source, game)) {
chosenZone = DragonZone.HAND;
} else {
chosenZone = DragonZone.BATTLEFIELD;
}
}
} else if (dragonInHand) {
if (controller.chooseUse(Outcome.Benefit, "Reveal a Dragon card from your hand?", source, game)) {
chosenZone = DragonZone.HAND;
}
} else if (dragonOnBattlefield) {
if (controller.chooseUse(Outcome.Benefit, "Choose a dragon on the battlefield?", source, game)) {
chosenZone = DragonZone.BATTLEFIELD;
}
}
switch(chosenZone) {
case HAND:
targets.add(new TargetCardInHand(handFilter));
if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), game)) {
Card card = game.getCard(targets.getFirstTarget());
if (card != null) {
dragonZone = DragonZone.HAND;
selectedCardId = targets.getFirstTarget();
controller.revealCards(source, new CardsImpl(card), game);
}
}
break;
case BATTLEFIELD:
targets.add(new TargetControlledPermanent(battlefieldFilter));
if (targets.choose(Outcome.Benefit, controllerId, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(targets.getFirstTarget());
if (permanent != null) {
dragonZone = DragonZone.BATTLEFIELD;
selectedCardId = targets.getFirstTarget();
game.informPlayers(controller.getLogName() + " chooses " + permanent.getLogName());
}
}
break;
}
}
return paid = true;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class MartyrsBondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> perms = new ArrayList<>();
if (source != null) {
Permanent saccedPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && saccedPermanent != null) {
FilterControlledPermanent filter = new FilterControlledPermanent();
String message = "permanent with type (";
boolean firstType = true;
List<CardType.CardTypePredicate> cardTypes = new ArrayList<>();
for (CardType type : saccedPermanent.getCardType(game)) {
cardTypes.add(type.getPredicate());
if (firstType) {
message += type;
firstType = false;
} else {
message += " or " + type;
}
}
message += ") to sacrifice";
filter.add(Predicates.or(cardTypes));
filter.setMessage(message);
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && !playerId.equals(controller.getId())) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), playerId, game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.add(target.getFirstTarget());
}
}
}
boolean saccedPermaents = false;
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
saccedPermaents = true;
}
}
return saccedPermaents;
}
}
return false;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class OathOfLimDulEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
boolean sacrificeDone = false;
int numberSacrificed = 0;
int numberToDiscard = 0;
int numberOfControlledPermanents = 0;
Player controller = game.getPlayer(source.getControllerId());
int amountDamage = (int) game.getState().getValue(source.getSourceId().toString() + "oathOfLimDul");
if (amountDamage > 0 && controller != null) {
TargetControlledPermanent target = new TargetControlledPermanent(0, numberOfControlledPermanents, filter, true);
target.setNotTarget(true);
if (controller.choose(Outcome.Detriment, target, source.getSourceId(), game)) {
for (UUID targetPermanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(targetPermanentId);
if (permanent != null && permanent.sacrifice(source, game)) {
numberSacrificed += 1;
sacrificeDone = true;
}
}
}
numberToDiscard = amountDamage - numberSacrificed;
Cost cost = new DiscardTargetCost(new TargetCardInHand(numberToDiscard, new FilterCard("card(s) in your hand to discard")));
if (numberToDiscard > 0 && cost.canPay(source, source, controller.getId(), game)) {
// discard cost paid simultaneously
return cost.pay(source, game, source, controller.getId(), true);
}
}
return sacrificeDone;
}
use of mage.target.common.TargetControlledPermanent in project mage by magefree.
the class SelfInflictedWoundEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetOpponent = game.getPlayer(source.getTargets().getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (targetOpponent == null || controller == null) {
return false;
}
FilterControlledPermanent filter = new FilterControlledPermanent("a green or white creature");
filter.add(CardType.CREATURE.getPredicate());
filter.add(TargetController.YOU.getControllerPredicate());
filter.add(Predicates.or(new ColorPredicate(ObjectColor.GREEN), new ColorPredicate(ObjectColor.WHITE)));
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), targetOpponent.getId(), game)) {
targetOpponent.chooseTarget(Outcome.Sacrifice, target, source, game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
if (permanent.sacrifice(source, game)) {
targetOpponent.loseLife(2, game, source, false);
}
}
}
return true;
}
Aggregations