use of mage.cards.Cards in project mage by magefree.
the class CurseOfTheSwineEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Cards creaturesToExile = new CardsImpl();
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (UUID targetId : this.getTargetPointer().getTargets(game, source)) {
Permanent creature = game.getPermanent(targetId);
// TODO implement a way to verify that tokens are indeed exiled from the battlefield
if (creature instanceof PermanentToken) {
playersWithTargets.put(creature.getControllerId(), playersWithTargets.getOrDefault(creature.getControllerId(), 0) + 1);
}
if (creature != null) {
creaturesToExile.add(creature);
}
}
// move creatures to exile all at once
controller.moveCards(creaturesToExile, Zone.EXILED, source, game);
// Count all creatures actually exiled and add them to the player's count
for (Card card : creaturesToExile.getCards(game)) {
Permanent lkiP = game.getPermanentOrLKIBattlefield(card.getId());
// note that tokens have no LKI once they are moved from the battlefield so they are handled earlier
if (lkiP != null && game.getState().getZone(lkiP.getId()) == Zone.EXILED) {
playersWithTargets.put(lkiP.getControllerId(), playersWithTargets.getOrDefault(lkiP.getControllerId(), 0) + 1);
}
}
Boar2Token swineToken = new Boar2Token();
for (Map.Entry<UUID, Integer> exiledByController : playersWithTargets.entrySet()) {
swineToken.putOntoBattlefield(exiledByController.getValue(), game, source, exiledByController.getKey());
}
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class GamePreserveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
cards.add(player.getLibrary().getFromTop(game));
}
}
controller.revealCards(source, cards, game);
if (cards.isEmpty() || cards.count(StaticFilters.FILTER_CARD_NON_CREATURE, game) > 0) {
return false;
}
controller.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class HarnessInfinityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards hand = new CardsImpl(player.getHand());
Cards graveyard = new CardsImpl(player.getGraveyard());
player.moveCards(hand, Zone.GRAVEYARD, source, game);
player.moveCards(graveyard, Zone.HAND, source, game);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class HarmonicConvergenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
FilterEnchantmentPermanent filter = new FilterEnchantmentPermanent();
filter.add(new OwnerIdPredicate(player.getId()));
Cards toLib = new CardsImpl();
for (Permanent enchantment : game.getBattlefield().getActivePermanents(filter, playerId, source.getSourceId(), game)) {
toLib.add(enchantment);
}
player.putCardsOnTopOfLibrary(toLib, game, source, true);
}
}
return true;
}
use of mage.cards.Cards 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