use of mage.constants.SubType in project mage by magefree.
the class EquippedHasSubtypeCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
if (permanent == null || permanent.getAttachedTo() == null) {
return false;
}
Permanent attachedTo = game.getBattlefield().getPermanent(permanent.getAttachedTo());
if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
}
if (attachedTo == null) {
return false;
}
for (SubType s : subTypes) {
if (attachedTo.hasSubtype(s, game)) {
return true;
}
}
return false;
}
use of mage.constants.SubType 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.SubType in project mage by magefree.
the class HauntingVoyageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
SubType chosenSubType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
if (controller != null && chosenSubType != null) {
Set<Card> cardsToBattlefield = new LinkedHashSet<>();
if (!ForetoldCondition.instance.apply(game, source)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, 2, new FilterBySubtypeCard(chosenSubType), true);
controller.chooseTarget(outcome, target, source, game);
for (UUID cardId : target.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
cardsToBattlefield.add(card);
}
}
} else {
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.hasSubtype(chosenSubType, game)) {
cardsToBattlefield.add(card);
}
}
}
if (!cardsToBattlefield.isEmpty()) {
controller.moveCards(cardsToBattlefield, Zone.BATTLEFIELD, source, game);
return true;
}
}
return false;
}
use of mage.constants.SubType in project mage by magefree.
the class TargetCardInLibrarySharingLandType method canTarget.
@Override
public boolean canTarget(UUID playerId, UUID id, Ability source, Cards cards, Game game) {
if (!super.canTarget(playerId, id, source, cards, game)) {
return false;
}
if (getTargets().isEmpty()) {
// first target
return true;
}
Card card1 = game.getCard(getTargets().get(0));
Card card2 = game.getCard(id);
return card1 != null && card2 != null && card1.getSubtype(game).stream().filter(SubType.getLandTypes()::contains).anyMatch(subType -> card2.hasSubtype(subType, game));
}
use of mage.constants.SubType in project mage by magefree.
the class VolrathsLaboratoryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ObjectColor color = (ObjectColor) game.getState().getValue(source.getSourceId() + "_color");
SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
Token token = new VolrathsLaboratoryToken(color, subType);
return token.putOntoBattlefield(1, game, source, source.getControllerId());
}
Aggregations