use of mage.constants.CardType in project mage by magefree.
the class CounterlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (stackObject != null && controller != null) {
game.getStack().counter(source.getFirstTarget(), source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
FilterCard filter = new FilterCard();
List<Predicate<MageObject>> types = new ArrayList<>();
for (CardType type : stackObject.getCardType(game)) {
if (type != CardType.LAND) {
types.add(type.getPredicate());
}
}
filter.add(Predicates.or(types));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.constants.CardType 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.constants.CardType in project mage by magefree.
the class AminatousAuguryCastFromExileEffect method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
Player player = game.getPlayer(affectedControllerId);
EnumSet<CardType> usedCardTypes = EnumSet.noneOf(CardType.class);
if (game.getState().getValue(source.getSourceId().toString() + "cardTypes") != null) {
usedCardTypes = (EnumSet<CardType>) game.getState().getValue(source.getSourceId().toString() + "cardTypes");
}
if (player != null && objectId != null && objectId.equals(getTargetPointer().getFirst(game, source)) && affectedControllerId.equals(source.getControllerId())) {
Card card = game.getCard(objectId);
if (card != null && game.getState().getZone(objectId) == Zone.EXILED) {
EnumSet<CardType> unusedCardTypes = EnumSet.noneOf(CardType.class);
for (CardType cardT : card.getCardType(game)) {
if (!usedCardTypes.contains(cardT)) {
unusedCardTypes.add(cardT);
}
}
if (!unusedCardTypes.isEmpty()) {
if (!game.inCheckPlayableState()) {
// Select the card type to consume and remove all not seleczted card types
if (unusedCardTypes.size() > 1) {
Choice choice = new ChoiceImpl(true);
choice.setMessage("Which card type do you want to consume?");
Set<String> choices = choice.getChoices();
for (CardType cardType : unusedCardTypes) {
choices.add(cardType.toString());
}
player.choose(Outcome.Detriment, choice, game);
for (Iterator<CardType> iterator = unusedCardTypes.iterator(); iterator.hasNext(); ) {
CardType next = iterator.next();
if (!next.toString().equals(choice.getChoice())) {
iterator.remove();
}
}
usedCardTypes.add(CardType.fromString(choice.getChoice()));
}
usedCardTypes.addAll(unusedCardTypes);
game.getState().setValue(source.getSourceId().toString() + "cardTypes", usedCardTypes);
}
player.setCastSourceIdWithAlternateMana(objectId, null, card.getSpellAbility().getCosts());
return true;
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class MuldrothaTheGravetideWatcher method addPermanentTypes.
private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
UUID playerId = null;
if (mageObject instanceof Spell) {
playerId = ((Spell) mageObject).getControllerId();
} else if (mageObject instanceof Permanent) {
playerId = ((Permanent) mageObject).getControllerId();
}
if (playerId != null) {
Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
if (permanentTypes == null) {
permanentTypes = EnumSet.noneOf(CardType.class);
sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
}
Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
for (CardType cardType : mageObject.getCardType(game)) {
if (cardType.isPermanentType()) {
if (!permanentTypes.contains(cardType)) {
typesNotCast.add(cardType);
}
}
}
if (typesNotCast.size() <= 1) {
permanentTypes.addAll(typesNotCast);
} else {
Player player = game.getPlayer(playerId);
if (player != null) {
Choice typeChoice = new ChoiceImpl(true);
typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
for (CardType cardType : typesNotCast) {
typeChoice.getChoices().add(cardType.toString());
}
if (player.choose(Outcome.Detriment, typeChoice, game)) {
String typeName = typeChoice.getChoice();
CardType chosenType = null;
for (CardType cardType : CardType.values()) {
if (cardType.toString().equals(typeName)) {
chosenType = cardType;
break;
}
}
if (chosenType != null) {
permanentTypes.add(chosenType);
}
}
}
}
}
}
}
use of mage.constants.CardType in project mage by magefree.
the class ReweaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (permanent != null && sourceObject != null) {
if (permanent.sacrifice(source, game)) {
Player permanentController = game.getPlayer(permanent.getControllerId());
if (permanentController != null) {
Library library = permanentController.getLibrary();
if (library.hasCards()) {
Cards cards = new CardsImpl();
Card permanentCard = null;
for (Card card : permanentController.getLibrary().getCards(game)) {
cards.add(card);
if (card.isPermanent(game)) {
for (CardType cardType : permanent.getCardType(game)) {
if (card.getCardType(game).contains(cardType)) {
permanentCard = card;
break;
}
}
}
}
permanentController.revealCards(source, cards, game);
if (permanentCard != null) {
permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
}
permanentController.shuffleLibrary(source, game);
}
return true;
}
return false;
}
}
return true;
}
Aggregations