mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
removed rarity from Card, use CardPrinted instead
Predicate: stylechanges acquiring legacy booster longer throws
This commit is contained in:
@@ -2602,24 +2602,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return sickness && isCreature();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>rarity</code>.</p>
|
||||
*
|
||||
* @param s a {@link java.lang.String} object.
|
||||
*/
|
||||
public void setRarity(String s) {
|
||||
rarity = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Getter for the field <code>rarity</code>.</p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String getRarity() {
|
||||
return rarity;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Setter for the field <code>imageName</code>.</p>
|
||||
*
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Card;
|
||||
@@ -48,6 +50,10 @@ public final class CardDb {
|
||||
// this is the same list in flat storage
|
||||
private final List<CardPrinted> allCardsFlat = new ArrayList<CardPrinted>();
|
||||
|
||||
// Lambda to get rules for selects from list of printed cards
|
||||
public static final Lambda1<CardPrinted, Card> fnGetCardPrintedByForgeCard = new Lambda1<CardPrinted, Card>() {
|
||||
@Override public CardPrinted apply(final Card from) { return CardDb.instance().getCard(from.getName()); }
|
||||
};
|
||||
|
||||
private CardDb() {
|
||||
this(new MtgDataParser()); // I wish cardname.txt parser was be here.
|
||||
|
||||
@@ -130,6 +130,9 @@ public final class CardPrinted implements Comparable<CardPrinted> {
|
||||
}
|
||||
public static Predicate<CardPrinted> printedInSets(final List<String> value, final boolean shouldContain)
|
||||
{
|
||||
if (value == null || value.isEmpty()) {
|
||||
return Predicate.getTrue(CardPrinted.class);
|
||||
}
|
||||
return new PredicateSets(value, shouldContain);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ package forge.card.cardFactory;
|
||||
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
import forge.*;
|
||||
import forge.card.CardDb;
|
||||
import forge.card.CardPrinted;
|
||||
import forge.card.abilityFactory.AbilityFactory;
|
||||
import forge.card.cost.Cost;
|
||||
import forge.card.spellability.*;
|
||||
@@ -13,7 +15,11 @@ import forge.gui.input.Input;
|
||||
import forge.gui.input.Input_PayManaCost;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -1840,22 +1846,17 @@ public class CardFactory_Creatures {
|
||||
list.addAll(AllZoneUtil.getPlayerHand(AllZone.getHumanPlayer()));
|
||||
list.addAll(AllZoneUtil.getPlayerCardsInLibrary(AllZone.getHumanPlayer()));
|
||||
list = list.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
public boolean addCard(final Card c) {
|
||||
return !c.isLand() && !c.isUnCastable();
|
||||
}
|
||||
});
|
||||
|
||||
if (list.size() > 0) {
|
||||
CardList rare;
|
||||
rare = list;
|
||||
rare = rare.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
return c.getRarity().equals("Rare");
|
||||
}
|
||||
});
|
||||
Predicate<CardPrinted> isRare = CardPrinted.Predicates.Presets.isRareOrMythic;
|
||||
List<CardPrinted> rares = isRare.select(list, CardDb.fnGetCardPrintedByForgeCard, CardDb.fnGetCardPrintedByForgeCard);
|
||||
|
||||
if (rare.size() > 0) {
|
||||
s = rare.get(CardUtil.getRandomIndex(rare)).getName();
|
||||
if (!rares.isEmpty()) {
|
||||
s = Predicate.getTrue(CardPrinted.class).random(rares).getName();
|
||||
} else {
|
||||
Card c = list.get(CardUtil.getRandomIndex(list));
|
||||
//System.out.println(c + " - " + c.getRarity());
|
||||
|
||||
@@ -43,35 +43,35 @@ public abstract class Predicate<T> {
|
||||
// selects are fun
|
||||
public final List<T> select(final Iterable<T> source) {
|
||||
ArrayList<T> result = new ArrayList<T>();
|
||||
if (source != null) for (T c : source) { if (isTrue(c)) { result.add(c); } }
|
||||
if (source != null) { for (T c : source) { if (isTrue(c)) { result.add(c); } } }
|
||||
return result;
|
||||
}
|
||||
public final <U> List<U> select(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
ArrayList<U> result = new ArrayList<U>();
|
||||
if (source != null) for (U c : source) { if (isTrue(accessor.apply(c))) { result.add(c); } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(accessor.apply(c))) { result.add(c); } } }
|
||||
return result;
|
||||
}
|
||||
public final <U, V> List<V> select(final Iterable<U> source, final Lambda1<T, U> cardAccessor,
|
||||
final Lambda1<V, U> transformer)
|
||||
{
|
||||
ArrayList<V> result = new ArrayList<V>();
|
||||
if (source != null) for (U c : source) { if (isTrue(cardAccessor.apply(c))) { result.add(transformer.apply(c)); } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(cardAccessor.apply(c))) { result.add(transformer.apply(c)); } } }
|
||||
return result;
|
||||
}
|
||||
|
||||
// select top 1
|
||||
public final T first(final Iterable<T> source) {
|
||||
if (source != null) for (T c : source) { if (isTrue(c)) { return c; } }
|
||||
if (source != null) { for (T c : source) { if (isTrue(c)) { return c; } } }
|
||||
return null;
|
||||
}
|
||||
public final <U> U first(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
if (source != null) for (U c : source) { if (isTrue(accessor.apply(c))) { return c; } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(accessor.apply(c))) { return c; } } }
|
||||
return null;
|
||||
}
|
||||
public final <U, V> V first(final Iterable<U> source, final Lambda1<T, U> cardAccessor,
|
||||
final Lambda1<V, U> transformer)
|
||||
{
|
||||
if (source != null) for (U c : source) { if (isTrue(cardAccessor.apply(c))) { return transformer.apply(c); } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(cardAccessor.apply(c))) { return transformer.apply(c); } } }
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -79,43 +79,46 @@ public abstract class Predicate<T> {
|
||||
public final void split(final Iterable<T> source,
|
||||
final List<T> trueList, final List<T> falseList)
|
||||
{
|
||||
if (source != null) for (T c : source) { if (isTrue(c)) { trueList.add(c); } else { falseList.add(c); } }
|
||||
if (source == null) { return; }
|
||||
for (T c : source) { if (isTrue(c)) { trueList.add(c); } else { falseList.add(c); } }
|
||||
}
|
||||
public final <U> void split(final Iterable<U> source, final Lambda1<T, U> accessor,
|
||||
final List<U> trueList, final List<U> falseList)
|
||||
{
|
||||
if (source != null) for (U c : source) { if (isTrue(accessor.apply(c))) { trueList.add(c); } else { falseList.add(c); } }
|
||||
if (source == null) { return; }
|
||||
for (U c : source) { if (isTrue(accessor.apply(c))) { trueList.add(c); } else { falseList.add(c); } }
|
||||
}
|
||||
public final <U, V> void split(final Iterable<U> source, final Lambda1<T, U> cardAccessor,
|
||||
final Lambda1<V, U> transformer, final List<V> trueList, final List<V> falseList)
|
||||
{
|
||||
if (source != null) for (U c : source) {
|
||||
if (source == null) { return; }
|
||||
for (U c : source) {
|
||||
if (isTrue(cardAccessor.apply(c))) { trueList.add(transformer.apply(c)); }
|
||||
else { falseList.add(transformer.apply(c)); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Count
|
||||
public final int count(final Iterable<T> source) {
|
||||
int result = 0;
|
||||
if (source != null) for (T c : source) { if (isTrue(c)) { result++; } }
|
||||
if (source != null) { for (T c : source) { if (isTrue(c)) { result++; } } }
|
||||
return result;
|
||||
}
|
||||
public final <U> int count(final Iterable<U> source, final Lambda1<T, U> accessor) {
|
||||
int result = 0;
|
||||
if (source != null) for (U c : source) { if (isTrue(accessor.apply(c))) { result++; } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(accessor.apply(c))) { result++; } } }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Aggregates?
|
||||
public final <U> int aggregate(final Iterable<U> source, final Lambda1<T, U> accessor,
|
||||
final Lambda1<Integer, U> valueAccessor)
|
||||
{
|
||||
int result = 0;
|
||||
if (source != null) for (U c : source) { if (isTrue(accessor.apply(c))) { result += valueAccessor.apply(c); } }
|
||||
if (source != null) { for (U c : source) { if (isTrue(accessor.apply(c))) { result += valueAccessor.apply(c); } } }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Random - algorithm adapted from Braid's GeneratorFunctions
|
||||
public final T random(final Iterable<T> source) {
|
||||
int n = 0;
|
||||
|
||||
Reference in New Issue
Block a user