* Added tournament options for adjustable construction time and free mulligans

* Added duel options for free mulligans
This commit is contained in:
LevelX2 2013-06-14 23:45:30 +02:00
parent fa5ddb23a2
commit 84df0f2c43
27 changed files with 558 additions and 402 deletions

View file

@ -137,6 +137,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
protected transient GameStates gameStates = new GameStates();
protected RangeOfInfluence range;
protected int freeMulligans;
protected Map<UUID, Integer> usedFreeMulligans = new LinkedHashMap<UUID, Integer>();
protected MultiplayerAttackOption attackOption;
protected GameOptions gameOptions;
protected String startMessage;
@ -156,9 +158,10 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
@Override
public abstract T copy();
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range) {
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
this.id = UUID.randomUUID();
this.range = range;
this.freeMulligans = freeMulligans;
this.attackOption = attackOption;
this.state = new GameState();
this.actions = new LinkedList<MageAction>();
@ -174,6 +177,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
this.startingPlayerId = game.startingPlayerId;
this.winnerId = game.winnerId;
this.range = game.range;
this.freeMulligans = game.freeMulligans;
this.attackOption = game.attackOption;
this.state = game.state.copy();
// Issue 350
@ -740,7 +744,18 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
@Override
public int mulliganDownTo(UUID playerId) {
Player player = getPlayer(playerId);
return player.getHand().size() -1;
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
if (used < freeMulligans ) {
deduction = 0;
}
} else {
deduction = 0;
}
}
return player.getHand().size() - deduction;
}
@ -751,8 +766,25 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
player.getLibrary().addAll(player.getHand().getCards(this), this);
player.getHand().clear();
player.shuffleLibrary(this);
fireInformEvent(player.getName() + " mulligans down to " + Integer.toString(numCards - 1) + " cards");
player.drawCards(numCards - 1, this);
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
if (used < freeMulligans ) {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(used+1));
}
} else {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(1));
}
}
fireInformEvent(new StringBuilder(player.getName())
.append(" mulligans")
.append(deduction == 0 ? " for free and draws ":" down to ")
.append(Integer.toString(numCards - deduction))
.append(numCards - deduction == 1? " card":" cards").toString());
player.drawCards(numCards - deduction, this);
}
@Override

View file

@ -64,6 +64,7 @@ public interface Match {
Game getGame();
List<Game> getGames();
int getWinsNeeded();
int getFreeMulligans();
int getNumGames();
boolean isDoneSideboarding();
UUID getChooser();

View file

@ -149,6 +149,11 @@ public abstract class MatchImpl implements Match {
return options.getWinsNeeded();
}
@Override
public int getFreeMulligans() {
return options.getFreeMulligans();
}
protected void initGame(Game game) throws GameException {
shufflePlayers();
for (MatchPlayer matchPlayer: this.players) {

View file

@ -44,6 +44,7 @@ public class MatchOptions implements Serializable {
protected MultiplayerAttackOption attackOption;
protected RangeOfInfluence range;
protected int winsNeeded;
protected int freeMulligans;
protected String gameType;
protected String deckType;
protected boolean limited;
@ -82,6 +83,13 @@ public class MatchOptions implements Serializable {
this.winsNeeded = winsNeeded;
}
public int getFreeMulligans() {
return freeMulligans;
}
public void setFreeMulligans(int freeMulligans) {
this.freeMulligans = freeMulligans;
}
public String getGameType() {
return gameType;
}

View file

@ -39,9 +39,18 @@ import java.util.List;
public class LimitedOptions implements Serializable {
protected List<String> sets = new ArrayList<String>();
protected int constructionTime;
public List<String> getSetCodes() {
return sets;
}
public int getConstructionTime() {
return constructionTime;
}
public void setConstructionTime(int constructionTime) {
this.constructionTime = constructionTime;
}
}

View file

@ -28,6 +28,8 @@
package mage.game.tournament;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.decks.Deck;
@ -37,8 +39,6 @@ import mage.game.match.Match;
import mage.players.Player;
import org.apache.log4j.Logger;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
*
@ -61,8 +61,6 @@ public abstract class TournamentImpl implements Tournament {
protected Date startTime;
protected Date endTime;
private static final int CONSTRUCT_TIME = 600;
public TournamentImpl(TournamentOptions options) {
this.options = options;
startTime = new Date();
@ -227,8 +225,9 @@ public abstract class TournamentImpl implements Tournament {
@Override
public boolean isDoneConstructing() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isDoneConstructing())
if (!player.isDoneConstructing()) {
return false;
}
}
return true;
}
@ -236,8 +235,9 @@ public abstract class TournamentImpl implements Tournament {
@Override
public boolean allJoined() {
for (TournamentPlayer player: this.players.values()) {
if (!player.isJoined())
if (!player.isJoined()) {
return false;
}
}
return true;
}
@ -254,8 +254,7 @@ public abstract class TournamentImpl implements Tournament {
@Override
public void fireConstructEvent(UUID playerId) {
TournamentPlayer player = players.get(playerId);
playerQueryEventSource.construct(playerId, "Construct", CONSTRUCT_TIME);
playerQueryEventSource.construct(playerId, "Construct", getOptions().getLimitedOptions().getConstructionTime());
}
public void construct() {

View file

@ -39,6 +39,7 @@ import mage.game.match.MatchOptions;
*/
public class TournamentOptions implements Serializable {
protected String name;
protected String tournamentType;
protected List<String> playerTypes = new ArrayList<String>();