Added option to select time limit (also none) on match or tournament creation.

This commit is contained in:
LevelX2 2013-06-21 21:34:06 +02:00
parent a573d2c026
commit 738efcc47f
15 changed files with 367 additions and 214 deletions

View file

@ -0,0 +1,37 @@
package mage.constants;
/**
*
* @author LevelX2
*/
public enum MatchTimeLimit {
NONE(0,"None"),
MIN__20(1200, "20 Minutes"),
MIN__30(1800, "30 Minutes"),
MIN__40(2400, "40 Minutes"),
MIN__50(3000, "50 Minutes"),
MIN__60(3600, "60 Minutes"),
MIN__90(5400, "90 Minutes"),
MIN_120(7200, "120 Minutes");
private int matchSeconds;
private String name;
MatchTimeLimit(int matchSeconds, String name) {
this.matchSeconds = matchSeconds;
this.name = name;
}
public int getTimeLimit() {
return matchSeconds;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}

View file

@ -230,4 +230,6 @@ public interface Game extends MageItem, Serializable {
void initTimer(UUID playerId);
void resumeTimer(UUID playerId);
void pauseTimer(UUID playerId);
int getPriorityTime();
void setPriorityTime(int priorityTime);
}

View file

@ -155,6 +155,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
// used to indicate that currently applied replacement effects have to check for scope relevance (614.12 13/01/18)
private boolean scopeRelevant = false;
private int priorityTime;
@Override
public abstract T copy();
@ -198,6 +200,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
this.stateCheckRequired = game.stateCheckRequired;
this.scorePlayer = game.scorePlayer;
this.scopeRelevant = game.scopeRelevant;
this.priorityTime = game.priorityTime;
}
@Override
@ -589,7 +592,9 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
protected void init(UUID choosingPlayerId, GameOptions gameOptions) {
for (Player player: state.getPlayers().values()) {
player.beginTurn(this);
initTimer(player.getId());
if (priorityTime > 0) {
initTimer(player.getId());
}
}
if (startMessage == null || startMessage.isEmpty()) {
startMessage = "Game has started";
@ -1949,17 +1954,32 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
@Override
public void initTimer(UUID playerId) {
tableEventSource.fireTableEvent(EventType.INIT_TIMER, playerId, null, this);
if (priorityTime > 0) {
tableEventSource.fireTableEvent(EventType.INIT_TIMER, playerId, null, this);
}
}
@Override
public void resumeTimer(UUID playerId) {
tableEventSource.fireTableEvent(EventType.RESUME_TIMER, playerId, null, this);
if (priorityTime > 0) {
tableEventSource.fireTableEvent(EventType.RESUME_TIMER, playerId, null, this);
}
}
@Override
public void pauseTimer(UUID playerId) {
tableEventSource.fireTableEvent(EventType.PAUSE_TIMER, playerId, null, this);
if (priorityTime > 0) {
tableEventSource.fireTableEvent(EventType.PAUSE_TIMER, playerId, null, this);
}
}
@Override
public int getPriorityTime() {
return priorityTime;
}
@Override
public void setPriorityTime(int priorityTime) {
this.priorityTime = priorityTime;
}
}

View file

@ -162,6 +162,7 @@ public abstract class MatchImpl implements Match {
game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId());
game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck());
}
game.setPriorityTime(options.getPriorityTime());
}
protected void shufflePlayers() {

View file

@ -31,6 +31,7 @@ package mage.game.match;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
@ -49,6 +50,10 @@ public class MatchOptions implements Serializable {
protected String deckType;
protected boolean limited;
protected List<String> playerTypes = new ArrayList<String>();
/**
* Time each player has during the game to play using his\her priority.
*/
protected MatchTimeLimit matchTimeLimit; // 0 = no priorityTime handling
public MatchOptions(String name, String gameType) {
this.name = name;
@ -90,6 +95,7 @@ public class MatchOptions implements Serializable {
public void setFreeMulligans(int freeMulligans) {
this.freeMulligans = freeMulligans;
}
public String getGameType() {
return gameType;
}
@ -117,4 +123,13 @@ public class MatchOptions implements Serializable {
public void setLimited(boolean limited) {
this.limited = limited;
}
public int getPriorityTime() {
return matchTimeLimit.getTimeLimit();
}
public void setMatchTimeLimit(MatchTimeLimit matchTimeLimit) {
this.matchTimeLimit = matchTimeLimit;
}
}