mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
checkstyle and refactor
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
package forge.game;
|
||||
|
||||
/**
|
||||
* The Enum GameEndReason.
|
||||
*/
|
||||
public enum GameEndReason {
|
||||
/** The All opponents lost. */
|
||||
AllOpponentsLost,
|
||||
// Noone won
|
||||
Draw, // Having little idea how they can reach a draw, so I didn't enumerate possible reasons here
|
||||
/** The Draw. */
|
||||
Draw, // Having little idea how they can reach a draw, so I didn't enumerate
|
||||
// possible reasons here
|
||||
// Special conditions, they force one player to win and thus end the game
|
||||
|
||||
WinsGameSpellEffect // ones that could be both hardcoded (felidar) and scripted ( such as Mayael's Aria )
|
||||
/** The Wins game spell effect. */
|
||||
WinsGameSpellEffect // ones that could be both hardcoded (felidar) and
|
||||
// scripted ( such as Mayael's Aria )
|
||||
}
|
||||
|
||||
@@ -4,62 +4,95 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.slightlymagic.maxmtg.Predicate;
|
||||
|
||||
import forge.card.CardRules;
|
||||
import forge.item.CardPrinted;
|
||||
|
||||
/**
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class GameFormat {
|
||||
|
||||
|
||||
private final String name;
|
||||
// contains allowed sets, when empty allows all sets
|
||||
private final List<String> allowedSetCodes;
|
||||
private final List<String> bannedCardNames;
|
||||
|
||||
private final List<String> allowedSetCodes;
|
||||
private final List<String> bannedCardNames;
|
||||
|
||||
private final Predicate<CardPrinted> filterRules;
|
||||
private final Predicate<CardPrinted> filterPrinted;
|
||||
|
||||
|
||||
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards)
|
||||
{
|
||||
name = fName;
|
||||
allowedSetCodes = Collections.unmodifiableList(sets);
|
||||
bannedCardNames = Collections.unmodifiableList(bannedCards);
|
||||
filterRules = buildFilterRules();
|
||||
filterPrinted = buildFilterPritned();
|
||||
|
||||
/**
|
||||
* Instantiates a new game format.
|
||||
*
|
||||
* @param fName the f name
|
||||
* @param sets the sets
|
||||
* @param bannedCards the banned cards
|
||||
*/
|
||||
public GameFormat(final String fName, final List<String> sets, final List<String> bannedCards) {
|
||||
this.name = fName;
|
||||
this.allowedSetCodes = Collections.unmodifiableList(sets);
|
||||
this.bannedCardNames = Collections.unmodifiableList(bannedCards);
|
||||
this.filterRules = this.buildFilterRules();
|
||||
this.filterPrinted = this.buildFilterPritned();
|
||||
}
|
||||
|
||||
|
||||
private Predicate<CardPrinted> buildFilterPritned() {
|
||||
Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(bannedCardNames);
|
||||
Predicate<CardPrinted> allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty()
|
||||
? CardPrinted.Predicates.Presets.isTrue
|
||||
: CardPrinted.Predicates.printedInSets(allowedSetCodes, true);
|
||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||
: CardPrinted.Predicates.printedInSets(this.allowedSetCodes, true);
|
||||
return Predicate.and(banNames, allowSets);
|
||||
}
|
||||
|
||||
|
||||
private Predicate<CardPrinted> buildFilterRules() {
|
||||
Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(bannedCardNames);
|
||||
Predicate<CardPrinted> allowSets = allowedSetCodes == null || allowedSetCodes.isEmpty()
|
||||
? CardPrinted.Predicates.Presets.isTrue
|
||||
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(allowedSetCodes), CardPrinted.fnGetRules);
|
||||
final Predicate<CardPrinted> banNames = CardPrinted.Predicates.namesExcept(this.bannedCardNames);
|
||||
final Predicate<CardPrinted> allowSets = (this.allowedSetCodes == null) || this.allowedSetCodes.isEmpty() ? CardPrinted.Predicates.Presets.isTrue
|
||||
: Predicate.brigde(CardRules.Predicates.wasPrintedInSets(this.allowedSetCodes), CardPrinted.fnGetRules);
|
||||
return Predicate.and(banNames, allowSets);
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public Predicate<CardPrinted> getFilterRules() { return filterRules; }
|
||||
public Predicate<CardPrinted> getFilterPrinted() { return filterPrinted; }
|
||||
|
||||
public boolean isSetLegal(String setCode) { return allowedSetCodes.isEmpty() || allowedSetCodes.contains(setCode); }
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name + " (format)";
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the filter rules.
|
||||
*
|
||||
* @return the filter rules
|
||||
*/
|
||||
public Predicate<CardPrinted> getFilterRules() {
|
||||
return this.filterRules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter printed.
|
||||
*
|
||||
* @return the filter printed
|
||||
*/
|
||||
public Predicate<CardPrinted> getFilterPrinted() {
|
||||
return this.filterPrinted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is sets the legal.
|
||||
*
|
||||
* @param setCode the set code
|
||||
* @return true, if is sets the legal
|
||||
*/
|
||||
public boolean isSetLegal(final String setCode) {
|
||||
return this.allowedSetCodes.isEmpty() || this.allowedSetCodes.contains(setCode);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + " (format)";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +1,52 @@
|
||||
package forge.game;
|
||||
|
||||
/**
|
||||
* The Enum GameLossReason.
|
||||
*/
|
||||
public enum GameLossReason {
|
||||
|
||||
DidNotLoseYet, // a winner must have this status by the end of the game
|
||||
|
||||
Conceded, // rule 104.3a
|
||||
LifeReachedZero, // rule 104.3b
|
||||
Milled, // 104.3c
|
||||
Poisoned, // 104.3d
|
||||
/** The Did not lose yet. */
|
||||
DidNotLoseYet, // a winner must have this status by the end of the game
|
||||
|
||||
/** The Conceded. */
|
||||
Conceded, // rule 104.3a
|
||||
/** The Life reached zero. */
|
||||
LifeReachedZero, // rule 104.3b
|
||||
/** The Milled. */
|
||||
Milled, // 104.3c
|
||||
/** The Poisoned. */
|
||||
Poisoned, // 104.3d
|
||||
|
||||
// 104.3e and others
|
||||
SpellEffect
|
||||
|
||||
/*DoorToNothingness, // Door To Nothingness's ability activated
|
||||
|
||||
// TODO: Implement game logics for the ones below
|
||||
Transcendence20Life, // When you have 20 or more life, you lose the game.
|
||||
FailedToPayPactUpkeep, // Pacts from Future Sight series (cost 0 but you must pay their real cost at next turn's upkeep, otherwise GL)
|
||||
PhageTheUntouchableDamage, // Whenever Phage deals combat damage to a player, that player loses the game.
|
||||
PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if you didn't cast it from your hand, you lose the game.
|
||||
NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you lose the game.
|
||||
NefariousLichCannotExileGrave, // If damage would be dealt to you, exile that many cards from your graveyard instead. If you can't, you lose the game.
|
||||
LichWasPutToGraveyard, // When Lich is put into a graveyard from the battlefield, you lose the game.
|
||||
FinalFortune, // same as Warrior's Oath - lose at the granted extra turn's end step
|
||||
ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard, you lose the game.
|
||||
ForbiddenCryptEmptyGraveyard, // If you would draw a card, return a card from your graveyard to your hand instead. If you can't, you lose the game.
|
||||
/** The Spell effect. */
|
||||
SpellEffect
|
||||
|
||||
// Amulet of quoz skipped for using ante,
|
||||
// Form of the Squirrel and Rocket-Powered Turbo Slug skipped for being part of UN- set
|
||||
/*
|
||||
* DoorToNothingness, // Door To Nothingness's ability activated
|
||||
*
|
||||
* // TODO: Implement game logics for the ones below Transcendence20Life, //
|
||||
* When you have 20 or more life, you lose the game. FailedToPayPactUpkeep,
|
||||
* // Pacts from Future Sight series (cost 0 but you must pay their real
|
||||
* cost at next turn's upkeep, otherwise GL) PhageTheUntouchableDamage, //
|
||||
* Whenever Phage deals combat damage to a player, that player loses the
|
||||
* game. PhageTheUntouchableWrongETB, // When Phage the Untouchable ETB, if
|
||||
* you didn't cast it from your hand, you lose the game.
|
||||
* NefariousLichLeavesTB, // When Nefarious Lich leaves the battlefield, you
|
||||
* lose the game. NefariousLichCannotExileGrave, // If damage would be dealt
|
||||
* to you, exile that many cards from your graveyard instead. If you can't,
|
||||
* you lose the game. LichWasPutToGraveyard, // When Lich is put into a
|
||||
* graveyard from the battlefield, you lose the game. FinalFortune, // same
|
||||
* as Warrior's Oath - lose at the granted extra turn's end step
|
||||
* ImmortalCoilEmptyGraveyard, // When there are no cards in your graveyard,
|
||||
* you lose the game. ForbiddenCryptEmptyGraveyard, // If you would draw a
|
||||
* card, return a card from your graveyard to your hand instead. If you
|
||||
* can't, you lose the game.
|
||||
*
|
||||
* // Amulet of quoz skipped for using ante, // Form of the Squirrel and
|
||||
* Rocket-Powered Turbo Slug skipped for being part of UN- set
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
// refer to http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22] for more cards when they are printed
|
||||
// refer to
|
||||
// http://gatherer.wizards.com/Pages/Search/Default.aspx?output=standard&text=+[%22lose+the+game%22]
|
||||
// for more cards when they are printed
|
||||
}
|
||||
|
||||
|
||||
@@ -1,47 +1,91 @@
|
||||
package forge.game;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Max
|
||||
* The Class GamePlayerRating.
|
||||
*
|
||||
* @author Max
|
||||
*/
|
||||
public class GamePlayerRating {
|
||||
boolean hasWonTheCoin;
|
||||
|
||||
protected int turnsMade = 0;
|
||||
protected int openingHandSize = 7;
|
||||
protected int timesMulliganed = 0;
|
||||
/** The has won the coin. */
|
||||
private boolean hasWonTheCoin;
|
||||
|
||||
protected GameLossReason lossReason = GameLossReason.DidNotLoseYet;
|
||||
protected String lossSpellName;
|
||||
/** The turns made. */
|
||||
private int turnsMade = 0;
|
||||
|
||||
/** The opening hand size. */
|
||||
private int openingHandSize = 7;
|
||||
|
||||
/** The times mulliganed. */
|
||||
private int timesMulliganed = 0;
|
||||
|
||||
/** The loss reason. */
|
||||
private GameLossReason lossReason = GameLossReason.DidNotLoseYet;
|
||||
|
||||
/** The loss spell name. */
|
||||
private String lossSpellName;
|
||||
|
||||
/**
|
||||
* Gets the loss reason.
|
||||
*
|
||||
* @return the loss reason
|
||||
*/
|
||||
public final GameLossReason getLossReason() {
|
||||
return lossReason;
|
||||
}
|
||||
|
||||
public void setLossReason(GameLossReason loseCondition, String spellName) {
|
||||
lossReason = loseCondition;
|
||||
lossSpellName = spellName;
|
||||
}
|
||||
public String getLossSpellName() {
|
||||
return lossSpellName;
|
||||
return this.lossReason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the loss reason.
|
||||
*
|
||||
* @param loseCondition the lose condition
|
||||
* @param spellName the spell name
|
||||
*/
|
||||
public void setLossReason(final GameLossReason loseCondition, final String spellName) {
|
||||
this.lossReason = loseCondition;
|
||||
this.lossSpellName = spellName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the loss spell name.
|
||||
*
|
||||
* @return the loss spell name
|
||||
*/
|
||||
public String getLossSpellName() {
|
||||
return this.lossSpellName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opening hand size.
|
||||
*
|
||||
* @return the opening hand size
|
||||
*/
|
||||
public final int getOpeningHandSize() {
|
||||
return openingHandSize;
|
||||
return this.openingHandSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify has mulliganed.
|
||||
*/
|
||||
public final void notifyHasMulliganed() {
|
||||
timesMulliganed++;
|
||||
this.timesMulliganed++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mulligan count.
|
||||
*
|
||||
* @return the mulligan count
|
||||
*/
|
||||
public final int getMulliganCount() {
|
||||
return timesMulliganed;
|
||||
return this.timesMulliganed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify opening hand size.
|
||||
*
|
||||
* @param newHand the new hand
|
||||
*/
|
||||
public final void notifyOpeningHandSize(final int newHand) {
|
||||
openingHandSize = newHand;
|
||||
this.openingHandSize = newHand;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,63 +3,141 @@ package forge.game;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* <p>GameInfo class.</p>
|
||||
*
|
||||
* <p>
|
||||
* GameInfo class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
// This class might be divided in two parts: the very summary (immutable with only getters) and
|
||||
// This class might be divided in two parts: the very summary (immutable with
|
||||
// only getters) and
|
||||
// GameObserver class - who should be notified of any considerable ingame event
|
||||
public final class GameSummary {
|
||||
protected String playerWinner = "Nobody";
|
||||
protected String playerGotFirstTurn = "Nobody";
|
||||
protected int lastTurnNumber = 0;
|
||||
|
||||
protected GameEndReason winCondition;
|
||||
protected String spellEffectWin;
|
||||
protected final Map<String, GamePlayerRating> playerRating = new HashMap<String, GamePlayerRating>();
|
||||
|
||||
public GameSummary(String... names)
|
||||
{
|
||||
for (String n : names) {
|
||||
playerRating.put(n, new GamePlayerRating());
|
||||
/** The player winner. */
|
||||
private String playerWinner = "Nobody";
|
||||
|
||||
/** The player got first turn. */
|
||||
private String playerGotFirstTurn = "Nobody";
|
||||
|
||||
/** The last turn number. */
|
||||
private int lastTurnNumber = 0;
|
||||
|
||||
/** The win condition. */
|
||||
private GameEndReason winCondition;
|
||||
|
||||
/** The spell effect win. */
|
||||
private String spellEffectWin;
|
||||
|
||||
/** The player rating. */
|
||||
private final Map<String, GamePlayerRating> playerRating = new HashMap<String, GamePlayerRating>();
|
||||
|
||||
/**
|
||||
* Instantiates a new game summary.
|
||||
*
|
||||
* @param names the names
|
||||
*/
|
||||
public GameSummary(final String... names) {
|
||||
for (final String n : names) {
|
||||
this.playerRating.put(n, new GamePlayerRating());
|
||||
}
|
||||
}
|
||||
|
||||
public final void end( final GameEndReason condition, String winner, String spellEffect )
|
||||
{
|
||||
winCondition = condition;
|
||||
playerWinner = winner;
|
||||
spellEffectWin = spellEffect;
|
||||
|
||||
/**
|
||||
* End.
|
||||
*
|
||||
* @param condition the condition
|
||||
* @param winner the winner
|
||||
* @param spellEffect the spell effect
|
||||
*/
|
||||
public void end(final GameEndReason condition, final String winner, final String spellEffect) {
|
||||
this.winCondition = condition;
|
||||
this.playerWinner = winner;
|
||||
this.spellEffectWin = spellEffect;
|
||||
}
|
||||
public final boolean isDraw() { return null == playerWinner; }
|
||||
public final boolean isWinner(String name) { return name != null && name.equals(playerWinner); }
|
||||
public String getWinner() { return playerWinner; }
|
||||
|
||||
public GameEndReason getWinCondition() { return winCondition; }
|
||||
public GamePlayerRating getPlayerRating(String name) { return playerRating.get(name); }
|
||||
/**
|
||||
* Checks if is draw.
|
||||
*
|
||||
* @return true, if is draw
|
||||
*/
|
||||
public boolean isDraw() {
|
||||
return null == this.playerWinner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is winner.
|
||||
*
|
||||
* @param name the name
|
||||
* @return true, if is winner
|
||||
*/
|
||||
public boolean isWinner(final String name) {
|
||||
return (name != null) && name.equals(this.playerWinner);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the winner.
|
||||
*
|
||||
* @return the winner
|
||||
*/
|
||||
public String getWinner() {
|
||||
return this.playerWinner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the win condition.
|
||||
*
|
||||
* @return the win condition
|
||||
*/
|
||||
public GameEndReason getWinCondition() {
|
||||
return this.winCondition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player rating.
|
||||
*
|
||||
* @param name the name
|
||||
* @return the player rating
|
||||
*/
|
||||
public GamePlayerRating getPlayerRating(final String name) {
|
||||
return this.playerRating.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the turn game ended.
|
||||
*
|
||||
* @return the turn game ended
|
||||
*/
|
||||
public int getTurnGameEnded() {
|
||||
return lastTurnNumber;
|
||||
}
|
||||
|
||||
public final void setPlayerWhoGotFirstTurn(String playerName)
|
||||
{
|
||||
playerGotFirstTurn = playerName;
|
||||
return this.lastTurnNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the player who got first turn.
|
||||
*
|
||||
* @param playerName the new player who got first turn
|
||||
*/
|
||||
public void setPlayerWhoGotFirstTurn(final String playerName) {
|
||||
this.playerGotFirstTurn = playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify next turn.
|
||||
*/
|
||||
public void notifyNextTurn() {
|
||||
lastTurnNumber++;
|
||||
this.lastTurnNumber++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the win spell effect.
|
||||
*
|
||||
* @return the win spell effect
|
||||
*/
|
||||
public String getWinSpellEffect() {
|
||||
return spellEffectWin;
|
||||
return this.spellEffectWin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,25 +1,50 @@
|
||||
package forge.game;
|
||||
|
||||
/**
|
||||
/**
|
||||
* GameType is an enum to determine the type of current game. :)
|
||||
*/
|
||||
public enum GameType {
|
||||
|
||||
/** The Constructed. */
|
||||
Constructed(false),
|
||||
Sealed(true),
|
||||
Draft(true),
|
||||
Commander(false),
|
||||
Quest(true);
|
||||
/** The Sealed. */
|
||||
Sealed(true),
|
||||
/** The Draft. */
|
||||
Draft(true),
|
||||
/** The Commander. */
|
||||
Commander(false),
|
||||
/** The Quest. */
|
||||
Quest(true);
|
||||
|
||||
private final boolean bLimited;
|
||||
public final boolean isLimited() { return bLimited; }
|
||||
|
||||
GameType(final boolean isLimited) {
|
||||
bLimited = isLimited;
|
||||
/**
|
||||
* Checks if is limited.
|
||||
*
|
||||
* @return true, if is limited
|
||||
*/
|
||||
public final boolean isLimited() {
|
||||
return this.bLimited;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new game type.
|
||||
*
|
||||
* @param isLimited the is limited
|
||||
*/
|
||||
GameType(final boolean isLimited) {
|
||||
this.bLimited = isLimited;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smart value of.
|
||||
*
|
||||
* @param value the value
|
||||
* @return the game type
|
||||
*/
|
||||
public static GameType smartValueOf(final String value) {
|
||||
String valToCompate = value.trim();
|
||||
for (GameType v : GameType.values()) {
|
||||
final String valToCompate = value.trim();
|
||||
for (final GameType v : GameType.values()) {
|
||||
if (v.name().compareToIgnoreCase(valToCompate) == 0) {
|
||||
return v;
|
||||
}
|
||||
|
||||
@@ -5,52 +5,57 @@ import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
/**
|
||||
* <p>BoosterDraft interface.</p>
|
||||
*
|
||||
* <p>
|
||||
* BoosterDraft interface.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface BoosterDraft {
|
||||
/**
|
||||
* <p>nextChoice.</p>
|
||||
*
|
||||
* <p>
|
||||
* nextChoice.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
ItemPoolView<CardPrinted> nextChoice();
|
||||
|
||||
/**
|
||||
* <p>setChoice.</p>
|
||||
*
|
||||
* @param c a {@link forge.Card} object.
|
||||
* <p>
|
||||
* setChoice.
|
||||
* </p>
|
||||
*
|
||||
* @param c
|
||||
* a {@link forge.Card} object.
|
||||
*/
|
||||
void setChoice(CardPrinted c);
|
||||
|
||||
/**
|
||||
* <p>hasNextChoice.</p>
|
||||
*
|
||||
* <p>
|
||||
* hasNextChoice.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
boolean hasNextChoice();
|
||||
|
||||
/**
|
||||
* <p>getDecks.</p>
|
||||
*
|
||||
* <p>
|
||||
* getDecks.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.deck.Deck} objects.
|
||||
*/
|
||||
Deck[] getDecks(); //size 7, all the computers decks
|
||||
Deck[] getDecks(); // size 7, all the computers decks
|
||||
|
||||
/** Constant <code>LandSetCode="{}"</code>. */
|
||||
public String LandSetCode[] = {""};
|
||||
String[] LAND_SET_CODE = { "" };
|
||||
|
||||
/**
|
||||
* Called when drafting is over - to upload picks.
|
||||
*/
|
||||
void finishedDrafting();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,19 @@
|
||||
package forge.game.limited;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
@@ -18,156 +32,154 @@ import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO Write javadoc for this type.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public final class BoosterDraft_1 implements BoosterDraft {
|
||||
private final BoosterDraftAI draftAI = new BoosterDraftAI();
|
||||
private static final int nPlayers = 8;
|
||||
private static final int N_PLAYERS = 8;
|
||||
|
||||
private int nextBoosterGroup = 0;
|
||||
private int currentBoosterSize = 0;
|
||||
private int currentBoosterPick = 0;
|
||||
private List<List<CardPrinted>> pack; //size 8
|
||||
|
||||
public Map<String,Float> draftPicks = new TreeMap<String,Float>();
|
||||
private CardPoolLimitation draftFormat;
|
||||
private List<List<CardPrinted>> pack; // size 8
|
||||
|
||||
private ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||
/** The draft picks. */
|
||||
private Map<String, Float> draftPicks = new TreeMap<String, Float>();
|
||||
private final CardPoolLimitation draftFormat;
|
||||
|
||||
private final ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||
|
||||
/**
|
||||
* <p>Constructor for BoosterDraft_1.</p>
|
||||
*
|
||||
* @param draftType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for BoosterDraft_1.
|
||||
* </p>
|
||||
*
|
||||
* @param draftType
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public BoosterDraft_1(CardPoolLimitation draftType) {
|
||||
draftAI.bd = this;
|
||||
draftFormat = draftType;
|
||||
public BoosterDraft_1(final CardPoolLimitation draftType) {
|
||||
this.draftAI.setBd(this);
|
||||
this.draftFormat = draftType;
|
||||
|
||||
switch (draftType) {
|
||||
case Full: // Draft from all cards in Forge
|
||||
BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
packs.add(picker);
|
||||
case Full: // Draft from all cards in Forge
|
||||
final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
this.packs.add(picker);
|
||||
}
|
||||
|
||||
BoosterDraft.LAND_SET_CODE[0] = CardDb.instance().getCard("Plains").getSet();
|
||||
break;
|
||||
|
||||
case Block: // Draft from cards by block or set
|
||||
final List<CardBlock> blocks = SetUtils.getBlocks();
|
||||
|
||||
final Object o = GuiUtils.getChoice("Choose Block", blocks.toArray());
|
||||
final CardBlock block = (CardBlock) o;
|
||||
|
||||
final CardSet[] cardSets = block.getSets();
|
||||
final String[] sets = new String[cardSets.length];
|
||||
for (int k = cardSets.length - 1; k >= 0; --k) {
|
||||
sets[k] = cardSets[k].getCode();
|
||||
}
|
||||
|
||||
final int nPacks = block.getCntBoostersDraft();
|
||||
|
||||
final ArrayList<String> setCombos = new ArrayList<String>();
|
||||
if (sets.length >= 2) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1]));
|
||||
}
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2]));
|
||||
}
|
||||
|
||||
if (sets.length > 1) {
|
||||
final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||
final String[] pp = p.toString().split("/");
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||
this.packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||
}
|
||||
|
||||
LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
||||
break;
|
||||
|
||||
case Block: // Draft from cards by block or set
|
||||
List<CardBlock> blocks = SetUtils.getBlocks();
|
||||
|
||||
Object o = GuiUtils.getChoice("Choose Block", blocks.toArray());
|
||||
CardBlock block = (CardBlock) o;
|
||||
|
||||
CardSet[] cardSets = block.getSets();
|
||||
String[] sets = new String[cardSets.length];
|
||||
for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();}
|
||||
|
||||
int nPacks = block.getCntBoostersDraft();
|
||||
|
||||
ArrayList<String> setCombos = new ArrayList<String>();
|
||||
if (sets.length >= 2) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[1], sets[1], sets[1]));
|
||||
|
||||
} else {
|
||||
final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
this.packs.add(pick1);
|
||||
}
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[1], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[1]));
|
||||
setCombos.add(String.format("%s/%s/%s", sets[2], sets[2], sets[2]));
|
||||
}
|
||||
|
||||
|
||||
if (sets.length > 1) {
|
||||
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||
String[] pp = p.toString().split("/");
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||
}
|
||||
|
||||
} else {
|
||||
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> pick1 = BoosterGenerator.getSimplePicker(bpOne);
|
||||
for (int i = 0; i < nPacks; i++) { packs.add(pick1); }
|
||||
}
|
||||
|
||||
LandSetCode[0] = block.getLandSet().getCode();
|
||||
break;
|
||||
|
||||
case Custom:
|
||||
List<CustomLimited> myDrafts = loadCustomDrafts("res/draft/", ".draft");
|
||||
|
||||
if (myDrafts.size() < 1) {
|
||||
JOptionPane.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft", myDrafts.toArray());
|
||||
setupCustomDraft(draft);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!");
|
||||
}
|
||||
|
||||
BoosterDraft.LAND_SET_CODE[0] = block.getLandSet().getCode();
|
||||
break;
|
||||
|
||||
case Custom:
|
||||
final List<CustomLimited> myDrafts = this.loadCustomDrafts("res/draft/", ".draft");
|
||||
|
||||
if (myDrafts.size() < 1) {
|
||||
JOptionPane
|
||||
.showMessageDialog(null, "No custom draft files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Draft",
|
||||
myDrafts.toArray());
|
||||
this.setupCustomDraft(draft);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new NoSuchElementException("Draft for mode " + draftType + " has not been set up!");
|
||||
}
|
||||
|
||||
pack = get8BoosterPack();
|
||||
this.pack = this.get8BoosterPack();
|
||||
}
|
||||
|
||||
private void setupCustomDraft(final CustomLimited draft)
|
||||
{
|
||||
DeckManager dio = AllZone.getDeckManager();
|
||||
Deck dPool = dio.getDeck(draft.DeckFile);
|
||||
private void setupCustomDraft(final CustomLimited draft) {
|
||||
final DeckManager dio = AllZone.getDeckManager();
|
||||
final Deck dPool = dio.getDeck(draft.DeckFile);
|
||||
if (dPool == null) {
|
||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
||||
}
|
||||
|
||||
BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
|
||||
if ( draft.IgnoreRarity ) {
|
||||
final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
@Override
|
||||
public List<CardPrinted> apply(final BoosterGenerator pack) {
|
||||
if (draft.IgnoreRarity) {
|
||||
if (!draft.Singleton) {
|
||||
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
||||
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
||||
} else {
|
||||
return pack.getSingletonBoosterPack(draft.NumCards);
|
||||
}
|
||||
}
|
||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, 0, 0, 0);
|
||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics,
|
||||
draft.NumSpecials, 0, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(fnPick, bpCustom);
|
||||
for (int i = 0; i < draft.NumPacks; i++) { packs.add(picker); }
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(
|
||||
fnPick, bpCustom);
|
||||
for (int i = 0; i < draft.NumPacks; i++) {
|
||||
this.packs.add(picker);
|
||||
}
|
||||
|
||||
LandSetCode[0] = draft.LandSetCode;
|
||||
BoosterDraft.LAND_SET_CODE[0] = draft.LandSetCode;
|
||||
}
|
||||
|
||||
/** Looks for res/draft/*.draft files, reads them, returns a list */
|
||||
private List<CustomLimited> loadCustomDrafts(String lookupFolder, String fileExtension)
|
||||
{
|
||||
|
||||
/** Looks for res/draft/*.draft files, reads them, returns a list. */
|
||||
private List<CustomLimited> loadCustomDrafts(final String lookupFolder, final String fileExtension) {
|
||||
String[] dList;
|
||||
ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||
final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||
|
||||
// get list of custom draft files
|
||||
File dFolder = new File(lookupFolder);
|
||||
final File dFolder = new File(lookupFolder);
|
||||
if (!dFolder.exists()) {
|
||||
throw new RuntimeException("BoosterDraft : folder not found -- folder is " + dFolder.getAbsolutePath());
|
||||
}
|
||||
@@ -178,151 +190,172 @@ public final class BoosterDraft_1 implements BoosterDraft {
|
||||
|
||||
dList = dFolder.list();
|
||||
|
||||
for (int i = 0; i < dList.length; i++) {
|
||||
if (dList[i].endsWith(fileExtension)) {
|
||||
List<String> dfData = FileUtil.readFile(lookupFolder + dList[i]);
|
||||
for (final String element : dList) {
|
||||
if (element.endsWith(fileExtension)) {
|
||||
final List<String> dfData = FileUtil.readFile(lookupFolder + element);
|
||||
customs.add(CustomLimited.parse(dfData));
|
||||
}
|
||||
}
|
||||
return customs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* <p>nextChoice.</p>
|
||||
*
|
||||
* <p>
|
||||
* nextChoice.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
@Override
|
||||
public ItemPoolView<CardPrinted> nextChoice() {
|
||||
if (pack.get(getCurrentBoosterIndex()).size() == 0) {
|
||||
pack = get8BoosterPack();
|
||||
if (this.pack.get(this.getCurrentBoosterIndex()).size() == 0) {
|
||||
this.pack = this.get8BoosterPack();
|
||||
}
|
||||
|
||||
computerChoose();
|
||||
return ItemPool.createFrom(pack.get(getCurrentBoosterIndex()), CardPrinted.class);
|
||||
this.computerChoose();
|
||||
return ItemPool.createFrom(this.pack.get(this.getCurrentBoosterIndex()), CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>get8BoosterPack.</p>
|
||||
*
|
||||
* <p>
|
||||
* get8BoosterPack.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.CardList} objects.
|
||||
*/
|
||||
public List<List<CardPrinted>> get8BoosterPack() {
|
||||
if (nextBoosterGroup >= packs.size()) { return null; }
|
||||
if (this.nextBoosterGroup >= this.packs.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<List<CardPrinted>> list = new ArrayList<List<CardPrinted>>();
|
||||
for (int i = 0; i < 8; i++) { list.add(packs.get(nextBoosterGroup).apply()); }
|
||||
|
||||
nextBoosterGroup++;
|
||||
currentBoosterSize = list.get(0).size();
|
||||
currentBoosterPick = 0;
|
||||
final List<List<CardPrinted>> list = new ArrayList<List<CardPrinted>>();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
list.add(this.packs.get(this.nextBoosterGroup).apply());
|
||||
}
|
||||
|
||||
this.nextBoosterGroup++;
|
||||
this.currentBoosterSize = list.get(0).size();
|
||||
this.currentBoosterPick = 0;
|
||||
return list;
|
||||
}
|
||||
|
||||
//size 7, all the computers decks
|
||||
// size 7, all the computers decks
|
||||
|
||||
/**
|
||||
* <p>getDecks.</p>
|
||||
*
|
||||
* <p>
|
||||
* getDecks.
|
||||
* </p>
|
||||
*
|
||||
* @return an array of {@link forge.deck.Deck} objects.
|
||||
*/
|
||||
@Override
|
||||
public Deck[] getDecks() {
|
||||
return draftAI.getDecks();
|
||||
return this.draftAI.getDecks();
|
||||
}
|
||||
|
||||
private void computerChoose() {
|
||||
|
||||
int iHumansBooster = getCurrentBoosterIndex();
|
||||
final int iHumansBooster = this.getCurrentBoosterIndex();
|
||||
int iPlayer = 0;
|
||||
for (int i = 0; i < pack.size(); i++) {
|
||||
if (iHumansBooster == i) { continue; } // don't touch player's booster
|
||||
for (int i = 0; i < this.pack.size(); i++) {
|
||||
if (iHumansBooster == i) {
|
||||
continue;
|
||||
} // don't touch player's booster
|
||||
|
||||
CardList forAi = new CardList();
|
||||
List<CardPrinted> booster = pack.get(i);
|
||||
for (CardPrinted cr : booster) {
|
||||
final CardList forAi = new CardList();
|
||||
final List<CardPrinted> booster = this.pack.get(i);
|
||||
for (final CardPrinted cr : booster) {
|
||||
forAi.add(cr.toForgeCard());
|
||||
}
|
||||
// TODO: Please write this drafting code to work without heavy card objects
|
||||
Card aiPick = draftAI.choose(forAi, iPlayer++);
|
||||
String pickedName = aiPick.getName();
|
||||
// TODO: Please write this drafting code to work without heavy card
|
||||
// objects
|
||||
final Card aiPick = this.draftAI.choose(forAi, iPlayer++);
|
||||
final String pickedName = aiPick.getName();
|
||||
|
||||
for (int pick = booster.size() - 1; pick >= 0; pick--) {
|
||||
CardPrinted cp = booster.get(pick);
|
||||
final CardPrinted cp = booster.get(pick);
|
||||
if (cp.getName().equalsIgnoreCase(pickedName)) {
|
||||
booster.remove(pick);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} //computerChoose()
|
||||
} // computerChoose()
|
||||
|
||||
private int getCurrentBoosterIndex() {
|
||||
return currentBoosterPick % nPlayers;
|
||||
return this.currentBoosterPick % BoosterDraft_1.N_PLAYERS;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>hasNextChoice.</p>
|
||||
*
|
||||
* <p>
|
||||
* hasNextChoice.
|
||||
* </p>
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNextChoice() {
|
||||
boolean isLastGroup = nextBoosterGroup >= packs.size();
|
||||
boolean isBoosterDepleted = currentBoosterPick >= currentBoosterSize;
|
||||
boolean noMoreCards = isLastGroup && isBoosterDepleted;
|
||||
final boolean isLastGroup = this.nextBoosterGroup >= this.packs.size();
|
||||
final boolean isBoosterDepleted = this.currentBoosterPick >= this.currentBoosterSize;
|
||||
final boolean noMoreCards = isLastGroup && isBoosterDepleted;
|
||||
return !noMoreCards;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void setChoice(final CardPrinted c) {
|
||||
List<CardPrinted> thisBooster = pack.get(getCurrentBoosterIndex());
|
||||
final List<CardPrinted> thisBooster = this.pack.get(this.getCurrentBoosterIndex());
|
||||
|
||||
if (!thisBooster.contains(c)) {
|
||||
throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c + " - booster pack = " + thisBooster);
|
||||
throw new RuntimeException("BoosterDraft : setChoice() error - card not found - " + c
|
||||
+ " - booster pack = " + thisBooster);
|
||||
}
|
||||
|
||||
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
||||
for (int i = 0; i < thisBooster.size(); i++) {
|
||||
CardPrinted cc = thisBooster.get(i);
|
||||
String cnBk = cc.getName() + "|" + cc.getSet();
|
||||
final CardPrinted cc = thisBooster.get(i);
|
||||
final String cnBk = cc.getName() + "|" + cc.getSet();
|
||||
|
||||
float pickValue = 0;
|
||||
if (cc.equals(c)) {
|
||||
pickValue = thisBooster.size() * (1f - ((float) currentBoosterPick / currentBoosterSize) * 2f);
|
||||
pickValue = thisBooster.size()
|
||||
* (1f - (((float) this.currentBoosterPick / this.currentBoosterSize) * 2f));
|
||||
} else {
|
||||
pickValue = 0;
|
||||
}
|
||||
|
||||
if (!draftPicks.containsKey(cnBk)) {
|
||||
draftPicks.put(cnBk, pickValue);
|
||||
if (!this.draftPicks.containsKey(cnBk)) {
|
||||
this.draftPicks.put(cnBk, pickValue);
|
||||
} else {
|
||||
float curValue = draftPicks.get(cnBk);
|
||||
float newValue = (curValue + pickValue) / 2;
|
||||
draftPicks.put(cnBk, newValue);
|
||||
final float curValue = this.draftPicks.get(cnBk);
|
||||
final float newValue = (curValue + pickValue) / 2;
|
||||
this.draftPicks.put(cnBk, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thisBooster.remove(c);
|
||||
currentBoosterPick++;
|
||||
} //setChoice()
|
||||
this.currentBoosterPick++;
|
||||
} // setChoice()
|
||||
|
||||
/** This will upload drafting picks to cardforge HQ. */
|
||||
@Override
|
||||
public void finishedDrafting() {
|
||||
if (Constant.Runtime.UPLOAD_DRAFT[0]) {
|
||||
if (draftPicks.size() > 1) {
|
||||
ArrayList<String> outDraftData = new ArrayList<String>();
|
||||
if (this.draftPicks.size() > 1) {
|
||||
final ArrayList<String> outDraftData = new ArrayList<String>();
|
||||
|
||||
String[] keys = draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
final String[] keys = this.draftPicks.keySet().toArray(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
|
||||
for (int i = 0; i < keys.length; i++) {
|
||||
outDraftData.add(keys[i] + "|" + draftPicks.get(keys[i]));
|
||||
for (final String key : keys) {
|
||||
outDraftData.add(key + "|" + this.draftPicks.get(key));
|
||||
}
|
||||
|
||||
FileUtil.writeFile("res/draft/tmpDraftData.txt", outDraftData);
|
||||
|
||||
HttpUtil poster = new HttpUtil();
|
||||
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt="
|
||||
+ draftFormat, "res/draft/tmpDraftData.txt");
|
||||
final HttpUtil poster = new HttpUtil();
|
||||
poster.upload("http://cardforge.org/draftAI/submitDraftData.php?fmt=" + this.draftFormat,
|
||||
"res/draft/tmpDraftData.txt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,73 @@
|
||||
package forge.game.limited;
|
||||
|
||||
/**
|
||||
* <p>CCnt class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CCnt class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
class CCnt {
|
||||
public String Color;
|
||||
public int Count;
|
||||
|
||||
/** The Color. */
|
||||
private String color;
|
||||
|
||||
/** The Count. */
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* <p>Constructor for CCnt.</p>
|
||||
*
|
||||
* @param clr a {@link java.lang.String} object.
|
||||
* @param cnt a int.
|
||||
* <p>
|
||||
* Constructor for CCnt.
|
||||
* </p>
|
||||
*
|
||||
* @param clr
|
||||
* a {@link java.lang.String} object.
|
||||
* @param cnt
|
||||
* a int.
|
||||
*/
|
||||
/**
|
||||
* <p>deckColors class.</p>
|
||||
*
|
||||
* @param clr a {@link java.lang.String} object.
|
||||
* @param cnt a int.
|
||||
* <p>
|
||||
* deckColors class.
|
||||
* </p>
|
||||
*
|
||||
* @param clr
|
||||
* a {@link java.lang.String} object.
|
||||
* @param cnt
|
||||
* a int.
|
||||
*/
|
||||
public CCnt(final String clr, final int cnt) {
|
||||
Color = clr;
|
||||
Count = cnt;
|
||||
this.setColor(clr);
|
||||
this.setCount(cnt);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the color
|
||||
*/
|
||||
public String getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param color
|
||||
* the color to set
|
||||
*/
|
||||
public void setColor(final String color) {
|
||||
this.color = color; // TODO: Add 0 to parameter's name.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the count
|
||||
*/
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param count
|
||||
* the count to set
|
||||
*/
|
||||
public void setCount(final int count) {
|
||||
this.count = count; // TODO: Add 0 to parameter's name.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package forge.game.limited;
|
||||
|
||||
/**
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*
|
||||
*/
|
||||
public enum CardPoolLimitation {
|
||||
|
||||
/** The Full. */
|
||||
Full,
|
||||
Block,
|
||||
Custom
|
||||
/** The Block. */
|
||||
Block,
|
||||
/** The Custom. */
|
||||
Custom
|
||||
}
|
||||
|
||||
@@ -5,53 +5,125 @@ import java.util.List;
|
||||
import forge.AllZone;
|
||||
|
||||
/**
|
||||
* <p>CustomDraft class.</p>
|
||||
*
|
||||
* <p>
|
||||
* CustomDraft class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
class CustomLimited {
|
||||
|
||||
/** The Name. */
|
||||
public String Name;
|
||||
|
||||
/** The Type. */
|
||||
public String Type;
|
||||
|
||||
/** The Deck file. */
|
||||
public String DeckFile;
|
||||
|
||||
/** The Ignore rarity. */
|
||||
public Boolean IgnoreRarity;
|
||||
|
||||
/** The Singleton. */
|
||||
public Boolean Singleton = false;
|
||||
|
||||
/** The Num cards. */
|
||||
public int NumCards = 15;
|
||||
|
||||
/** The Num specials. */
|
||||
public int NumSpecials = 0;
|
||||
|
||||
/** The Num mythics. */
|
||||
public int NumMythics = 1;
|
||||
|
||||
/** The Num rares. */
|
||||
public int NumRares = 1;
|
||||
|
||||
/** The Num uncommons. */
|
||||
public int NumUncommons = 3;
|
||||
|
||||
/** The Num commons. */
|
||||
public int NumCommons = 11;
|
||||
|
||||
/** The Num double faced. */
|
||||
public int NumDoubleFaced = 0;
|
||||
|
||||
/** The Num packs. */
|
||||
public int NumPacks = 3;
|
||||
|
||||
/** The Land set code. */
|
||||
public String LandSetCode = AllZone.getCardFactory().getCard("Plains", AllZone.getHumanPlayer()).getMostRecentSet();
|
||||
|
||||
@Override public String toString() { return Name; }
|
||||
|
||||
public static CustomLimited parse(List<String> dfData)
|
||||
{
|
||||
CustomLimited cd = new CustomLimited();
|
||||
|
||||
for (String dd : dfData) {
|
||||
String[] v = dd.split(":", 2);
|
||||
String key = v[0];
|
||||
String value = v.length > 1 ? v[1].trim() : "";
|
||||
|
||||
if (key.equalsIgnoreCase("Name")) { cd.Name = value; }
|
||||
if (key.equalsIgnoreCase("Type")) { cd.Type = value; }
|
||||
if (key.equalsIgnoreCase("DeckFile")) { cd.DeckFile = value; }
|
||||
if (key.equalsIgnoreCase("IgnoreRarity")) { cd.IgnoreRarity = value.equals("True"); }
|
||||
if (key.equalsIgnoreCase("Singleton")) { cd.Singleton = value.equals("True"); }
|
||||
if (key.equalsIgnoreCase("LandSetCode")) { cd.LandSetCode = value; }
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.Name;
|
||||
}
|
||||
|
||||
if (key.equalsIgnoreCase("NumCards")) { cd.NumCards = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumDoubleFaced")) { cd.NumDoubleFaced = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumSpecials")) { cd.NumSpecials = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumMythics")) { cd.NumMythics = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumRares")) { cd.NumRares = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumUncommons")) { cd.NumUncommons = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumCommons")) { cd.NumCommons = Integer.parseInt(value); }
|
||||
if (key.equalsIgnoreCase("NumPacks")) { cd.NumPacks = Integer.parseInt(value); }
|
||||
/**
|
||||
* Parses the.
|
||||
*
|
||||
* @param dfData
|
||||
* the df data
|
||||
* @return the custom limited
|
||||
*/
|
||||
public static CustomLimited parse(final List<String> dfData) {
|
||||
final CustomLimited cd = new CustomLimited();
|
||||
|
||||
for (final String dd : dfData) {
|
||||
final String[] v = dd.split(":", 2);
|
||||
final String key = v[0];
|
||||
final String value = v.length > 1 ? v[1].trim() : "";
|
||||
|
||||
if (key.equalsIgnoreCase("Name")) {
|
||||
cd.Name = value;
|
||||
}
|
||||
if (key.equalsIgnoreCase("Type")) {
|
||||
cd.Type = value;
|
||||
}
|
||||
if (key.equalsIgnoreCase("DeckFile")) {
|
||||
cd.DeckFile = value;
|
||||
}
|
||||
if (key.equalsIgnoreCase("IgnoreRarity")) {
|
||||
cd.IgnoreRarity = value.equals("True");
|
||||
}
|
||||
if (key.equalsIgnoreCase("Singleton")) {
|
||||
cd.Singleton = value.equals("True");
|
||||
}
|
||||
if (key.equalsIgnoreCase("LandSetCode")) {
|
||||
cd.LandSetCode = value;
|
||||
}
|
||||
|
||||
if (key.equalsIgnoreCase("NumCards")) {
|
||||
cd.NumCards = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumDoubleFaced")) {
|
||||
cd.NumDoubleFaced = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumSpecials")) {
|
||||
cd.NumSpecials = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumMythics")) {
|
||||
cd.NumMythics = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumRares")) {
|
||||
cd.NumRares = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumUncommons")) {
|
||||
cd.NumUncommons = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumCommons")) {
|
||||
cd.NumCommons = Integer.parseInt(value);
|
||||
}
|
||||
if (key.equalsIgnoreCase("NumPacks")) {
|
||||
cd.NumPacks = Integer.parseInt(value);
|
||||
}
|
||||
}
|
||||
return cd;
|
||||
}
|
||||
|
||||
@@ -3,56 +3,71 @@ package forge.game.limited;
|
||||
import forge.Constant;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: dhudson
|
||||
* Date: 6/24/11
|
||||
* Time: 8:42 PM
|
||||
* To change this template use File | Settings | File Templates.
|
||||
* Created by IntelliJ IDEA. User: dhudson Date: 6/24/11 Time: 8:42 PM To change
|
||||
* this template use File | Settings | File Templates.
|
||||
*/
|
||||
class DeckColors {
|
||||
|
||||
/** The Color1. */
|
||||
public String Color1 = "none";
|
||||
|
||||
/** The Color2. */
|
||||
public String Color2 = "none";
|
||||
//public String Splash = "none";
|
||||
// public String Splash = "none";
|
||||
/** The Mana1. */
|
||||
public String Mana1 = "";
|
||||
|
||||
/** The Mana2. */
|
||||
public String Mana2 = "";
|
||||
//public String ManaS = "";
|
||||
|
||||
// public String ManaS = "";
|
||||
|
||||
/**
|
||||
* <p>Constructor for deckColors.</p>
|
||||
*
|
||||
* @param c1 a {@link java.lang.String} object.
|
||||
* @param c2 a {@link java.lang.String} object.
|
||||
* @param sp a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for deckColors.
|
||||
* </p>
|
||||
*
|
||||
* @param c1
|
||||
* a {@link java.lang.String} object.
|
||||
* @param c2
|
||||
* a {@link java.lang.String} object.
|
||||
* @param sp
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public DeckColors(String c1, String c2, String sp) {
|
||||
Color1 = c1;
|
||||
Color2 = c2;
|
||||
//Splash = sp;
|
||||
public DeckColors(final String c1, final String c2, final String sp) {
|
||||
this.Color1 = c1;
|
||||
this.Color2 = c2;
|
||||
// Splash = sp;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Constructor for DeckColors.</p>
|
||||
* <p>
|
||||
* Constructor for DeckColors.
|
||||
* </p>
|
||||
*/
|
||||
public DeckColors() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>ColorToMana.</p>
|
||||
*
|
||||
* @param color a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* ColorToMana.
|
||||
* </p>
|
||||
*
|
||||
* @param color
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public String ColorToMana(String color) {
|
||||
String Mana[] = {"W", "U", "B", "R", "G"};
|
||||
public String ColorToMana(final String color) {
|
||||
final String Mana[] = { "W", "U", "B", "R", "G" };
|
||||
|
||||
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
||||
if (Constant.Color.ONLY_COLORS[i].equals(color))
|
||||
if (Constant.Color.ONLY_COLORS[i].equals(color)) {
|
||||
return Mana[i];
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
package forge.game.limited;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
import forge.AllZone;
|
||||
import forge.Card;
|
||||
import forge.CardList;
|
||||
@@ -21,164 +29,180 @@ import forge.item.CardDb;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import net.slightlymagic.braids.util.lambda.Lambda1;
|
||||
import net.slightlymagic.maxmtg.Closure1;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>SealedDeck class.</p>
|
||||
*
|
||||
* <p>
|
||||
* SealedDeck class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public class SealedDeck {
|
||||
private List<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||
public String LandSetCode[] = {""};
|
||||
private final List<Closure1<List<CardPrinted>, BoosterGenerator>> packs = new ArrayList<Closure1<List<CardPrinted>, BoosterGenerator>>();
|
||||
|
||||
/** The Land set code. */
|
||||
public String LandSetCode[] = { "" };
|
||||
|
||||
/**
|
||||
* <p>Constructor for SealedDeck.</p>
|
||||
*
|
||||
* @param sealedType a {@link java.lang.String} object.
|
||||
* <p>
|
||||
* Constructor for SealedDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param sealedType
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public SealedDeck(String sealedType) {
|
||||
public SealedDeck(final String sealedType) {
|
||||
|
||||
if (sealedType.equals("Full")) {
|
||||
BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||
for (int i = 0; i < 6; i++)
|
||||
packs.add(picker);
|
||||
final BoosterGenerator bpFull = new BoosterGenerator(CardDb.instance().getAllUniqueCards());
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpFull);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
this.packs.add(picker);
|
||||
}
|
||||
|
||||
LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
||||
this.LandSetCode[0] = CardDb.instance().getCard("Plains").getSet();
|
||||
} else if (sealedType.equals("Block")) {
|
||||
|
||||
Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray());
|
||||
CardBlock block = (CardBlock) o;
|
||||
final Object o = GuiUtils.getChoice("Choose Block", SetUtils.getBlocks().toArray());
|
||||
final CardBlock block = (CardBlock) o;
|
||||
|
||||
CardSet[] cardSets = block.getSets();
|
||||
String[] sets = new String[cardSets.length];
|
||||
for (int k = cardSets.length - 1; k >= 0 ; --k) { sets[k] = cardSets[k].getCode();}
|
||||
final CardSet[] cardSets = block.getSets();
|
||||
final String[] sets = new String[cardSets.length];
|
||||
for (int k = cardSets.length - 1; k >= 0; --k) {
|
||||
sets[k] = cardSets[k].getCode();
|
||||
}
|
||||
|
||||
int nPacks = block.getCntBoostersSealed();
|
||||
final int nPacks = block.getCntBoostersSealed();
|
||||
|
||||
List<String> setCombos = new ArrayList<String>();
|
||||
final List<String> setCombos = new ArrayList<String>();
|
||||
if (sets.length >= 2) {
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[0], sets[0], sets[0], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[0], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[1], sets[1], sets[1], sets[0], sets[0], sets[0]));
|
||||
}
|
||||
if (sets.length >= 3) {
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[2], sets[0], sets[0], sets[0]));
|
||||
setCombos.add(String.format("%s/%s/%s/%s/%s/%s", sets[2], sets[2], sets[1], sets[1], sets[0], sets[0]));
|
||||
}
|
||||
|
||||
|
||||
if (sets.length > 1) {
|
||||
Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||
final Object p = GuiUtils.getChoice("Choose Set Combination", setCombos.toArray());
|
||||
|
||||
String[] pp = p.toString().split("/");
|
||||
final String[] pp = p.toString().split("/");
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||
packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||
final BoosterGenerator bpMulti = new BoosterGenerator(SetUtils.getSetByCode(pp[i]));
|
||||
this.packs.add(BoosterGenerator.getSimplePicker(bpMulti));
|
||||
}
|
||||
} else {
|
||||
BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
||||
for (int i = 0; i < nPacks; i++) { packs.add(picker); }
|
||||
final BoosterGenerator bpOne = new BoosterGenerator(SetUtils.getSetByCode(sets[0]));
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> picker = BoosterGenerator.getSimplePicker(bpOne);
|
||||
for (int i = 0; i < nPacks; i++) {
|
||||
this.packs.add(picker);
|
||||
}
|
||||
}
|
||||
|
||||
LandSetCode[0] = block.getLandSet().getCode();
|
||||
this.LandSetCode[0] = block.getLandSet().getCode();
|
||||
|
||||
} else if (sealedType.equals("Custom")) {
|
||||
String dList[];
|
||||
ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||
final ArrayList<CustomLimited> customs = new ArrayList<CustomLimited>();
|
||||
|
||||
// get list of custom draft files
|
||||
File dFolder = new File("res/sealed/");
|
||||
if (!dFolder.exists())
|
||||
throw new RuntimeException("GenerateSealed : folder not found -- folder is " + dFolder.getAbsolutePath());
|
||||
final File dFolder = new File("res/sealed/");
|
||||
if (!dFolder.exists()) {
|
||||
throw new RuntimeException("GenerateSealed : folder not found -- folder is "
|
||||
+ dFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!dFolder.isDirectory())
|
||||
if (!dFolder.isDirectory()) {
|
||||
throw new RuntimeException("GenerateSealed : not a folder -- " + dFolder.getAbsolutePath());
|
||||
}
|
||||
|
||||
dList = dFolder.list();
|
||||
|
||||
for (int i = 0; i < dList.length; i++) {
|
||||
if (dList[i].endsWith(".sealed")) {
|
||||
ArrayList<String> dfData = FileUtil.readFile("res/sealed/" + dList[i]);
|
||||
CustomLimited cs = CustomLimited.parse(dfData);
|
||||
for (final String element : dList) {
|
||||
if (element.endsWith(".sealed")) {
|
||||
final ArrayList<String> dfData = FileUtil.readFile("res/sealed/" + element);
|
||||
final CustomLimited cs = CustomLimited.parse(dfData);
|
||||
customs.add(cs);
|
||||
}
|
||||
}
|
||||
|
||||
// present list to user
|
||||
if (customs.size() < 1)
|
||||
JOptionPane.showMessageDialog(null, "No custom sealed files found.", "", JOptionPane.INFORMATION_MESSAGE);
|
||||
if (customs.size() < 1) {
|
||||
JOptionPane.showMessageDialog(null, "No custom sealed files found.", "",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool",
|
||||
customs.toArray());
|
||||
|
||||
else {
|
||||
final CustomLimited draft = (CustomLimited) GuiUtils.getChoice("Choose Custom Sealed Pool", customs.toArray());
|
||||
|
||||
DeckManager dio = AllZone.getDeckManager();
|
||||
Deck dPool = dio.getDeck(draft.DeckFile);
|
||||
final DeckManager dio = AllZone.getDeckManager();
|
||||
final Deck dPool = dio.getDeck(draft.DeckFile);
|
||||
if (dPool == null) {
|
||||
throw new RuntimeException("BoosterGenerator : deck not found - " + draft.DeckFile);
|
||||
}
|
||||
|
||||
BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||
Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
@Override public List<CardPrinted> apply(BoosterGenerator pack) {
|
||||
if ( draft.IgnoreRarity ) {
|
||||
final BoosterGenerator bpCustom = new BoosterGenerator(dPool);
|
||||
final Lambda1<List<CardPrinted>, BoosterGenerator> fnPick = new Lambda1<List<CardPrinted>, BoosterGenerator>() {
|
||||
@Override
|
||||
public List<CardPrinted> apply(final BoosterGenerator pack) {
|
||||
if (draft.IgnoreRarity) {
|
||||
return pack.getBoosterPack(0, 0, 0, 0, 0, 0, 0, draft.NumCards, 0);
|
||||
}
|
||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares, draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0);
|
||||
return pack.getBoosterPack(draft.NumCommons, draft.NumUncommons, 0, draft.NumRares,
|
||||
draft.NumMythics, draft.NumSpecials, draft.NumDoubleFaced, 0, 0);
|
||||
}
|
||||
};
|
||||
|
||||
Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(fnPick, bpCustom);
|
||||
final Closure1<List<CardPrinted>, BoosterGenerator> picker = new Closure1<List<CardPrinted>, BoosterGenerator>(
|
||||
fnPick, bpCustom);
|
||||
|
||||
for (int i = 0; i < draft.NumPacks; i++) {
|
||||
packs.add(picker);
|
||||
this.packs.add(picker);
|
||||
}
|
||||
|
||||
LandSetCode[0] = draft.LandSetCode;
|
||||
this.LandSetCode[0] = draft.LandSetCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>getCardpool.</p>
|
||||
*
|
||||
* <p>
|
||||
* getCardpool.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link forge.CardList} object.
|
||||
*/
|
||||
public ItemPool<CardPrinted> getCardpool() {
|
||||
ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
final ItemPool<CardPrinted> pool = new ItemPool<CardPrinted>(CardPrinted.class);
|
||||
|
||||
for (int i = 0; i < packs.size(); i++)
|
||||
pool.addAllCards(packs.get(i).apply());
|
||||
for (int i = 0; i < this.packs.size(); i++) {
|
||||
pool.addAllCards(this.packs.get(i).apply());
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>buildAIDeck.</p>
|
||||
*
|
||||
* @param aiCardpool a {@link forge.CardList} object.
|
||||
* <p>
|
||||
* buildAIDeck.
|
||||
* </p>
|
||||
*
|
||||
* @param aiCardpool
|
||||
* a {@link forge.CardList} object.
|
||||
* @return a {@link forge.deck.Deck} object.
|
||||
*/
|
||||
public Deck buildAIDeck(CardList aiCardpool) {
|
||||
CardList deck = new CardList();
|
||||
public Deck buildAIDeck(final CardList aiCardpool) {
|
||||
final CardList deck = new CardList();
|
||||
|
||||
int cardsNeeded = 22;
|
||||
int landsNeeded = 18;
|
||||
int nCreatures = 15;
|
||||
|
||||
CardList AIPlayables = aiCardpool.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
final CardList AIPlayables = aiCardpool.filter(new CardListFilter() {
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
return !(c.getSVar("RemAIDeck").equals("True"));
|
||||
}
|
||||
});
|
||||
@@ -186,28 +210,32 @@ public class SealedDeck {
|
||||
CardList creatures = AIPlayables.getType("Creature");
|
||||
CardListUtil.sortByEvaluateCreature(creatures);
|
||||
|
||||
CardList colorChooserList = new CardList(); // choose colors based on top 33% of creatures
|
||||
for (int i = 0; i < (creatures.size() * .33); i++)
|
||||
final CardList colorChooserList = new CardList(); // choose colors based
|
||||
// on top 33% of
|
||||
// creatures
|
||||
for (int i = 0; i < (creatures.size() * .33); i++) {
|
||||
colorChooserList.add(creatures.get(i));
|
||||
}
|
||||
|
||||
int colorCounts[] = {0, 0, 0, 0, 0};
|
||||
String colors[] = Constant.Color.ONLY_COLORS;
|
||||
for (int i = 0; i < colors.length; i++)
|
||||
final int colorCounts[] = { 0, 0, 0, 0, 0 };
|
||||
final String colors[] = Constant.Color.ONLY_COLORS;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
colorCounts[i] = colorChooserList.getColor(colors[i]).size();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (colorCounts[i + 1] < colorCounts[i]) {
|
||||
int t = colorCounts[i];
|
||||
final int t = colorCounts[i];
|
||||
colorCounts[i] = colorCounts[i + 1];
|
||||
colorCounts[i + 1] = t;
|
||||
|
||||
String s = colors[i];
|
||||
final String s = colors[i];
|
||||
colors[i] = colors[i + 1];
|
||||
colors[i + 1] = s;
|
||||
}
|
||||
}
|
||||
|
||||
DeckColors dcAI = new DeckColors();
|
||||
final DeckColors dcAI = new DeckColors();
|
||||
dcAI.Color1 = colors[0];
|
||||
dcAI.Color2 = colors[1];
|
||||
dcAI.Splash = colors[2];
|
||||
@@ -220,8 +248,8 @@ public class SealedDeck {
|
||||
|
||||
CardListUtil.sortByEvaluateCreature(creatures);
|
||||
int i = 0;
|
||||
while (nCreatures > 0 && i < creatures.size()) {
|
||||
Card c = creatures.get(i);
|
||||
while ((nCreatures > 0) && (i < creatures.size())) {
|
||||
final Card c = creatures.get(i);
|
||||
|
||||
deck.add(c);
|
||||
aiCardpool.remove(c);
|
||||
@@ -231,9 +259,9 @@ public class SealedDeck {
|
||||
i++;
|
||||
}
|
||||
|
||||
CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash);
|
||||
while (nCreatures > 1 && splashCreatures.size() > 1) {
|
||||
Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1));
|
||||
final CardList splashCreatures = AIPlayables.getType("Creature").getColor(dcAI.Splash);
|
||||
while ((nCreatures > 1) && (splashCreatures.size() > 1)) {
|
||||
final Card c = splashCreatures.get(MyRandom.getRandom().nextInt(splashCreatures.size() - 1));
|
||||
|
||||
deck.add(c);
|
||||
aiCardpool.remove(c);
|
||||
@@ -243,7 +271,7 @@ public class SealedDeck {
|
||||
nCreatures--;
|
||||
}
|
||||
|
||||
CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||
final CardList walkers = AIPlayables.getType("Planeswalker").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||
if (walkers.size() > 0) {
|
||||
deck.add(walkers.get(0));
|
||||
AIPlayables.remove(walkers.get(0));
|
||||
@@ -251,12 +279,12 @@ public class SealedDeck {
|
||||
cardsNeeded--;
|
||||
}
|
||||
|
||||
CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||
final CardList spells = AIPlayables.getType("Instant").getOnly2Colors(dcAI.Color1, dcAI.Color2);
|
||||
spells.addAll(AIPlayables.getType("Sorcery").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
||||
spells.addAll(AIPlayables.getType("Enchantment").getOnly2Colors(dcAI.Color1, dcAI.Color2));
|
||||
|
||||
while (cardsNeeded > 0 && spells.size() > 1) {
|
||||
Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1));
|
||||
while ((cardsNeeded > 0) && (spells.size() > 1)) {
|
||||
final Card c = spells.get(MyRandom.getRandom().nextInt(spells.size() - 1));
|
||||
deck.add(c);
|
||||
spells.remove(c);
|
||||
AIPlayables.remove(c);
|
||||
@@ -264,11 +292,11 @@ public class SealedDeck {
|
||||
cardsNeeded--;
|
||||
}
|
||||
|
||||
CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash);
|
||||
final CardList splashSpells = AIPlayables.getType("Instant").getColor(dcAI.Splash);
|
||||
splashSpells.addAll(AIPlayables.getType("Sorcery").getColor(dcAI.Splash));
|
||||
|
||||
while (cardsNeeded > 0 && splashSpells.size() > 1) {
|
||||
Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1));
|
||||
while ((cardsNeeded > 0) && (splashSpells.size() > 1)) {
|
||||
final Card c = splashSpells.get(MyRandom.getRandom().nextInt(splashSpells.size() - 1));
|
||||
deck.add(c);
|
||||
splashSpells.remove(c);
|
||||
AIPlayables.remove(c);
|
||||
@@ -276,16 +304,18 @@ public class SealedDeck {
|
||||
cardsNeeded--;
|
||||
}
|
||||
|
||||
CardList lands = AIPlayables.getType("Land");
|
||||
final CardList lands = AIPlayables.getType("Land");
|
||||
if (lands.size() > 0) {
|
||||
final DeckColors AIdc = dcAI; // just for the filter
|
||||
final DeckColors AIdc = dcAI; // just for the filter
|
||||
|
||||
lands.filter(new CardListFilter() {
|
||||
public boolean addCard(Card c) {
|
||||
ArrayList<Ability_Mana> maList = c.getManaAbility();
|
||||
@Override
|
||||
public boolean addCard(final Card c) {
|
||||
final ArrayList<Ability_Mana> maList = c.getManaAbility();
|
||||
for (int j = 0; j < maList.size(); j++) {
|
||||
if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2))
|
||||
if (maList.get(j).canProduce(AIdc.Mana1) || maList.get(j).canProduce(AIdc.Mana2)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -294,7 +324,7 @@ public class SealedDeck {
|
||||
|
||||
if (lands.size() > 0) {
|
||||
for (i = 0; i < lands.size(); i++) {
|
||||
Card c = lands.get(i);
|
||||
final Card c = lands.get(i);
|
||||
|
||||
deck.add(c);
|
||||
aiCardpool.remove(c);
|
||||
@@ -304,52 +334,56 @@ public class SealedDeck {
|
||||
}
|
||||
}
|
||||
|
||||
if (landsNeeded > 0) // attempt to optimize basic land counts according to color representation
|
||||
if (landsNeeded > 0) // attempt to optimize basic land counts
|
||||
// according to color representation
|
||||
{
|
||||
CCnt ClrCnts[] = {new CCnt("Plains", 0),
|
||||
new CCnt("Island", 0),
|
||||
new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0),
|
||||
new CCnt("Forest", 0)};
|
||||
final CCnt ClrCnts[] = { new CCnt("Plains", 0), new CCnt("Island", 0), new CCnt("Swamp", 0),
|
||||
new CCnt("Mountain", 0), new CCnt("Forest", 0) };
|
||||
|
||||
// count each card color using mana costs
|
||||
// TODO: count hybrid mana differently?
|
||||
for (i = 0; i < deck.size(); i++) {
|
||||
String mc = deck.get(i).getManaCost();
|
||||
final String mc = deck.get(i).getManaCost();
|
||||
|
||||
// count each mana symbol in the mana cost
|
||||
for (int j = 0; j < mc.length(); j++) {
|
||||
char c = mc.charAt(j);
|
||||
final char c = mc.charAt(j);
|
||||
|
||||
if (c == 'W')
|
||||
ClrCnts[0].Count++;
|
||||
else if (c == 'U')
|
||||
ClrCnts[1].Count++;
|
||||
else if (c == 'B')
|
||||
ClrCnts[2].Count++;
|
||||
else if (c == 'R')
|
||||
ClrCnts[3].Count++;
|
||||
else if (c == 'G')
|
||||
ClrCnts[4].Count++;
|
||||
if (c == 'W') {
|
||||
ClrCnts[0].setCount(ClrCnts[0].getCount() + 1);
|
||||
} else if (c == 'U') {
|
||||
ClrCnts[1].setCount(ClrCnts[1].getCount() + 1);
|
||||
} else if (c == 'B') {
|
||||
ClrCnts[2].setCount(ClrCnts[2].getCount() + 1);
|
||||
} else if (c == 'R') {
|
||||
ClrCnts[3].setCount(ClrCnts[3].getCount() + 1);
|
||||
} else if (c == 'G') {
|
||||
ClrCnts[4].setCount(ClrCnts[4].getCount() + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// total of all ClrCnts
|
||||
int totalColor = 0;
|
||||
for (i = 0; i < 5; i++) {
|
||||
totalColor += ClrCnts[i].Count;
|
||||
totalColor += ClrCnts[i].getCount();
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (ClrCnts[i].Count > 0) { // calculate number of lands for each color
|
||||
float p = (float) ClrCnts[i].Count / (float) totalColor;
|
||||
int nLand = (int) ((float) landsNeeded * p) + 1;
|
||||
//tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand + "\n";
|
||||
if (Constant.Runtime.DEV_MODE[0])
|
||||
System.out.println("Basics[" + ClrCnts[i].Color + "]:" + nLand);
|
||||
if (ClrCnts[i].getCount() > 0) { // calculate number of
|
||||
// lands for
|
||||
// each color
|
||||
final float p = (float) ClrCnts[i].getCount() / (float) totalColor;
|
||||
final int nLand = (int) (landsNeeded * p) + 1;
|
||||
// tmpDeck += "nLand-" + ClrCnts[i].Color + ":" + nLand
|
||||
// + "\n";
|
||||
if (Constant.Runtime.DEV_MODE[0]) {
|
||||
System.out.println("Basics[" + ClrCnts[i].getColor() + "]:" + nLand);
|
||||
}
|
||||
|
||||
for (int j = 0; j <= nLand; j++) {
|
||||
Card c = AllZone.getCardFactory().getCard(ClrCnts[i].Color, AllZone.getComputerPlayer());
|
||||
final Card c = AllZone.getCardFactory().getCard(ClrCnts[i].getColor(),
|
||||
AllZone.getComputerPlayer());
|
||||
c.setCurSetCode(this.LandSetCode[0]);
|
||||
deck.add(c);
|
||||
landsNeeded--;
|
||||
@@ -358,63 +392,103 @@ public class SealedDeck {
|
||||
}
|
||||
int n = 0;
|
||||
while (landsNeeded > 0) {
|
||||
if (ClrCnts[n].Count > 0) {
|
||||
Card c = AllZone.getCardFactory().getCard(ClrCnts[n].Color, AllZone.getComputerPlayer());
|
||||
if (ClrCnts[n].getCount() > 0) {
|
||||
final Card c = AllZone.getCardFactory().getCard(ClrCnts[n].getColor(),
|
||||
AllZone.getComputerPlayer());
|
||||
c.setCurSetCode(this.LandSetCode[0]);
|
||||
deck.add(c);
|
||||
landsNeeded--;
|
||||
|
||||
if (Constant.Runtime.DEV_MODE[0])
|
||||
if (Constant.Runtime.DEV_MODE[0]) {
|
||||
System.out.println("AddBasics: " + c.getName());
|
||||
}
|
||||
}
|
||||
if (++n > 4)
|
||||
if (++n > 4) {
|
||||
n = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Deck aiDeck = new Deck(GameType.Sealed);
|
||||
final Deck aiDeck = new Deck(GameType.Sealed);
|
||||
|
||||
for (i = 0; i < deck.size(); i++)
|
||||
for (i = 0; i < deck.size(); i++) {
|
||||
aiDeck.addMain(deck.get(i).getName() + "|" + deck.get(i).getCurSetCode());
|
||||
}
|
||||
|
||||
for (i = 0; i < aiCardpool.size(); i++)
|
||||
for (i = 0; i < aiCardpool.size(); i++) {
|
||||
aiDeck.addSideboard(aiCardpool.get(i).getName() + "|" + aiCardpool.get(i).getCurSetCode());
|
||||
}
|
||||
|
||||
return aiDeck;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class DeckColors.
|
||||
*/
|
||||
class DeckColors {
|
||||
|
||||
/** The Color1. */
|
||||
public String Color1 = "none";
|
||||
|
||||
/** The Color2. */
|
||||
public String Color2 = "none";
|
||||
|
||||
/** The Splash. */
|
||||
public String Splash = "none";
|
||||
|
||||
/** The Mana1. */
|
||||
public String Mana1 = "";
|
||||
|
||||
/** The Mana2. */
|
||||
public String Mana2 = "";
|
||||
|
||||
/** The Mana s. */
|
||||
public String ManaS = "";
|
||||
|
||||
public DeckColors(String c1, String c2, String sp) {
|
||||
Color1 = c1;
|
||||
Color2 = c2;
|
||||
//Splash = sp;
|
||||
/**
|
||||
* Instantiates a new deck colors.
|
||||
*
|
||||
* @param c1
|
||||
* the c1
|
||||
* @param c2
|
||||
* the c2
|
||||
* @param sp
|
||||
* the sp
|
||||
*/
|
||||
public DeckColors(final String c1, final String c2, final String sp) {
|
||||
this.Color1 = c1;
|
||||
this.Color2 = c2;
|
||||
// Splash = sp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck colors.
|
||||
*/
|
||||
public DeckColors() {
|
||||
|
||||
}
|
||||
|
||||
public String ColorToMana(String color) {
|
||||
String Mana[] = {"W", "U", "B", "R", "G"};
|
||||
String Clrs[] = {"white", "blue", "black", "red", "green"};
|
||||
/**
|
||||
* Color to mana.
|
||||
*
|
||||
* @param color
|
||||
* the color
|
||||
* @return the string
|
||||
*/
|
||||
public String ColorToMana(final String color) {
|
||||
final String Mana[] = { "W", "U", "B", "R", "G" };
|
||||
final String Clrs[] = { "white", "blue", "black", "red", "green" };
|
||||
|
||||
for (int i = 0; i < Constant.Color.ONLY_COLORS.length; i++) {
|
||||
if (Clrs[i].equals(color))
|
||||
if (Clrs[i].equals(color)) {
|
||||
return Mana[i];
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
/** Forge Card Game */
|
||||
package forge.game.limited;
|
||||
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
/** Forge Card Game */
|
||||
/** Forge Card Game. */
|
||||
package forge.game;
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ public class DeckEditorDraft extends DeckEditorBase implements NewConstants, New
|
||||
ItemPoolView<CardPrinted> list = ItemPool.createFrom(bottom.getCards(), CardPrinted.class);
|
||||
deck.addSideboard(list);
|
||||
|
||||
String landSet = BoosterDraft.LandSetCode[0];
|
||||
String landSet = BoosterDraft.LAND_SET_CODE[0];
|
||||
final int LANDS_COUNT = 20;
|
||||
deck.addSideboard(CardDb.instance().getCard("Forest", landSet), LANDS_COUNT);
|
||||
deck.addSideboard(CardDb.instance().getCard("Mountain", landSet), LANDS_COUNT);
|
||||
|
||||
Reference in New Issue
Block a user