use of mage.constants.SuperType in project mage by magefree.
the class CardTextPredicate method apply.
@Override
public boolean apply(Card input, Game game) {
if (text.isEmpty() && !isUnique) {
return true;
}
if (text.isEmpty() && isUnique) {
boolean found = !seenCards.containsKey(input.getName());
seenCards.put(input.getName(), true);
return found;
}
// first check in card name
if (inNames) {
String fullName = input.getName();
if (input instanceof MockCard) {
fullName = ((MockCard) input).getFullName(true);
} else if (input instanceof ModalDoubleFacesCard) {
fullName = input.getName() + MockCard.MODAL_DOUBLE_FACES_NAME_SEPARATOR + ((ModalDoubleFacesCard) input).getRightHalfCard().getName();
} else if (input instanceof AdventureCard) {
fullName = input.getName() + MockCard.ADVENTURE_NAME_SEPARATOR + ((AdventureCard) input).getSpellCard().getName();
}
if (fullName.toLowerCase(Locale.ENGLISH).contains(text.toLowerCase(Locale.ENGLISH))) {
if (isUnique && seenCards.containsKey(input.getName())) {
return false;
}
if (isUnique) {
seenCards.put(input.getName(), true);
}
return true;
}
}
// separate by spaces
String[] tokens = text.toLowerCase(Locale.ENGLISH).split(" ");
for (String token : tokens) {
boolean found = false;
if (!token.isEmpty()) {
// then try to find in rules
if (inRules) {
if (input instanceof SplitCard) {
for (String rule : ((SplitCard) input).getLeftHalfCard().getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
for (String rule : ((SplitCard) input).getRightHalfCard().getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
}
if (input instanceof ModalDoubleFacesCard) {
for (String rule : ((ModalDoubleFacesCard) input).getLeftHalfCard().getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
for (String rule : ((ModalDoubleFacesCard) input).getRightHalfCard().getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
}
if (input instanceof AdventureCard) {
for (String rule : ((AdventureCard) input).getSpellCard().getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
}
for (String rule : input.getRules(game)) {
if (rule.toLowerCase(Locale.ENGLISH).contains(token)) {
found = true;
break;
}
}
}
if (inTypes) {
for (SubType subType : input.getSubtype(game)) {
if (subType.toString().equalsIgnoreCase(token)) {
found = true;
break;
}
}
for (SuperType superType : input.getSuperType()) {
if (superType.toString().equalsIgnoreCase(token)) {
found = true;
break;
}
}
}
}
if (found && isUnique && seenCards.containsKey(input.getName())) {
found = false;
}
if (!found) {
return false;
}
}
if (isUnique) {
seenCards.put(input.getName(), true);
}
return true;
}
use of mage.constants.SuperType 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.SuperType 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.SuperType in project mage by magefree.
the class SelectionBox method reselectBy.
public void reselectBy() {
// Deselect everything
deselectAll();
boolean useText = false;
String searchStr = "";
if (searchByTextField.getText().length() >= 3) {
useText = true;
searchStr = searchByTextField.getText().toLowerCase(Locale.ENGLISH);
}
for (CardType cardType : selectByTypeButtons.keySet()) {
AbstractButton button = selectByTypeButtons.get(cardType);
if (button != null) {
if (button.isSelected()) {
// Special case - "Multiples" (CONSPIRACY type)
if (cardType == CardType.CONSPIRACY) {
Map<String, CardView> cardNames = new HashMap<>();
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
if (cardNames.get(card.getName()) == null) {
cardNames.put(card.getName(), card);
} else {
card.setSelected(true);
cardViews.get(card.getId()).update(card);
CardView origCard = cardNames.get(card.getName());
origCard.setSelected(true);
cardViews.get(origCard.getId()).update(origCard);
}
}
}
}
continue;
}
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
boolean s = card.isSelected() || card.getCardTypes().contains(cardType);
card.setSelected(s);
cardViews.get(card.getId()).update(card);
}
}
}
}
}
}
if (useText) {
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
boolean s = card.isSelected();
// Name
if (!s) {
s = card.getName().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Sub & Super Types
if (!s) {
for (SuperType str : card.getSuperTypes()) {
s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
for (SubType str : card.getSubTypes()) {
s |= str.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
// Rarity
if (!s) {
Rarity r = card.getRarity();
if (r != null) {
s |= r.toString().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
// Type line
if (!s) {
String t = "";
for (CardType type : card.getCardTypes()) {
t += ' ' + type.toString();
}
s |= t.toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Casting cost
if (!s) {
s |= card.getManaCostStr().toLowerCase(Locale.ENGLISH).contains(searchStr);
}
// Rules
if (!s) {
for (String str : card.getRules()) {
s |= str.toLowerCase(Locale.ENGLISH).contains(searchStr);
}
}
card.setSelected(s);
cardViews.get(card.getId()).update(card);
}
}
}
}
// And finally rerender
layoutGrid();
repaintGrid();
}
Aggregations