use of mage.filter.FilterPermanent in project mage by magefree.
the class NecriteTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
FilterPermanent filter = new FilterCreaturePermanent();
filter.add(new ControllerIdPredicate(defendingPlayerId));
Target target = new TargetPermanent(filter);
this.getTargets().clear();
this.addTarget(target);
return true;
}
return false;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class RareBGoneEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPermanent, playerId, game)) {
permanent.sacrifice(source, game);
}
Cards cards = player.getHand();
player.revealCards(source, cards, game);
player.discard(new CardsImpl(cards.getCards(filterCard, game)), false, source, game);
}
return true;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class SasayasEssenceManaEffect method getNetMana.
@Override
public List<Mana> getNetMana(Game game, Ability source) {
List<Mana> netMana = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
Mana producedMana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && producedMana != null && permanent != null) {
FilterPermanent filter = new FilterLandPermanent();
filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
filter.add(new NamePredicate(permanent.getName()));
int count = game.getBattlefield().countAll(filter, controller.getId(), game);
if (count > 0) {
if (producedMana.getBlack() > 0) {
netMana.add(Mana.BlackMana(count));
}
if (producedMana.getRed() > 0) {
netMana.add(Mana.RedMana(count));
}
if (producedMana.getBlue() > 0) {
netMana.add(Mana.BlueMana(count));
}
if (producedMana.getGreen() > 0) {
netMana.add(Mana.GreenMana(count));
}
if (producedMana.getWhite() > 0) {
netMana.add(Mana.WhiteMana(count));
}
if (producedMana.getColorless() > 0) {
netMana.add(Mana.ColorlessMana(count));
}
}
}
return netMana;
}
use of mage.filter.FilterPermanent in project mage by magefree.
the class ShamanOfForgottenWaysEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
FilterPermanent filter = new FilterCreaturePermanent();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int numberCreatures = game.getBattlefield().getAllActivePermanents(filter, playerId, game).size();
player.setLife(numberCreatures, game, source);
}
}
return true;
}
return false;
}
use of mage.filter.FilterPermanent 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;
}
Aggregations