mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 08:48:39 +00:00
Check for Snow lands and Wastes when generating random decks
This commit is contained in:
@@ -63,7 +63,6 @@ public enum ManaCostShard {
|
|||||||
S(ManaAtom.IS_SNOW, "S"),
|
S(ManaAtom.IS_SNOW, "S"),
|
||||||
GENERIC(ManaAtom.GENERIC, "1"),
|
GENERIC(ManaAtom.GENERIC, "1"),
|
||||||
|
|
||||||
|
|
||||||
/* Phyrexian */
|
/* Phyrexian */
|
||||||
WP(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "W/P", "WP"),
|
WP(ManaAtom.WHITE | ManaAtom.OR_2_LIFE, "W/P", "WP"),
|
||||||
UP(ManaAtom.BLUE | ManaAtom.OR_2_LIFE, "U/P", "UP"),
|
UP(ManaAtom.BLUE | ManaAtom.OR_2_LIFE, "U/P", "UP"),
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import forge.adventure.data.GeneratedDeckData;
|
|||||||
import forge.adventure.data.GeneratedDeckTemplateData;
|
import forge.adventure.data.GeneratedDeckTemplateData;
|
||||||
import forge.adventure.data.RewardData;
|
import forge.adventure.data.RewardData;
|
||||||
import forge.card.*;
|
import forge.card.*;
|
||||||
|
import forge.card.mana.ManaCost;
|
||||||
import forge.card.mana.ManaCostShard;
|
import forge.card.mana.ManaCostShard;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
@@ -499,52 +500,68 @@ public class CardUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<PaperCard> fillWithLands(List<PaperCard> nonLands, GeneratedDeckTemplateData template) {
|
private static List<PaperCard> fillWithLands(List<PaperCard> nonLands, GeneratedDeckTemplateData template) {
|
||||||
int red=0;
|
int red = 0, blue = 0, green = 0, white = 0, black = 0, colorless = 0;
|
||||||
int blue=0;
|
|
||||||
int green=0;
|
|
||||||
int white=0;
|
|
||||||
int black=0;
|
|
||||||
int colorLess=0;
|
|
||||||
int cardCount = nonLands.size();
|
int cardCount = nonLands.size();
|
||||||
List<PaperCard> cards = new ArrayList<>();
|
List<PaperCard> cards = new ArrayList<>();
|
||||||
boolean allCardVariants = Config.instance().getSettingData().useAllCardVariants;
|
boolean allCardVariants = Config.instance().getSettingData().useAllCardVariants;
|
||||||
|
boolean useSnowLands = false;
|
||||||
|
|
||||||
for(PaperCard nonLand:nonLands)
|
for (PaperCard nonLand : nonLands) {
|
||||||
{
|
CardRules rules = nonLand.getRules();
|
||||||
red+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.RED);
|
ManaCost manaCost = rules.getManaCost();
|
||||||
green+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.GREEN);
|
|
||||||
white+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.WHITE);
|
red += manaCost.getShardCount(ManaCostShard.RED);
|
||||||
blue+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.BLUE);
|
green += manaCost.getShardCount(ManaCostShard.GREEN);
|
||||||
black+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.BLACK);
|
white += manaCost.getShardCount(ManaCostShard.WHITE);
|
||||||
colorLess+=nonLand.getRules().getManaCost().getShardCount(ManaCostShard.GENERIC);
|
blue += manaCost.getShardCount(ManaCostShard.BLUE);
|
||||||
|
black += manaCost.getShardCount(ManaCostShard.BLACK);
|
||||||
|
colorless += manaCost.getShardCount(ManaCostShard.COLORLESS);
|
||||||
|
|
||||||
|
// Check for Snow lands requirement
|
||||||
|
if (!useSnowLands) {
|
||||||
|
if (manaCost.getShardCount(ManaCostShard.S) > 0) {
|
||||||
|
useSnowLands = true;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
float sum= red+ blue+ green+ white+ black;
|
|
||||||
|
if (rules.getAiHints() != null && rules.getAiHints().getDeckHints() != null) {
|
||||||
|
useSnowLands = rules.getAiHints().getDeckHints().contains(Type.TYPE, "Snow");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float sumColoredCost = red + blue + green + white + black;
|
||||||
int neededLands = template.count - cardCount;
|
int neededLands = template.count - cardCount;
|
||||||
int neededDualLands = Math.round(neededLands * template.rares);
|
int neededDualLands = Math.round(neededLands * template.rares);
|
||||||
int neededBase = neededLands - neededDualLands;
|
int neededBase = neededLands - neededDualLands;
|
||||||
String edition = "";
|
String edition = "";
|
||||||
|
|
||||||
if (allCardVariants) {
|
if (allCardVariants) {
|
||||||
PaperCard templateLand = CardUtil.getCardByName("Plains");
|
PaperCard templateLand = CardUtil.getCardByName("Plains");
|
||||||
edition = templateLand.getEdition();
|
edition = templateLand.getEdition();
|
||||||
}
|
}
|
||||||
if(sum==0.)
|
|
||||||
{
|
if (sumColoredCost == 0) {
|
||||||
cards.addAll(generateLands("Wastes", neededLands));
|
cards.addAll(generateLands("Wastes", neededLands));
|
||||||
}
|
} else {
|
||||||
else
|
float sumTotalCost = sumColoredCost + colorless;
|
||||||
{
|
|
||||||
int mount=Math.round(neededBase*(red/sum));
|
int mountain = Math.round(neededBase * (red / sumTotalCost));
|
||||||
int island=Math.round(neededBase*(blue/sum));
|
int island = Math.round(neededBase * (blue / sumTotalCost));
|
||||||
int forest=Math.round(neededBase*(green/sum));
|
int forest = Math.round(neededBase * (green / sumTotalCost));
|
||||||
int plains=Math.round(neededBase*(white/sum));
|
int plains = Math.round(neededBase * (white / sumTotalCost));
|
||||||
int swamp=Math.round(neededBase*(black/sum));
|
int swamp = Math.round(neededBase * (black / sumTotalCost));
|
||||||
cards.addAll(generateLands("Plains",plains,edition));
|
int wastes = Math.round(neededBase * (colorless / sumTotalCost));
|
||||||
cards.addAll(generateLands("Island",island,edition));
|
|
||||||
cards.addAll(generateLands("Forest",forest,edition));
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Plains" : "Plains", plains, edition));
|
||||||
cards.addAll(generateLands("Mountain",mount,edition));
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Island" : "Island", island, edition));
|
||||||
cards.addAll(generateLands("Swamp",swamp,edition));
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Forest" : "Forest", forest, edition));
|
||||||
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Mountain" : "Mountain", mountain, edition));
|
||||||
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Swamp" : "Swamp", swamp, edition));
|
||||||
|
cards.addAll(generateLands(useSnowLands ? "Snow-Covered Wastes" : "Wastes", wastes, edition));
|
||||||
|
|
||||||
List<String> landTypes = new ArrayList<>();
|
List<String> landTypes = new ArrayList<>();
|
||||||
if(mount>0)
|
if (mountain > 0)
|
||||||
landTypes.add("Mountain");
|
landTypes.add("Mountain");
|
||||||
if (island > 0)
|
if (island > 0)
|
||||||
landTypes.add("Island");
|
landTypes.add("Island");
|
||||||
@@ -554,12 +571,12 @@ public class CardUtil {
|
|||||||
landTypes.add("Swamp");
|
landTypes.add("Swamp");
|
||||||
if (forest > 0)
|
if (forest > 0)
|
||||||
landTypes.add("Forest");
|
landTypes.add("Forest");
|
||||||
cards.addAll(generateDualLands(landTypes,neededDualLands));
|
|
||||||
|
|
||||||
|
cards.addAll(generateDualLands(landTypes, neededDualLands));
|
||||||
}
|
}
|
||||||
|
|
||||||
return cards;
|
return cards;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<PaperCard> generateDualLands(List<String> landName, int count) {
|
private static Collection<PaperCard> generateDualLands(List<String> landName, int count) {
|
||||||
ArrayList<RewardData> rewards=new ArrayList<>();
|
ArrayList<RewardData> rewards=new ArrayList<>();
|
||||||
RewardData base= new RewardData();
|
RewardData base= new RewardData();
|
||||||
@@ -737,6 +754,7 @@ public class CardUtil {
|
|||||||
if (deck != null)
|
if (deck != null)
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json json = new Json();
|
Json json = new Json();
|
||||||
FileHandle handle = Config.instance().getFile(path);
|
FileHandle handle = Config.instance().getFile(path);
|
||||||
if (handle.exists())
|
if (handle.exists())
|
||||||
@@ -744,7 +762,6 @@ public class CardUtil {
|
|||||||
Deck deck = DeckgenUtil.getRandomOrPreconOrThemeDeck(colors, true, false, true);
|
Deck deck = DeckgenUtil.getRandomOrPreconOrThemeDeck(colors, true, false, true);
|
||||||
System.err.println("Error loading JSON: " + handle.path() + "\nGenerating random deck: " + deck.getName());
|
System.err.println("Error loading JSON: " + handle.path() + "\nGenerating random deck: " + deck.getName());
|
||||||
return deck;
|
return deck;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final GameFormat.Collection formats = FModel.getFormats();
|
private static final GameFormat.Collection formats = FModel.getFormats();
|
||||||
|
|||||||
Reference in New Issue
Block a user