use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class LiegeOfThePitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
}
if (player == null || sourcePermanent == null) {
return false;
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
filter.add(AnotherPredicate.instance);
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
if (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);
return true;
}
} else {
player.damage(7, source.getSourceId(), source, game);
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class StormHeraldAttachableToPredicate method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterCard filter = new FilterCard("aura cards to attach to creatures you control");
filter.add(SubType.AURA.getPredicate());
filter.add(new StormHeraldAttachablePredicate(controller.getId()));
Set<Card> possibleTargets = controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game);
if (!possibleTargets.isEmpty()) {
TargetCard targetAuras = new TargetCard(0, Integer.MAX_VALUE, Zone.GRAVEYARD, filter);
targetAuras.setNotTarget(true);
controller.chooseTarget(outcome, new CardsImpl(possibleTargets), targetAuras, source, game);
// Move the cards to the battlefield to a creature you control
List<Permanent> toExile = new ArrayList<>();
for (UUID auraId : targetAuras.getTargets()) {
Card auraCard = game.getCard(auraId);
if (auraCard != null) {
FilterPermanent filterAttachTo = new FilterControlledCreaturePermanent("creature you control to attach " + auraCard.getIdName() + " to");
filterAttachTo.add(new StormHeraldAttachableToPredicate(auraCard));
TargetPermanent targetCreature = new TargetPermanent(filterAttachTo);
targetCreature.setNotTarget(true);
if (controller.choose(Outcome.PutCardInPlay, targetCreature, source.getSourceId(), game)) {
Permanent targetPermanent = game.getPermanent(targetCreature.getFirstTarget());
if (!targetPermanent.cantBeAttachedBy(auraCard, source, game, true)) {
game.getState().setValue("attachTo:" + auraCard.getId(), targetPermanent);
controller.moveCards(auraCard, Zone.BATTLEFIELD, source, game);
targetPermanent.addAttachment(auraCard.getId(), source, game);
Permanent permanent = game.getPermanent(auraId);
if (permanent != null) {
toExile.add(permanent);
}
}
}
}
}
ContinuousEffect continuousEffect = new StormHeraldReplacementEffect();
continuousEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addEffect(continuousEffect, source);
Effect exileEffect = new ExileTargetEffect("exile those Auras");
exileEffect.setTargetPointer(new FixedTargets(toExile, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class DeterminedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetControlledPermanent target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent("a creature (to sacrifice)"), true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.chooseTarget(outcome, target, source, game)) {
Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
if (toSacrifice != null) {
toSacrifice.sacrifice(source, game);
game.getState().processAction(game);
int colors = toSacrifice.getColor(game).getColorCount();
if (colors > 0) {
TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(0, colors, new FilterCard("up to " + colors + " card" + (colors > 1 ? "s" : "") + " from your graveyard"));
controller.chooseTarget(outcome, targetCard, source, game);
controller.moveCards(new CardsImpl(targetCard.getTargets()), Zone.HAND, source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class CataclysmEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
Target target2 = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
Target target3 = new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
Target target4 = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target1, source, game);
}
Permanent artifact = game.getPermanent(target1.getFirstTarget());
if (artifact != null) {
chosen.add(artifact);
}
target1.clearChosen();
}
if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target2, source, game);
}
Permanent creature = game.getPermanent(target2.getFirstTarget());
if (creature != null) {
chosen.add(creature);
}
target2.clearChosen();
}
if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target3, source, game);
}
Permanent enchantment = game.getPermanent(target3.getFirstTarget());
if (enchantment != null) {
chosen.add(enchantment);
}
target3.clearChosen();
}
if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Benefit, target4, source, game);
}
Permanent land = game.getPermanent(target4.getFirstTarget());
if (land != null) {
chosen.add(land);
}
target4.clearChosen();
}
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (!chosen.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
return true;
}
use of mage.filter.common.FilterControlledCreaturePermanent in project mage by magefree.
the class KindredSummonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (subType == null) {
return false;
}
FilterControlledCreaturePermanent filterPermanent = new FilterControlledCreaturePermanent("creature you control of the chosen type");
filterPermanent.add(subType.getPredicate());
int numberOfCards = game.getBattlefield().countAll(filterPermanent, source.getControllerId(), game);
Cards revealed = new CardsImpl();
Set<Card> chosenSubtypeCreatureCards = new LinkedHashSet<>();
Cards otherCards = new CardsImpl();
FilterCreatureCard filterCard = new FilterCreatureCard("creature card of the chosen type");
filterCard.add(subType.getPredicate());
if (numberOfCards == 0) {
// no matches so nothing is revealed
game.informPlayers("There are 0 creature cards of the chosen type in " + controller.getName() + "'s library.");
return true;
}
for (Card card : controller.getLibrary().getCards(game)) {
revealed.add(card);
if (card != null && filterCard.match(card, game)) {
chosenSubtypeCreatureCards.add(card);
if (chosenSubtypeCreatureCards.size() == numberOfCards) {
break;
}
} else {
otherCards.add(card);
}
}
controller.revealCards(source, revealed, game);
controller.moveCards(chosenSubtypeCreatureCards, Zone.BATTLEFIELD, source, game);
if (!otherCards.isEmpty()) {
controller.putCardsOnTopOfLibrary(otherCards, game, source, false);
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
Aggregations