mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Fixed some more possible exception bugs.
This commit is contained in:
parent
1ec61abb8e
commit
74c310de3e
4 changed files with 35 additions and 32 deletions
|
@ -4,17 +4,16 @@ import mage.game.Table;
|
||||||
import mage.game.Table.TableRecorder;
|
import mage.game.Table.TableRecorder;
|
||||||
import mage.game.result.ResultProtos.TableProto;
|
import mage.game.result.ResultProtos.TableProto;
|
||||||
import mage.server.UserManager;
|
import mage.server.UserManager;
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
public class TableRecorderImpl implements TableRecorder {
|
public class TableRecorderImpl implements TableRecorder {
|
||||||
|
|
||||||
private static TableRecorderImpl INSTANCE = new TableRecorderImpl();
|
private final static TableRecorderImpl INSTANCE = new TableRecorderImpl();
|
||||||
private static final Logger logger = Logger.getLogger(TableRecorderImpl.class);
|
|
||||||
|
|
||||||
public static TableRecorderImpl getInstance() {
|
public static TableRecorderImpl getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void record(Table table) {
|
public void record(Table table) {
|
||||||
TableProto proto = table.toProto();
|
TableProto proto = table.toProto();
|
||||||
TableRecordRepository.instance.add(new TableRecord(proto, proto.getEndTimeMs()));
|
TableRecordRepository.instance.add(new TableRecord(proto, proto.getEndTimeMs()));
|
||||||
|
|
|
@ -112,16 +112,18 @@ class StorageMatrixRestrictionEffect extends RestrictionEffect {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String choosenType = choiceImpl.getChoice();
|
String choosenType = choiceImpl.getChoice();
|
||||||
game.informPlayers(storageMatrix.getLogName() + ": " + player.getLogName() + " chose to untap " + choosenType);
|
if (choosenType != null) {
|
||||||
|
game.informPlayers(storageMatrix.getLogName() + ": " + player.getLogName() + " chose to untap " + choosenType);
|
||||||
|
|
||||||
if (choosenType.equals(CardType.ARTIFACT.toString())) {
|
if (choosenType.equals(CardType.ARTIFACT.toString())) {
|
||||||
type = CardType.ARTIFACT;
|
type = CardType.ARTIFACT;
|
||||||
} else if (choosenType.equals(CardType.LAND.toString())) {
|
} else if (choosenType.equals(CardType.LAND.toString())) {
|
||||||
type = CardType.LAND;
|
type = CardType.LAND;
|
||||||
} else {
|
} else {
|
||||||
type = CardType.CREATURE;
|
type = CardType.CREATURE;
|
||||||
|
}
|
||||||
|
applies = true;
|
||||||
}
|
}
|
||||||
applies = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,8 +108,10 @@ class SarkhanTheMadRevealAndDrawEffect extends OneShotEffect {
|
||||||
Card card = controller.getLibrary().getFromTop(game);
|
Card card = controller.getLibrary().getFromTop(game);
|
||||||
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
controller.moveCards(card, null, Zone.HAND, source, game);
|
controller.moveCards(card, Zone.HAND, source, game);
|
||||||
sourcePermanent.damage(card.getManaCost().convertedManaCost(), source.getSourceId(), game, false, false);
|
if (sourcePermanent != null) {
|
||||||
|
sourcePermanent.damage(card.getManaCost().convertedManaCost(), source.getSourceId(), game, false, false);
|
||||||
|
}
|
||||||
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
|
controller.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
* The views and conclusions contained in the software and documentation are those of the
|
* The views and conclusions contained in the software and documentation are those of the
|
||||||
* authors and should not be interpreted as representing official policies, either expressed
|
* authors and should not be interpreted as representing official policies, either expressed
|
||||||
* or implied, of BetaSteward_at_googlemail.com.
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -65,7 +64,8 @@ public class Table implements Serializable {
|
||||||
private TableRecorder recorder;
|
private TableRecorder recorder;
|
||||||
|
|
||||||
public interface TableRecorder {
|
public interface TableRecorder {
|
||||||
void record(Table table);
|
|
||||||
|
void record(Table table);
|
||||||
};
|
};
|
||||||
|
|
||||||
protected TableEventSource tableEventSource = new TableEventSource();
|
protected TableEventSource tableEventSource = new TableEventSource();
|
||||||
|
@ -74,14 +74,14 @@ public class Table implements Serializable {
|
||||||
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
|
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
|
||||||
this.tournament = tournament;
|
this.tournament = tournament;
|
||||||
this.isTournament = true;
|
this.isTournament = true;
|
||||||
setState(TableState.WAITING);
|
setState(TableState.WAITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Match match) {
|
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder, Match match) {
|
||||||
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
|
this(roomId, gameType, name, controllerName, validator, playerTypes, recorder);
|
||||||
this.match = match;
|
this.match = match;
|
||||||
this.isTournament = false;
|
this.isTournament = false;
|
||||||
setState(TableState.WAITING);
|
setState(TableState.WAITING);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder) {
|
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, TableRecorder recorder) {
|
||||||
|
@ -100,7 +100,7 @@ public class Table implements Serializable {
|
||||||
private void createSeats(List<String> playerTypes) {
|
private void createSeats(List<String> playerTypes) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
seats = new Seat[numSeats];
|
seats = new Seat[numSeats];
|
||||||
for(String playerType: playerTypes) {
|
for (String playerType : playerTypes) {
|
||||||
seats[i] = new Seat(playerType);
|
seats[i] = new Seat(playerType);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initGame() {
|
public void initGame() {
|
||||||
setState(TableState.DUELING);
|
setState(TableState.DUELING);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initTournament() {
|
public void initTournament() {
|
||||||
|
@ -124,7 +124,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void endTournament() {
|
public void endTournament() {
|
||||||
setState(TableState.FINISHED);
|
setState(TableState.FINISHED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initDraft() {
|
public void initDraft() {
|
||||||
|
@ -138,8 +138,8 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All activities of the table end
|
* All activities of the table end (only replay of games (if active) and
|
||||||
* (only replay of games (if active) and display tournament results)
|
* display tournament results)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void closeTable() {
|
public void closeTable() {
|
||||||
|
@ -151,7 +151,7 @@ public class Table implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Complete remove of the table, release all objects
|
* Complete remove of the table, release all objects
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
|
@ -190,7 +190,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isReady() {
|
private boolean isReady() {
|
||||||
for (int i = 0; i < numSeats; i++ ) {
|
for (int i = 0; i < numSeats; i++) {
|
||||||
if (seats[i].getPlayer() == null) {
|
if (seats[i].getPlayer() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Seat getNextAvailableSeat(String playerType) {
|
public Seat getNextAvailableSeat(String playerType) {
|
||||||
for (int i = 0; i < numSeats; i++ ) {
|
for (int i = 0; i < numSeats; i++) {
|
||||||
if (seats[i].getPlayer() == null && seats[i].getPlayerType().equals(playerType)) {
|
if (seats[i].getPlayer() == null && seats[i].getPlayerType().equals(playerType)) {
|
||||||
return seats[i];
|
return seats[i];
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allSeatsAreOccupied() {
|
public boolean allSeatsAreOccupied() {
|
||||||
for (int i = 0; i < numSeats; i++ ) {
|
for (int i = 0; i < numSeats; i++) {
|
||||||
if (seats[i].getPlayer() == null) {
|
if (seats[i].getPlayer() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ public class Table implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void leaveNotStartedTable(UUID playerId) {
|
public void leaveNotStartedTable(UUID playerId) {
|
||||||
for (int i = 0; i < numSeats; i++ ) {
|
for (int i = 0; i < numSeats; i++) {
|
||||||
Player player = seats[i].getPlayer();
|
Player player = seats[i].getPlayer();
|
||||||
if (player != null && player.getId().equals(playerId)) {
|
if (player != null && player.getId().equals(playerId)) {
|
||||||
seats[i].setPlayer(null);
|
seats[i].setPlayer(null);
|
||||||
|
@ -296,15 +296,15 @@ public class Table implements Serializable {
|
||||||
return tournament.getStartTime();
|
return tournament.getStartTime();
|
||||||
} else {
|
} else {
|
||||||
return match.getStartTime();
|
return match.getStartTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getEndTime() {
|
public Date getEndTime() {
|
||||||
if (isTournament) {
|
if (isTournament) {
|
||||||
return tournament.getEndTime();
|
return tournament.getEndTime();
|
||||||
} else {
|
} else {
|
||||||
return match.getEndTime();
|
return match.getEndTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableProto toProto() {
|
public TableProto toProto() {
|
||||||
|
|
Loading…
Reference in a new issue