use of mage.game.permanent.token.SaprolingToken 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.game.permanent.token.SaprolingToken in project mage by magefree.
the class FlashFoliageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Token token = new SaprolingToken();
token.putOntoBattlefield(1, game, source, source.getControllerId());
Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (attackingCreature != null && game.getState().getCombat() != null) {
// Possible ruling (see Aetherplasm)
// The token you created is blocking the attacking creature,
// even if the block couldn't legally be declared (for example, if that creature
// enters the battlefield tapped, or it can't block, or the attacking creature
// has protection from it)
CombatGroup combatGroup = game.getState().getCombat().findGroup(attackingCreature.getId());
if (combatGroup != null) {
for (UUID tokenId : token.getLastAddedTokenIds()) {
Permanent saprolingToken = game.getPermanent(tokenId);
if (saprolingToken != null) {
combatGroup.addBlocker(tokenId, source.getControllerId(), game);
game.getCombat().addBlockingGroup(tokenId, attackingCreature.getId(), controller.getId(), game);
}
}
combatGroup.pickBlockerOrder(attackingCreature.getControllerId(), game);
}
}
return true;
}
return false;
}
use of mage.game.permanent.token.SaprolingToken in project mage by magefree.
the class DruidicSatchelEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
controller.revealCards(source, new CardsImpl(card), game);
if (card.isCreature(game)) {
new SaprolingToken().putOntoBattlefield(1, game, source, source.getControllerId());
}
if (card.isLand(game)) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
if (!card.isCreature(game) && !card.isLand(game)) {
controller.gainLife(2, game, source);
}
}
return true;
}
use of mage.game.permanent.token.SaprolingToken in project mage by magefree.
the class LastStandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
// Target opponent loses 2 life for each Swamp you control
Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (opponent != null) {
int swamps = game.getBattlefield().count(filterSwamp, source.getSourceId(), source.getControllerId(), game);
opponent.loseLife(swamps * 2, game, source, false);
}
// Last Stand deals damage equal to the number of Mountains you control to target creature.
Permanent creature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (creature != null) {
int mountains = game.getBattlefield().count(filterMountain, source.getSourceId(), source.getControllerId(), game);
if (mountains > 0) {
creature.damage(mountains, source.getSourceId(), source, game, false, true);
}
}
// Create a 1/1 green Saproling creature token for each Forest you control.
int forests = game.getBattlefield().count(filterForest, source.getSourceId(), source.getControllerId(), game);
if (forests > 0) {
new CreateTokenEffect(new SaprolingToken(), forests).apply(game, source);
}
// You gain 2 life for each Plains you control.
int plains = game.getBattlefield().count(filterPlains, source.getSourceId(), source.getControllerId(), game);
controller.gainLife(plains * 2, game, source);
// Draw a card for each Island you control, then discard that many cards
int islands = game.getBattlefield().count(filterIsland, source.getSourceId(), source.getControllerId(), game);
if (islands > 0) {
controller.drawCards(islands, source, game);
controller.discard(islands, false, false, source, game);
}
}
return false;
}
use of mage.game.permanent.token.SaprolingToken in project mage by magefree.
the class RithTheAwakenerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
ChoiceColor choice = new ChoiceColor();
if (controller.choose(outcome, choice, game)) {
game.informPlayers(controller.getLogName() + " chooses " + choice.getColor());
FilterPermanent filter = new FilterPermanent();
filter.add(new ColorPredicate(choice.getColor()));
int cardsWithColor = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
if (cardsWithColor > 0) {
new CreateTokenEffect(new SaprolingToken(), cardsWithColor).apply(game, source);
}
return true;
}
return false;
}
Aggregations