use of mage.constants.CardType in project mage by magefree.
the class WorldQuellerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Card> chosen = new ArrayList<>();
Player player = game.getPlayer(source.getControllerId());
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (player != null && sourceCreature != null) {
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
return false;
}
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) {
FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control of type " + type.toString());
filter.add(type.getPredicate());
TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false);
target.setNotTarget(true);
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player2 = game.getPlayer(playerId);
if (player2 != null && target.canChoose(source.getSourceId(), playerId, game)) {
while (player2.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), playerId, game)) {
player2.chooseTarget(Outcome.Sacrifice, target, source, game);
}
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent != null) {
chosen.add(permanent);
}
target.clearChosen();
}
}
// all chosen permanents are sacrificed together
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (chosen.contains(permanent)) {
permanent.sacrifice(source, game);
}
}
return true;
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class VerifyCardDataTest method checkSubtypes.
private void checkSubtypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_SUBTYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
Collection<String> expected = ref.subtypes;
// fix names (e.g. Urza’s to Urza's)
if (expected != null && expected.contains("Urza’s")) {
expected = new ArrayList<>(expected);
for (ListIterator<String> it = ((List<String>) expected).listIterator(); it.hasNext(); ) {
if (it.next().equals("Urza’s")) {
it.set("Urza's");
}
}
}
// Remove subtypes that need to be ignored
Collection<String> actual = card.getSubtype().stream().map(SubType::toString).collect(Collectors.toSet());
actual.removeIf(subtypesToIgnore::contains);
if (expected != null) {
expected.removeIf(subtypesToIgnore::contains);
}
for (SubType subType : card.getSubtype()) {
if (!subType.isCustomSet() && !subType.canGain(card)) {
String cardTypeString = card.getCardType().stream().map(CardType::toString).reduce((a, b) -> a + " " + b).orElse("");
fail(card, "subtypes", "card has subtype " + subType.getDescription() + " (" + subType.getSubTypeSet() + ')' + " that doesn't match its card type(s) (" + cardTypeString + ')');
}
}
if (!eqSet(actual, expected)) {
fail(card, "subtypes", actual + " != " + expected);
}
}
use of mage.constants.CardType in project mage by magefree.
the class BloodOathEffect 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();
opponent.revealCards(sourceObject.getIdName(), hand, game);
Set<Card> cards = hand.getCards(game);
int damageToDeal = 0;
for (Card card : cards) {
if (card != null && card.getCardType(game).contains(type)) {
damageToDeal += 3;
}
}
game.informPlayers(sourceObject.getLogName() + " deals " + (damageToDeal == 0 ? "no" : "" + damageToDeal) + " damage to " + opponent.getLogName());
opponent.damage(damageToDeal, source.getSourceId(), source, game);
return true;
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class CreepingRenaissanceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Choice typeChoice = new ChoiceCardType(true, Arrays.stream(CardType.values()).filter(CardType::isPermanentType).collect(Collectors.toList()));
typeChoice.setMessage("Choose a permanent type");
if (!controller.choose(Outcome.ReturnToHand, typeChoice, game)) {
return false;
}
String typeName = typeChoice.getChoice();
CardType chosenType = CardType.fromString(typeChoice.getChoice());
if (chosenType == null) {
return false;
}
FilterCard filter = new FilterCard(chosenType.toString().toLowerCase(Locale.ENGLISH) + " card");
filter.add(chosenType.getPredicate());
return controller.moveCards(controller.getGraveyard().getCards(filter, source.getSourceId(), controller.getId(), game), Zone.HAND, source, game);
}
use of mage.constants.CardType in project mage by magefree.
the class MythosOfSnapdaxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean conditionMet = condition.apply(game, source);
List<Player> playerList = game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).filter(Objects::nonNull).collect(Collectors.toList());
Set<UUID> toKeep = new HashSet();
for (Player player : playerList) {
for (CardType cardType : cardTypes) {
String message = cardType.toString().equals("Artifact") ? "an " : "a ";
message += cardType.toString().toLowerCase(Locale.ENGLISH);
message += (conditionMet && player != controller) ? " controlled by " + player.getName() : " you control";
FilterPermanent filter = new FilterNonlandPermanent(message);
filter.add(cardType.getPredicate());
filter.add(new ControllerIdPredicate(player.getId()));
if (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (conditionMet) {
controller.choose(outcome, target, source.getSourceId(), game);
} else {
player.choose(outcome, target, source.getSourceId(), game);
}
toKeep.add(target.getFirstTarget());
}
}
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_NON_LAND, source.getControllerId(), game)) {
if (permanent == null || toKeep.contains(permanent.getId())) {
continue;
}
permanent.sacrifice(source, game);
}
return true;
}
Aggregations