Adventure mode - Support to restrict cards from random pool

For now we just restrict the Power Nine. They can still be dropped explicitly.
This commit is contained in:
Magpie
2022-05-05 05:08:31 +02:00
parent 47168e1de7
commit 8251c08af0
3 changed files with 40 additions and 32 deletions

View File

@@ -1,6 +1,8 @@
package forge.adventure.data; package forge.adventure.data;
import java.util.List;
/** /**
* Data class that will be used to read Json configuration files * Data class that will be used to read Json configuration files
* BiomeData * BiomeData
@@ -17,4 +19,5 @@ public class ConfigData {
public String[] starterDecks; public String[] starterDecks;
public DifficultyData[] difficulties; public DifficultyData[] difficulties;
public RewardData legalCards; public RewardData legalCards;
public List<String> restrictedCards;
} }

View File

@@ -41,11 +41,8 @@ public class RewardData {
public String cardText; public String cardText;
public boolean matchAllSubTypes; public boolean matchAllSubTypes;
public RewardData() { }
public RewardData()
{
}
public RewardData(RewardData rewardData) { public RewardData(RewardData rewardData) {
type =rewardData.type; type =rewardData.type;
probability =rewardData.probability; probability =rewardData.probability;
@@ -68,23 +65,24 @@ public class RewardData {
private static Iterable<PaperCard> allCards; private static Iterable<PaperCard> allCards;
private static Iterable<PaperCard> allEnemyCards; private static Iterable<PaperCard> allEnemyCards;
public Array<Reward> generate(boolean isForEnemy)
{ public Array<Reward> generate(boolean isForEnemy) {
return generate(isForEnemy, null); return generate(isForEnemy, null);
} }
public Array<Reward> generate(boolean isForEnemy,Iterable<PaperCard> cards) public Array<Reward> generate(boolean isForEnemy, Iterable<PaperCard> cards) {
{ if(allCards==null) {
if(allCards==null)
{
RewardData legals = Config.instance().getConfigData().legalCards; RewardData legals = Config.instance().getConfigData().legalCards;
if(legals==null) if(legals==null) allCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAltNoOnline();
{ else allCards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCardsNoAltNoOnline(), new CardUtil.CardPredicate(legals, true));
allCards = FModel.getMagicDb().getCommonCards().getUniqueCardsNoAltNoOnline(); //Filter out specific cards.
} allCards = Iterables.filter(allCards, new Predicate<PaperCard>() {
else @Override
{ public boolean apply(PaperCard input){
allCards = Iterables.filter(FModel.getMagicDb().getCommonCards().getUniqueCardsNoAltNoOnline(), new CardUtil.CardPredicate(legals, true)); if(input == null) return false;
return !Config.instance().getConfigData().restrictedCards.contains(input.getName());
} }
});
//Filter AI cards for enemies.
allEnemyCards=Iterables.filter(allCards, new Predicate<PaperCard>() { allEnemyCards=Iterables.filter(allCards, new Predicate<PaperCard>() {
@Override @Override
public boolean apply(PaperCard input) { public boolean apply(PaperCard input) {
@@ -97,8 +95,7 @@ public class RewardData {
if(probability == 0 || WorldSave.getCurrentSave().getWorld().getRandom().nextFloat() <= probability) { if(probability == 0 || WorldSave.getCurrentSave().getWorld().getRandom().nextFloat() <= probability) {
if(type==null || type.isEmpty()) if(type==null || type.isEmpty())
type="randomCard"; type="randomCard";
int addedCount=(int)((float)(addMaxCount)* WorldSave.getCurrentSave().getWorld().getRandom().nextFloat()); int addedCount = WorldSave.getCurrentSave().getWorld().getRandom().nextInt(addMaxCount);
if( colors != null && colors.length > 0 ) { //Filter special "colorID" case. if( colors != null && colors.length > 0 ) { //Filter special "colorID" case.
String C = Current.player().getColorIdentityLong(); String C = Current.player().getColorIdentityLong();
for(int i = 0; i < colors.length; i++){ for(int i = 0; i < colors.length; i++){
@@ -128,18 +125,15 @@ public class RewardData {
} }
break; break;
case "item": case "item":
if(itemName!=null&&!itemName.isEmpty()) if(itemName!=null&&!itemName.isEmpty()) {
{ for(int i=0;i<count+addedCount;i++) {
for(int i=0;i<count+addedCount;i++)
{
ret.add(new Reward(ItemData.getItem(itemName))); ret.add(new Reward(ItemData.getItem(itemName)));
} }
} }
break; break;
case "deckCard": case "deckCard":
if(cards == null) return ret; if(cards == null) return ret;
for(PaperCard card: CardUtil.generateCards(cards,this, count+addedCount)) for(PaperCard card: CardUtil.generateCards(cards,this, count+addedCount)) {
{
ret.add(new Reward(card)); ret.add(new Reward(card));
} }
break; break;

View File

@@ -11,6 +11,17 @@
"decks/starter/red.json", "decks/starter/red.json",
"decks/starter/green.json" "decks/starter/green.json"
], ],
"restrictedCards": [
"Black Lotus",
"Mox Emerald",
"Mox Pearl",
"Mox Ruby",
"Mox Sapphire",
"Mox Jet",
"Ancestral Recall",
"Timetwister",
"Time Walk"
],
"difficulties": [ "difficulties": [
{ {
"name": "Easy", "name": "Easy",