use of mage.constants.CardType in project mage by magefree.
the class RiteOfRuinEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Set<String> choices = new HashSet<>();
choices.add("Artifacts");
choices.add("Creatures");
choices.add("Lands");
LinkedList<CardType> order = new LinkedList<>();
ChoiceImpl choice = new ChoiceImpl(true);
choice.setMessage("Choose a card type");
choice.setChoices(choices);
while (choices.size() > 1) {
if (!controller.choose(Outcome.Sacrifice, choice, game)) {
return false;
}
order.add(getCardType(choice.getChoice()));
choices.remove(choice.getChoice());
choice.clearChoice();
}
order.add(getCardType(choices.iterator().next()));
int count = 1;
for (CardType cardType : order) {
FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " you control");
filter.add(cardType.getPredicate());
new SacrificeAllEffect(count, filter).apply(game, source);
count++;
}
return true;
}
use of mage.constants.CardType in project mage by magefree.
the class HolisticWisdomEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
for (Cost cost : source.getCosts()) {
if (cost instanceof ExileFromHandCost) {
List<CardType> cardtypes = new ArrayList<>();
ExileFromHandCost exileCost = (ExileFromHandCost) cost;
for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
cardtypes.add(cardtype);
}
for (CardType cardtype : card.getCardType(game)) {
if (cardtypes.contains(cardtype)) {
Effect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
return effect.apply(game, source);
}
}
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class RowdyCrewEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.drawCards(3, source, game);
Cards cards = new CardsImpl();
int cardsInHand = player.getHand().size();
switch(cardsInHand) {
case 0:
break;
case 1:
player.discard(1, true, false, source, game);
break;
default:
cards = player.discard(2, true, false, source, game);
}
if (creature != null && cardsInHand > 1) {
for (CardType type : CardType.values()) {
int count = 0;
for (UUID cardId : cards) {
if (game.getCard(cardId).getCardType(game).contains(type)) {
count++;
if (count > 1) {
creature.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game);
return true;
}
}
}
}
}
return true;
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class CopyTokenFunction method apply.
@Override
public Token apply(Card source, Game game) {
if (target == null) {
throw new IllegalArgumentException("Target can't be null");
}
// A copy contains only the attributes of the basic card or basic Token that's the base of the permanent
// else gained abililies would be copied too.
MageObject sourceObj = source;
if (source instanceof PermanentToken) {
sourceObj = ((PermanentToken) source).getToken();
// to show the source image, the original values have to be used
target.setOriginalExpansionSetCode(((Token) sourceObj).getOriginalExpansionSetCode());
target.setOriginalCardNumber(((Token) sourceObj).getOriginalCardNumber());
target.setCopySourceCard(((PermanentToken) source).getToken().getCopySourceCard());
} else if (source instanceof PermanentCard) {
if (((PermanentCard) source).isMorphed() || ((PermanentCard) source).isManifested()) {
MorphAbility.setPermanentToFaceDownCreature(target, game);
return target;
} else {
if (((PermanentCard) source).isTransformed() && source.getSecondCardFace() != null) {
sourceObj = ((PermanentCard) source).getSecondCardFace();
} else {
sourceObj = ((PermanentCard) source).getCard();
}
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
target.setCopySourceCard((Card) sourceObj);
}
} else {
target.setOriginalExpansionSetCode(source.getExpansionSetCode());
target.setOriginalCardNumber(source.getCardNumber());
target.setCopySourceCard(source);
}
// modify all attributes permanently (without game usage)
target.setName(sourceObj.getName());
target.getColor().setColor(sourceObj.getColor());
target.getManaCost().clear();
target.getManaCost().add(sourceObj.getManaCost().copy());
target.removeAllCardTypes();
for (CardType type : sourceObj.getCardType()) {
target.addCardType(type);
}
target.getSubtype().copyFrom(sourceObj.getSubtype());
target.getSuperType().clear();
for (SuperType type : sourceObj.getSuperType()) {
target.addSuperType(type);
}
target.getAbilities().clear();
for (Ability ability0 : sourceObj.getAbilities()) {
Ability ability = ability0.copy();
// The token is independant from the copy from object so it need a new original Id,
// otherwise there are problems to check for created continuous effects to check if
// the source (the Token) has still this ability
ability.newOriginalId();
target.addAbility(ability);
}
target.getPower().modifyBaseValue(sourceObj.getPower().getBaseValueModified());
target.getToughness().modifyBaseValue(sourceObj.getToughness().getBaseValueModified());
target.setStartingLoyalty(sourceObj.getStartingLoyalty());
return target;
}
use of mage.constants.CardType in project mage by magefree.
the class RealityScrambleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (permanent == null || controller == null) {
return false;
}
Set<CardType> types = EnumSet.noneOf(CardType.class);
types.addAll(permanent.getCardType(game));
controller.putCardsOnBottomOfLibrary(new CardsImpl(permanent), game, source, false);
Cards toReveal = new CardsImpl();
Card cardToPlay = null;
for (Card card : controller.getLibrary().getCards(game)) {
toReveal.add(card);
for (CardType type : types) {
if (card.getCardType(game).contains(type)) {
cardToPlay = card;
break;
}
}
if (cardToPlay != null) {
break;
}
}
controller.revealCards(source, toReveal, game);
if (cardToPlay != null) {
controller.moveCards(cardToPlay, Zone.BATTLEFIELD, source, game);
toReveal.remove(cardToPlay);
}
controller.putCardsOnBottomOfLibrary(toReveal, game, source, false);
return true;
}
Aggregations