use of mage.cards.Card in project mage by magefree.
the class FertileImaginationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (player != null && opponent != null && sourceObject != null) {
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
CardType type = null;
String choosenType = choiceImpl.getChoice();
if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.LAND;
} else if (choosenType.equals(CardType.CREATURE.toString())) {
type = CardType.CREATURE;
} else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
type = CardType.ENCHANTMENT;
} else if (choosenType.equals(CardType.INSTANT.toString())) {
type = CardType.INSTANT;
} else if (choosenType.equals(CardType.SORCERY.toString())) {
type = CardType.SORCERY;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
type = CardType.PLANESWALKER;
} else if (choosenType.equals(CardType.TRIBAL.toString())) {
type = CardType.TRIBAL;
}
if (type != null) {
Cards hand = opponent.getHand();
SaprolingToken saprolingToken = new SaprolingToken();
opponent.revealCards(sourceObject.getIdName(), hand, game);
Set<Card> cards = hand.getCards(game);
int tokensToMake = 0;
for (Card card : cards) {
if (card != null && card.getCardType(game).contains(type)) {
tokensToMake += 2;
}
}
game.informPlayers(sourceObject.getLogName() + " creates " + (tokensToMake == 0 ? "no" : "" + tokensToMake) + " 1/1 green Saproling creature tokens.");
saprolingToken.putOntoBattlefield(tokensToMake, game, source, source.getControllerId());
return true;
}
}
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class FroghemothEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<Card> cardsToExile = new HashSet<>();
int numCounters = 0;
int lifeGain = 0;
for (UUID cardId : getTargetPointer().getTargets(game, source)) {
Card card = game.getCard(cardId);
if (card != null && game.getState().getZone(cardId) == Zone.GRAVEYARD && cardsToExile.add(card)) {
if (card.isCreature(game)) {
numCounters++;
} else {
lifeGain++;
}
}
}
if (!cardsToExile.isEmpty()) {
controller.moveCards(cardsToExile, Zone.EXILED, source, game);
if (numCounters > 0) {
Permanent permanent = source.getSourcePermanentIfItStillExists(game);
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(numCounters), source.getControllerId(), source, game);
}
}
if (lifeGain > 0) {
controller.gainLife(lifeGain, game, source);
}
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class GlyphOfReincarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && targetWall != null) {
BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
if (watcher != null) {
Map<UUID, Player> destroyed = new HashMap<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!creature.getId().equals(targetWall.getId())) {
if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
// If a commander is replaced to command zone, the creature does not die
Player permController = game.getPlayer(creature.getControllerId());
if (permController != null) {
destroyed.put(creature.getId(), permController);
}
}
}
}
}
// onto the battlefield under its owner’s control
for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
Player player = entry.getValue();
if (permanent != null && player != null) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
Target targetCreature = new TargetCardInGraveyard(filter);
targetCreature.setNotTarget(true);
if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
Card card = game.getCard(targetCreature.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
}
return true;
}
}
return false;
}
use of mage.cards.Card in project mage by magefree.
the class GlowsporeShamanEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetCardInYourGraveyard(0, 1, filter, true);
if (player.chooseUse(outcome, "Put a land card on top of your library?", source, game) && player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
}
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class HaukensInsightWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
MageObject sourceObject = source.getSourceObject(game);
String exileName = sourceObject == null ? null : sourceObject.getIdName();
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
if (game.getState().getZone(card.getId()) == Zone.EXILED) {
card.setFaceDown(true, game);
HaukensInsightLookEffect effect = new HaukensInsightLookEffect(controller.getId());
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
return true;
}
}
}
return false;
}
Aggregations