mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 20:28:00 +00:00
- Implemented a way to auto-suggest basic lands in the Add Basic Lands dialog in desktop and mobile Forge.
This commit is contained in:
@@ -9,6 +9,8 @@ import forge.card.CardDb;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardRulesPredicates;
|
||||
import forge.card.ColorSet;
|
||||
import forge.card.mana.ManaCost;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.deck.generation.*;
|
||||
import forge.game.GameFormat;
|
||||
import forge.game.GameType;
|
||||
@@ -530,4 +532,59 @@ public class DeckgenUtil {
|
||||
|
||||
return deck;
|
||||
}
|
||||
|
||||
public static Map<ManaCostShard, Integer> suggestBasicLandCount(Deck d) {
|
||||
int W=0, U=0, R=0, B=0, G=0, total=0;
|
||||
List<PaperCard> cards = d.getOrCreate(DeckSection.Main).toFlatList();
|
||||
|
||||
// attempt to determine if building for sealed, constructed or EDH
|
||||
int targetDeckSize = cards.size() < 30 ? 40
|
||||
: cards.size() > 60 ? 100 : 60;
|
||||
|
||||
int numLandsToAdd = targetDeckSize - cards.size();
|
||||
|
||||
for (PaperCard c : d.getMain().toFlatList()) {
|
||||
ManaCost m = c.getRules().getManaCost();
|
||||
W += m.getShardCount(ManaCostShard.WHITE);
|
||||
U += m.getShardCount(ManaCostShard.BLUE);
|
||||
R += m.getShardCount(ManaCostShard.RED);
|
||||
B += m.getShardCount(ManaCostShard.BLACK);
|
||||
G += m.getShardCount(ManaCostShard.GREEN);
|
||||
}
|
||||
total = W + U + R + B + G;
|
||||
|
||||
int whiteSources = Math.round(numLandsToAdd * ((float)W / (float)total));
|
||||
numLandsToAdd -= whiteSources;
|
||||
total -= W;
|
||||
int blueSources = Math.round(numLandsToAdd * ((float)U / (float)total));
|
||||
numLandsToAdd -= blueSources;
|
||||
total -= U;
|
||||
int blackSources = Math.round(numLandsToAdd * ((float)B / (float)total));
|
||||
numLandsToAdd -= blackSources;
|
||||
total -= B;
|
||||
int redSources = Math.round(numLandsToAdd * ((float)R / (float)total));
|
||||
numLandsToAdd -= redSources;
|
||||
total -= R;
|
||||
int greenSources = Math.round(numLandsToAdd * ((float)G / (float)total));
|
||||
numLandsToAdd -= greenSources;
|
||||
total -= G;
|
||||
|
||||
// in case of a rounding error, add the remaining lands to one of the relevant colors
|
||||
if (numLandsToAdd > 0) {
|
||||
if (whiteSources > 0) { whiteSources += numLandsToAdd; }
|
||||
else if (blueSources > 0) { blueSources += numLandsToAdd; }
|
||||
else if (blackSources > 0) { blackSources += numLandsToAdd; }
|
||||
else if (redSources > 0) { redSources += numLandsToAdd; }
|
||||
else if (greenSources > 0) { greenSources += numLandsToAdd; }
|
||||
}
|
||||
|
||||
HashMap<ManaCostShard, Integer> suggestionMap = new HashMap<>();
|
||||
suggestionMap.put(ManaCostShard.WHITE, whiteSources);
|
||||
suggestionMap.put(ManaCostShard.BLUE, blueSources);
|
||||
suggestionMap.put(ManaCostShard.RED, redSources);
|
||||
suggestionMap.put(ManaCostShard.BLACK, blackSources);
|
||||
suggestionMap.put(ManaCostShard.GREEN, greenSources);
|
||||
|
||||
return suggestionMap;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user