use of mage.cards.Cards in project mage by magefree.
the class ScalpelexisEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (targetPlayer == null) {
return false;
}
Set<String> cardNames = new HashSet<>();
boolean doubleName;
do {
doubleName = false;
Cards toExile = new CardsImpl(targetPlayer.getLibrary().getTopCards(game, 4));
cardNames.clear();
for (Card card : toExile.getCards(game)) {
if (cardNames.contains(card.getName())) {
doubleName = true;
break;
} else {
cardNames.add(card.getName());
}
}
targetPlayer.moveCards(toExile, Zone.EXILED, source, game);
} while (doubleName);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class ShrineOfPiercingVisionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
if (player == null || permanent == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, permanent.getCounters(game).getCount(CounterType.CHARGE)));
if (!cards.isEmpty()) {
player.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
if (player.choose(Outcome.DrawCard, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
player.moveCards(card, Zone.HAND, source, game);
}
}
player.putCardsOnBottomOfLibrary(cards, game, source, true);
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class SoulflayerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
// one time abilities collect
if (objectReference == null || !objectReference.refersTo(permanent, game)) {
abilitiesToAdd = new HashSet<>();
this.objectReference = new MageObjectReference(permanent, game);
String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
Cards delvedCards = (Cards) game.getState().getValue(keyString);
if (delvedCards != null) {
for (Card card : delvedCards.getCards(game)) {
if (!card.isCreature(game)) {
continue;
}
for (Ability cardAbility : card.getAbilities(game)) {
if (cardAbility instanceof FlyingAbility) {
abilitiesToAdd.add(FlyingAbility.getInstance());
}
if (cardAbility instanceof FirstStrikeAbility) {
abilitiesToAdd.add(FirstStrikeAbility.getInstance());
}
if (cardAbility instanceof DoubleStrikeAbility) {
abilitiesToAdd.add(DoubleStrikeAbility.getInstance());
}
if (cardAbility instanceof DeathtouchAbility) {
abilitiesToAdd.add(DeathtouchAbility.getInstance());
}
if (cardAbility instanceof HasteAbility) {
abilitiesToAdd.add(HasteAbility.getInstance());
}
if (cardAbility instanceof HexproofBaseAbility) {
abilitiesToAdd.add(HexproofAbility.getInstance());
}
if (cardAbility instanceof IndestructibleAbility) {
abilitiesToAdd.add(IndestructibleAbility.getInstance());
}
if (cardAbility instanceof LifelinkAbility) {
abilitiesToAdd.add(LifelinkAbility.getInstance());
}
if (cardAbility instanceof ReachAbility) {
abilitiesToAdd.add(ReachAbility.getInstance());
}
if (cardAbility instanceof TrampleAbility) {
abilitiesToAdd.add(TrampleAbility.getInstance());
}
if (cardAbility instanceof VigilanceAbility) {
abilitiesToAdd.add(VigilanceAbility.getInstance());
}
}
}
}
}
// all time abilities apply
for (Ability ability : abilitiesToAdd) {
permanent.addAbility(ability, source.getSourceId(), game);
}
return true;
} else if (abilitiesToAdd != null) {
abilitiesToAdd = null;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class SzatsWillEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).map(Player::getGraveyard).flatMap(Collection::stream).collect(Collectors.toSet()));
player.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
int maxPower = cards.getCards(game).stream().filter(Objects::nonNull).filter(card -> card.isCreature(game)).map(MageObject::getPower).mapToInt(MageInt::getValue).max().orElse(0);
if (maxPower > 0) {
new BreedingPitThrullToken().putOntoBattlefield(maxPower, game, source, source.getControllerId());
}
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class ThoughtpickerWitchEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) {
Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
if (!cards.isEmpty()) {
TargetCard target = new TargetCardInLibrary(new FilterCard("card to exile"));
if (controller.choose(Outcome.Exile, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
opponent.moveCards(card, Zone.EXILED, source, game);
}
}
}
return true;
}
return false;
}
Aggregations