mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Add ability type, and capability for cards to be marked has having specific abilities through DeckHas var.
This commit is contained in:
@@ -12,13 +12,15 @@ public class CardAiHints {
|
||||
|
||||
private final DeckHints deckHints;
|
||||
private final DeckHints deckNeeds;
|
||||
private final DeckHints deckHas;
|
||||
|
||||
|
||||
public CardAiHints(boolean remAi, boolean remRandom, DeckHints dh, DeckHints dn) {
|
||||
public CardAiHints(boolean remAi, boolean remRandom, DeckHints dh, DeckHints dn, DeckHints has) {
|
||||
isRemovedFromAIDecks = remAi;
|
||||
isRemovedFromRandomDecks = remRandom;
|
||||
deckHints = dh;
|
||||
deckNeeds = dn;
|
||||
deckHas = has;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,6 +55,13 @@ public class CardAiHints {
|
||||
return deckNeeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the deckHints
|
||||
*/
|
||||
public DeckHints getDeckHas() {
|
||||
return deckHas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ai status comparable.
|
||||
*
|
||||
|
||||
@@ -249,6 +249,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
private boolean removedFromRandomDecks = false;
|
||||
private DeckHints hints = null;
|
||||
private DeckHints needs = null;
|
||||
private DeckHints has = null;
|
||||
|
||||
/**
|
||||
* Reset all fields to parse next card (to avoid allocating new CardRulesReader N times)
|
||||
@@ -267,6 +268,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
this.removedFromRandomDecks = false;
|
||||
this.needs = null;
|
||||
this.hints = null;
|
||||
this.has = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,7 +277,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
* @return the card
|
||||
*/
|
||||
public final CardRules getCard() {
|
||||
CardAiHints cah = new CardAiHints(removedFromAIDecks, removedFromRandomDecks, hints, needs );
|
||||
CardAiHints cah = new CardAiHints(removedFromAIDecks, removedFromRandomDecks, hints, needs, has);
|
||||
faces[0].assignMissingFields();
|
||||
if (null != faces[1]) faces[1].assignMissingFields();
|
||||
final CardRules result = new CardRules(faces, altMode, cah);
|
||||
@@ -333,6 +335,8 @@ public final class CardRules implements ICardCharacteristics {
|
||||
hints = new DeckHints(value);
|
||||
} else if ("DeckNeeds".equals(key)) {
|
||||
needs = new DeckHints(value);
|
||||
} else if ("DeckHas".equals(key)) {
|
||||
has = new DeckHints(value);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -483,7 +487,7 @@ public final class CardRules implements ICardCharacteristics {
|
||||
}
|
||||
|
||||
public static CardRules getUnsupportedCardNamed(String name) {
|
||||
CardAiHints cah = new CardAiHints(true, true, null, null);
|
||||
CardAiHints cah = new CardAiHints(true, true, null, null, null);
|
||||
CardFace[] faces = { new CardFace(name), null};
|
||||
faces[0].setColor(ColorSet.fromMask(0));
|
||||
faces[0].setType(CardType.parse(""));
|
||||
|
||||
@@ -183,6 +183,25 @@ public final class CardRulesPredicates {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Has matching DeckHas hint.
|
||||
*
|
||||
* @param type
|
||||
* the DeckHints.Type
|
||||
* @param has
|
||||
* the hint
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> deckHas(final DeckHints.Type type, final String has) {
|
||||
return new Predicate<CardRules>() {
|
||||
@Override
|
||||
public boolean apply(final CardRules card) {
|
||||
DeckHints deckHas = card.getAiHints().getDeckHas();
|
||||
return deckHas != null && deckHas.isValid() && deckHas.contains(type, has);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Core type.
|
||||
*
|
||||
|
||||
@@ -4,13 +4,14 @@ import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import forge.item.PaperCard;
|
||||
import forge.util.PredicateString;
|
||||
import forge.util.PredicateString.StringOp;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* DeckHints provides the ability for a Card to "want" another Card or type of
|
||||
@@ -23,7 +24,8 @@ public class DeckHints {
|
||||
* Enum of types of DeckHints.
|
||||
*/
|
||||
public enum Type {
|
||||
|
||||
/** The Ability */
|
||||
ABILITY,
|
||||
/** The Color. */
|
||||
COLOR,
|
||||
/** The Keyword. */
|
||||
@@ -64,6 +66,17 @@ public class DeckHints {
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
public boolean contains(Type type, String hint) {
|
||||
if (filters == null) {
|
||||
return false;
|
||||
}
|
||||
for (Pair<Type, String> filter : filters) {
|
||||
if (filter.getLeft() == type && filter.getRight().equals(hint)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Map of Cards by Type from the given Iterable<PaperCard> that match this
|
||||
@@ -129,10 +142,10 @@ public class DeckHints {
|
||||
private Iterable<PaperCard> getCardsForFilter(Iterable<PaperCard> cardList, Type type, String param) {
|
||||
List<PaperCard> cards = new ArrayList<>();
|
||||
switch (type) {
|
||||
case TYPE:
|
||||
String[] types = param.split("\\|");
|
||||
for (String t : types) {
|
||||
Iterables.addAll(cards, getMatchingItems(cardList, CardRulesPredicates.subType(t), PaperCard.FN_GET_RULES));
|
||||
case ABILITY:
|
||||
String[] abilities = param.split("\\|");
|
||||
for (String ability : abilities) {
|
||||
Iterables.addAll(cards, getMatchingItems(cardList, CardRulesPredicates.deckHas(Type.ABILITY, ability), PaperCard.FN_GET_RULES));
|
||||
}
|
||||
break;
|
||||
case COLOR:
|
||||
@@ -158,6 +171,12 @@ public class DeckHints {
|
||||
Iterables.addAll(cards, getMatchingItems(cardList, CardRulesPredicates.name(StringOp.EQUALS, name), PaperCard.FN_GET_RULES));
|
||||
}
|
||||
break;
|
||||
case TYPE:
|
||||
String[] types = param.split("\\|");
|
||||
for (String t : types) {
|
||||
Iterables.addAll(cards, getMatchingItems(cardList, CardRulesPredicates.subType(t), PaperCard.FN_GET_RULES));
|
||||
}
|
||||
break;
|
||||
}
|
||||
return cards;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user