use of mage.filter.common.FilterArtifactCard in project mage by magefree.
the class ScrapMasteryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, Set<Card>> exiledCards = new HashMap<>();
// exile artifacts from graveyard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Set<Card> cards = player.getGraveyard().getCards(new FilterArtifactCard(), game);
controller.moveCards(cards, Zone.EXILED, source, game);
exiledCards.put(player.getId(), cards);
}
}
// sacrifice all artifacts
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterArtifactPermanent(), playerId, game)) {
permanent.sacrifice(source, game);
}
}
}
// puts all cards they exiled this way onto the battlefield
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.moveCards(exiledCards.get(playerId), Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterArtifactCard in project mage by magefree.
the class ScroungeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (controller != null && opponent != null) {
FilterArtifactCard filter = new FilterArtifactCard();
filter.add(new OwnerIdPredicate(opponent.getId()));
TargetCardInGraveyard chosenCard = new TargetCardInGraveyard(filter);
chosenCard.setNotTarget(true);
if (chosenCard.canChoose(source.getSourceId(), opponent.getId(), game)) {
opponent.chooseTarget(Outcome.ReturnToHand, chosenCard, source, game);
Card card = game.getCard(chosenCard.getFirstTarget());
if (card != null) {
game.informPlayers("Scrounge: " + opponent.getLogName() + " has chosen " + card.getLogName());
Cards cardsToMove = new CardsImpl();
cardsToMove.add(card);
controller.moveCards(cardsToMove, Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.filter.common.FilterArtifactCard in project mage by magefree.
the class OswaldFiddlebenderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent sacrificed = source.getCosts().stream().filter(SacrificeTargetCost.class::isInstance).map(SacrificeTargetCost.class::cast).map(SacrificeTargetCost::getPermanents).flatMap(Collection::stream).findFirst().orElse(null);
if (player == null || sacrificed == null) {
return false;
}
FilterCard filterCard = new FilterArtifactCard("artifact card with mana value " + (sacrificed.getManaValue() + 1));
filterCard.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, sacrificed.getManaValue() + 1));
TargetCardInLibrary target = new TargetCardInLibrary(filterCard);
player.searchLibrary(target, source, game);
Card card = player.getLibrary().getCard(target.getFirstTarget(), game);
player.moveCards(card, Zone.BATTLEFIELD, source, game);
player.shuffleLibrary(source, game);
return true;
}
use of mage.filter.common.FilterArtifactCard in project mage by magefree.
the class ThadaAdelPlayFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player damagedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || damagedPlayer == null || sourceObject == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(new FilterArtifactCard());
if (controller.searchLibrary(target, source, game, damagedPlayer.getId())) {
if (!target.getTargets().isEmpty()) {
Card card = damagedPlayer.getLibrary().remove(target.getFirstTarget(), game);
if (card != null) {
controller.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getIdName(), source, game, Zone.LIBRARY, true);
ContinuousEffect effect = new ThadaAdelPlayFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
}
}
damagedPlayer.shuffleLibrary(source, game);
return true;
}
use of mage.filter.common.FilterArtifactCard in project mage by magefree.
the class ScrapTrawlerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (((ZoneChangeEvent) event).getToZone() == Zone.GRAVEYARD && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = ((ZoneChangeEvent) event).getTarget();
if (permanent != null && permanent.isControlledBy(this.getControllerId()) && permanent.isArtifact(game)) {
FilterCard filter = new FilterArtifactCard("artifact card in your graveyard with mana value less than " + permanent.getManaCost().manaValue());
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, permanent.getManaCost().manaValue()));
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
getTargets().clear();
addTarget(target);
return true;
}
}
return false;
}
Aggregations