use of mage.constants.CardType in project mage by magefree.
the class CardCriteria method buildQuery.
public void buildQuery(QueryBuilder qb) throws SQLException {
optimize();
Where where = qb.where();
where.eq("nightCard", false);
where.eq("splitCardHalf", false);
int clausesCount = 2;
if (name != null) {
where.like("name", new SelectArg('%' + name + '%'));
clausesCount++;
}
if (nameExact != null) {
where.like("name", new SelectArg(nameExact));
clausesCount++;
}
if (rules != null) {
where.like("rules", new SelectArg('%' + rules + '%'));
clausesCount++;
}
if (doubleFaced != null) {
where.eq("doubleFaced", doubleFaced);
clausesCount++;
}
if (modalDoubleFaced != null) {
where.eq("modalDoubleFacesCard", modalDoubleFaced);
clausesCount++;
}
for (Rarity rarity : rarities) {
where.eq("rarity", rarity);
}
if (!rarities.isEmpty()) {
where.or(rarities.size());
clausesCount++;
}
for (String setCode : setCodes) {
where.eq("setCode", setCode);
}
if (!setCodes.isEmpty()) {
where.or(setCodes.size());
clausesCount++;
}
for (String ignoreSetCode : ignoreSetCodes) {
where.ne("setCode", ignoreSetCode);
}
if (!ignoreSetCodes.isEmpty()) {
where.or(ignoreSetCodes.size());
clausesCount++;
}
if (types.size() != 7) {
// if all types selected - no selection needed (Tribal and Conspiracy not selectable yet)
for (CardType type : types) {
where.like("types", new SelectArg('%' + type.name() + '%'));
}
if (!types.isEmpty()) {
where.or(types.size());
clausesCount++;
}
}
for (CardType type : notTypes) {
where.not().like("types", new SelectArg('%' + type.name() + '%'));
clausesCount++;
}
for (SuperType superType : supertypes) {
where.like("supertypes", new SelectArg('%' + superType.name() + '%'));
clausesCount++;
}
for (SuperType superType : notSupertypes) {
where.not().like("supertypes", new SelectArg('%' + superType.name() + '%'));
clausesCount++;
}
for (SubType subType : subtypes) {
where.like("subtypes", new SelectArg('%' + subType.toString() + '%'));
clausesCount++;
}
if (manaValue != null) {
where.eq("manaValue", manaValue);
clausesCount++;
}
int colorClauses = 0;
if (black) {
where.eq("black", true);
colorClauses++;
}
if (blue) {
where.eq("blue", true);
colorClauses++;
}
if (green) {
where.eq("green", true);
colorClauses++;
}
if (red) {
where.eq("red", true);
colorClauses++;
}
if (white) {
where.eq("white", true);
colorClauses++;
}
if (colorless) {
where.eq("black", false).eq("blue", false).eq("green", false).eq("red", false).eq("white", false);
where.and(5);
colorClauses++;
}
if (colorClauses > 0) {
where.or(colorClauses);
clausesCount++;
}
if (minCardNumber != Integer.MIN_VALUE) {
where.ge("cardNumberAsInt", minCardNumber);
clausesCount++;
}
if (maxCardNumber != Integer.MAX_VALUE) {
where.le("cardNumberAsInt", maxCardNumber);
clausesCount++;
}
if (clausesCount > 0) {
where.and(clausesCount);
} else {
where.eq("cardNumber", new SelectArg(0));
}
if (start != null) {
qb.offset(start);
}
if (count != null) {
qb.limit(count);
}
if (sortBy != null) {
qb.orderBy(sortBy, true);
}
}
use of mage.constants.CardType in project mage by magefree.
the class TargetPermanentsThatShareCardType method canChoose.
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
Set<CardType> cardTypes = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType cardType : permanent.getCardType(game)) {
if (cardTypes.contains(cardType)) {
return true;
}
}
cardTypes.addAll(permanent.getCardType(game));
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class TargetPermanentsThatShareCardType method canChoose.
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
Set<CardType> cardTypes = new HashSet<>();
MageObject targetSource = game.getObject(sourceId);
if (targetSource != null) {
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
for (CardType cardType : permanent.getCardType(game)) {
if (cardTypes.contains(cardType)) {
return true;
}
}
cardTypes.addAll(permanent.getCardType(game));
}
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class VigeanIntuitionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (sourceObject == null || player == null) {
return false;
}
Library library = player.getLibrary();
if (library == null) {
return false;
}
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
String choosenType = choiceImpl.getChoice();
if (choosenType == null || choosenType.isEmpty()) {
return false;
}
CardType type = null;
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) {
Set<Card> top = library.getTopCards(game, 4);
player.revealCards(source, new CardsImpl(top), game);
Cards putInHand = new CardsImpl();
Cards putInGraveyard = new CardsImpl();
for (Card card : top) {
if (card != null && card.getCardType(game).contains(type)) {
putInHand.add(card);
} else {
putInGraveyard.add(card);
}
}
player.moveCards(putInHand, Zone.HAND, source, game);
player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
return true;
}
}
return false;
}
use of mage.constants.CardType in project mage by magefree.
the class VerifyCardDataTest method checkTypes.
private void checkTypes(Card card, MtgJsonCard ref) {
if (skipListHaveName(SKIP_LIST_TYPE, card.getExpansionSetCode(), card.getName())) {
return;
}
Collection<String> expected = ref.types;
List<String> type = new ArrayList<>();
for (CardType cardType : card.getCardType()) {
type.add(cardType.toString());
}
if (!eqSet(type, expected)) {
fail(card, "types", type + " != " + expected);
}
}
Aggregations