mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
* Fixed some possible java exception causes.
This commit is contained in:
parent
b668209f7d
commit
c774e95335
5 changed files with 173 additions and 167 deletions
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
|
@ -43,6 +43,7 @@ import mage.game.Table;
|
||||||
import mage.game.tournament.TournamentPlayer;
|
import mage.game.tournament.TournamentPlayer;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.players.net.UserData;
|
import mage.players.net.UserData;
|
||||||
|
import mage.players.net.UserGroup;
|
||||||
import mage.server.draft.DraftSession;
|
import mage.server.draft.DraftSession;
|
||||||
import mage.server.game.GameManager;
|
import mage.server.game.GameManager;
|
||||||
import mage.server.game.GameSessionPlayer;
|
import mage.server.game.GameSessionPlayer;
|
||||||
|
@ -53,7 +54,6 @@ import mage.server.util.SystemUtil;
|
||||||
import mage.view.TableClientMessage;
|
import mage.view.TableClientMessage;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -63,12 +63,13 @@ public class User {
|
||||||
private static final Logger logger = Logger.getLogger(User.class);
|
private static final Logger logger = Logger.getLogger(User.class);
|
||||||
|
|
||||||
public enum UserState {
|
public enum UserState {
|
||||||
|
|
||||||
Created, Connected, Disconnected, Reconnected, Expired;
|
Created, Connected, Disconnected, Reconnected, Expired;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final UUID userId;
|
private final UUID userId;
|
||||||
private final String userName;
|
private final String userName;
|
||||||
private final String host;
|
private final String host;
|
||||||
private final Date connectionTime;
|
private final Date connectionTime;
|
||||||
private final Map<UUID, Table> tables;
|
private final Map<UUID, Table> tables;
|
||||||
private final ArrayList<UUID> tablesToDelete;
|
private final ArrayList<UUID> tablesToDelete;
|
||||||
|
@ -90,10 +91,10 @@ public class User {
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.userState = UserState.Created;
|
this.userState = UserState.Created;
|
||||||
|
|
||||||
this.connectionTime = new Date();
|
this.connectionTime = new Date();
|
||||||
this.lastActivity = new Date();
|
this.lastActivity = new Date();
|
||||||
|
|
||||||
this.tables = new ConcurrentHashMap<>();
|
this.tables = new ConcurrentHashMap<>();
|
||||||
this.gameSessions = new ConcurrentHashMap<>();
|
this.gameSessions = new ConcurrentHashMap<>();
|
||||||
this.draftSessions = new ConcurrentHashMap<>();
|
this.draftSessions = new ConcurrentHashMap<>();
|
||||||
|
@ -103,6 +104,8 @@ public class User {
|
||||||
this.watchedGames = new ArrayList<>();
|
this.watchedGames = new ArrayList<>();
|
||||||
this.tablesToDelete = new ArrayList<>();
|
this.tablesToDelete = new ArrayList<>();
|
||||||
this.sessionId = "";
|
this.sessionId = "";
|
||||||
|
// default these to avaiod NPE -> will be updated from client short after
|
||||||
|
this.userData = new UserData(UserGroup.PLAYER, 0, false, false, false, null, "world.png", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
@ -155,16 +158,16 @@ public class User {
|
||||||
long secondsDisconnected = getSecondsDisconnected();
|
long secondsDisconnected = getSecondsDisconnected();
|
||||||
long secondsLeft;
|
long secondsLeft;
|
||||||
String sign = "";
|
String sign = "";
|
||||||
if (secondsDisconnected > (3 * 60)) {
|
if (secondsDisconnected > (3 * 60)) {
|
||||||
sign="-";
|
sign = "-";
|
||||||
secondsLeft = secondsDisconnected - (3 *60);
|
secondsLeft = secondsDisconnected - (3 * 60);
|
||||||
} else {
|
} else {
|
||||||
secondsLeft = (3 * 60) - secondsDisconnected;
|
secondsLeft = (3 * 60) - secondsDisconnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
int minutes = (int) secondsLeft / 60;
|
int minutes = (int) secondsLeft / 60;
|
||||||
int seconds = (int) secondsLeft % 60;
|
int seconds = (int) secondsLeft % 60;
|
||||||
return new StringBuilder(sign).append(Integer.toString(minutes)).append(":").append(seconds > 9 ? seconds: "0" + Integer.toString(seconds)).toString();
|
return new StringBuilder(sign).append(Integer.toString(minutes)).append(":").append(seconds > 9 ? seconds : "0" + Integer.toString(seconds)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getSecondsDisconnected() {
|
public long getSecondsDisconnected() {
|
||||||
|
@ -217,11 +220,11 @@ public class User {
|
||||||
fireCallback(new ClientCallback("showGameEndDialog", gameId));
|
fireCallback(new ClientCallback("showGameEndDialog", gameId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showUserMessage(final String titel, String message) {
|
public void showUserMessage(final String titel, String message) {
|
||||||
List<String> messageData = new LinkedList<>();
|
List<String> messageData = new LinkedList<>();
|
||||||
messageData.add(titel);
|
messageData.add(titel);
|
||||||
messageData.add(message);
|
messageData.add(message);
|
||||||
fireCallback(new ClientCallback("showUserMessage", null, messageData ));
|
fireCallback(new ClientCallback("showUserMessage", null, messageData));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean ccWatchGame(final UUID gameId) {
|
public boolean ccWatchGame(final UUID gameId) {
|
||||||
|
@ -248,7 +251,7 @@ public class User {
|
||||||
GameManager.getInstance().sendPlayerManaType(gameId, playerId, userId, data);
|
GameManager.getInstance().sendPlayerManaType(gameId, playerId, userId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPlayerBoolean(final UUID gameId, final Boolean data) {
|
public void sendPlayerBoolean(final UUID gameId, final Boolean data) {
|
||||||
lastActivity = new Date();
|
lastActivity = new Date();
|
||||||
GameManager.getInstance().sendPlayerBoolean(gameId, userId, data);
|
GameManager.getInstance().sendPlayerBoolean(gameId, userId, data);
|
||||||
}
|
}
|
||||||
|
@ -275,14 +278,15 @@ public class User {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logger.trace(new StringBuilder("isExpired: User ").append(userName).append(" lastActivity: ").append(lastActivity).append(" expired: ").append(expired).toString());
|
logger.trace(new StringBuilder("isExpired: User ").append(userName).append(" lastActivity: ").append(lastActivity).append(" expired: ").append(expired).toString());
|
||||||
return false; /*userState == UserState.Disconnected && */
|
return false; /*userState == UserState.Disconnected && */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reconnect() {
|
private void reconnect() {
|
||||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
for (Entry<UUID, Table> entry : tables.entrySet()) {
|
||||||
ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
|
ccJoinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
|
||||||
}
|
}
|
||||||
for (Entry<UUID, UUID> entry: userTournaments.entrySet()) {
|
for (Entry<UUID, UUID> entry : userTournaments.entrySet()) {
|
||||||
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(entry.getValue());
|
TournamentController tournamentController = TournamentManager.getInstance().getTournamentController(entry.getValue());
|
||||||
if (tournamentController != null) {
|
if (tournamentController != null) {
|
||||||
ccTournamentStarted(entry.getValue(), entry.getKey());
|
ccTournamentStarted(entry.getValue(), entry.getKey());
|
||||||
|
@ -290,22 +294,22 @@ public class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<UUID, GameSessionPlayer> entry: gameSessions.entrySet()) {
|
for (Entry<UUID, GameSessionPlayer> entry : gameSessions.entrySet()) {
|
||||||
ccGameStarted(entry.getValue().getGameId(), entry.getKey());
|
ccGameStarted(entry.getValue().getGameId(), entry.getKey());
|
||||||
entry.getValue().init();
|
entry.getValue().init();
|
||||||
GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, "");
|
GameManager.getInstance().sendPlayerString(entry.getValue().getGameId(), userId, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
|
for (Entry<UUID, DraftSession> entry : draftSessions.entrySet()) {
|
||||||
ccDraftStarted(entry.getValue().getDraftId(), entry.getKey());
|
ccDraftStarted(entry.getValue().getDraftId(), entry.getKey());
|
||||||
entry.getValue().init();
|
entry.getValue().init();
|
||||||
entry.getValue().update();
|
entry.getValue().update();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Entry<UUID, TournamentSession> entry: constructing.entrySet()) {
|
for (Entry<UUID, TournamentSession> entry : constructing.entrySet()) {
|
||||||
entry.getValue().construct(0); // TODO: Check if this is correct
|
entry.getValue().construct(0); // TODO: Check if this is correct
|
||||||
}
|
}
|
||||||
for (Entry<UUID, Deck> entry: sideboarding.entrySet()) {
|
for (Entry<UUID, Deck> entry : sideboarding.entrySet()) {
|
||||||
TableController controller = TableManager.getInstance().getController(entry.getKey());
|
TableController controller = TableManager.getInstance().getController(entry.getKey());
|
||||||
ccSideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited());
|
ccSideboard(entry.getValue(), entry.getKey(), controller.getRemainingTime(), controller.getOptions().isLimited());
|
||||||
}
|
}
|
||||||
|
@ -355,32 +359,32 @@ public class User {
|
||||||
sideboarding.remove(tableId);
|
sideboarding.remove(tableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(DisconnectReason reason) {
|
public void remove(DisconnectReason reason) {
|
||||||
logger.trace("REMOVE " + getName() + " Draft sessions " + draftSessions.size());
|
logger.trace("REMOVE " + getName() + " Draft sessions " + draftSessions.size());
|
||||||
for (DraftSession draftSession: draftSessions.values()) {
|
for (DraftSession draftSession : draftSessions.values()) {
|
||||||
draftSession.setKilled();
|
draftSession.setKilled();
|
||||||
}
|
}
|
||||||
draftSessions.clear();
|
draftSessions.clear();
|
||||||
logger.trace("REMOVE " + getName() + " Tournament sessions " + userTournaments.size());
|
logger.trace("REMOVE " + getName() + " Tournament sessions " + userTournaments.size());
|
||||||
for (UUID tournamentId: userTournaments.values()) {
|
for (UUID tournamentId : userTournaments.values()) {
|
||||||
TournamentManager.getInstance().quit(tournamentId, getId());
|
TournamentManager.getInstance().quit(tournamentId, getId());
|
||||||
}
|
}
|
||||||
userTournaments.clear();
|
userTournaments.clear();
|
||||||
logger.trace("REMOVE " + getName() + " Tables " + tables.size());
|
logger.trace("REMOVE " + getName() + " Tables " + tables.size());
|
||||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
for (Entry<UUID, Table> entry : tables.entrySet()) {
|
||||||
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
logger.debug("-- leave tableId: " + entry.getValue().getId());
|
||||||
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
TableManager.getInstance().leaveTable(userId, entry.getValue().getId());
|
||||||
}
|
}
|
||||||
tables.clear();
|
tables.clear();
|
||||||
logger.trace("REMOVE " + getName() + " Game sessions: " + gameSessions.size() );
|
logger.trace("REMOVE " + getName() + " Game sessions: " + gameSessions.size());
|
||||||
for (GameSessionPlayer gameSessionPlayer: gameSessions.values()) {
|
for (GameSessionPlayer gameSessionPlayer : gameSessions.values()) {
|
||||||
logger.debug("-- kill game session of gameId: " + gameSessionPlayer.getGameId() );
|
logger.debug("-- kill game session of gameId: " + gameSessionPlayer.getGameId());
|
||||||
GameManager.getInstance().quitMatch(gameSessionPlayer.getGameId(), userId);
|
GameManager.getInstance().quitMatch(gameSessionPlayer.getGameId(), userId);
|
||||||
gameSessionPlayer.quitGame();
|
gameSessionPlayer.quitGame();
|
||||||
}
|
}
|
||||||
gameSessions.clear();
|
gameSessions.clear();
|
||||||
logger.trace("REMOVE " + getName() + " watched Games " + watchedGames.size());
|
logger.trace("REMOVE " + getName() + " watched Games " + watchedGames.size());
|
||||||
for (UUID gameId: watchedGames) {
|
for (UUID gameId : watchedGames) {
|
||||||
GameManager.getInstance().stopWatching(gameId, userId);
|
GameManager.getInstance().stopWatching(gameId, userId);
|
||||||
}
|
}
|
||||||
watchedGames.clear();
|
watchedGames.clear();
|
||||||
|
@ -428,7 +432,7 @@ public class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isConnected()) {
|
if (!isConnected()) {
|
||||||
tournamentPlayer.setDisconnectInfo(" (discon. "+ getDisconnectDuration() + ")");
|
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ")");
|
||||||
} else {
|
} else {
|
||||||
tournamentPlayer.setDisconnectInfo("");
|
tournamentPlayer.setDisconnectInfo("");
|
||||||
}
|
}
|
||||||
|
@ -460,7 +464,7 @@ public class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tablesToDelete.isEmpty()) {
|
if (!tablesToDelete.isEmpty()) {
|
||||||
for(UUID keyId: tablesToDelete) {
|
for (UUID keyId : tablesToDelete) {
|
||||||
removeTable(keyId);
|
removeTable(keyId);
|
||||||
}
|
}
|
||||||
tablesToDelete.clear();
|
tablesToDelete.clear();
|
||||||
|
@ -513,8 +517,8 @@ public class User {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
return pingInfo;
|
return pingInfo;
|
||||||
} else {
|
} else {
|
||||||
return " (discon. "+ getDisconnectDuration() + ")";
|
return " (discon. " + getDisconnectDuration() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* 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.server.game;
|
package mage.server.game;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -73,16 +72,16 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
|
|
||||||
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
private final ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public GamesRoomImpl() {
|
public GamesRoomImpl() {
|
||||||
updateExecutor.scheduleAtFixedRate(new Runnable() {
|
updateExecutor.scheduleAtFixedRate(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run() {
|
||||||
try {
|
try {
|
||||||
update();
|
update();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Games room update exception! " + ex.toString(), ex);
|
logger.fatal("Games room update exception! " + ex.toString(), ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, 2, 2, TimeUnit.SECONDS);
|
}, 2, 2, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
@ -97,12 +96,11 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
ArrayList<MatchView> matchList = new ArrayList<>();
|
ArrayList<MatchView> matchList = new ArrayList<>();
|
||||||
List<Table> allTables = new ArrayList<>(tables.values());
|
List<Table> allTables = new ArrayList<>(tables.values());
|
||||||
Collections.sort(allTables, new TableListSorter());
|
Collections.sort(allTables, new TableListSorter());
|
||||||
for (Table table: allTables) {
|
for (Table table : allTables) {
|
||||||
if (table.getState() != TableState.FINISHED) {
|
if (table.getState() != TableState.FINISHED) {
|
||||||
tableList.add(new TableView(table));
|
tableList.add(new TableView(table));
|
||||||
}
|
} else if (matchList.size() < 50) {
|
||||||
else if (matchList.size() < 50) {
|
if (table.isTournament()) {
|
||||||
if (table.isTournament()) {
|
|
||||||
matchList.add(new MatchView(table));
|
matchList.add(new MatchView(table));
|
||||||
} else {
|
} else {
|
||||||
matchList.add(new MatchView(table));
|
matchList.add(new MatchView(table));
|
||||||
|
@ -113,23 +111,23 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
TournamentManager.getInstance().removeTournament(table.getTournament().getId());
|
TournamentManager.getInstance().removeTournament(table.getTournament().getId());
|
||||||
}
|
}
|
||||||
this.removeTable(table.getId());
|
this.removeTable(table.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tableView = tableList;
|
tableView = tableList;
|
||||||
matchView = matchList;
|
matchView = matchList;
|
||||||
List<UsersView> users = new ArrayList<>();
|
List<UsersView> users = new ArrayList<>();
|
||||||
for (User user : UserManager.getInstance().getUsers()) {
|
for (User user : UserManager.getInstance().getUsers()) {
|
||||||
try {
|
try {
|
||||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), "[exception]", user.getPingInfo()));
|
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getInfo(), "[exception]", user.getPingInfo()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(users, new UserNameSorter());
|
Collections.sort(users, new UserNameSorter());
|
||||||
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
List<RoomUsersView> roomUserInfo = new ArrayList<>();
|
||||||
roomUserInfo.add(new RoomUsersView(users,
|
roomUserInfo.add(new RoomUsersView(users,
|
||||||
GameManager.getInstance().getNumberActiveGames(),
|
GameManager.getInstance().getNumberActiveGames(),
|
||||||
ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()),
|
ThreadExecutor.getInstance().getActiveThreads(ThreadExecutor.getInstance().getGameExecutor()),
|
||||||
ConfigSettings.getInstance().getMaxGameThreads()
|
ConfigSettings.getInstance().getMaxGameThreads()
|
||||||
|
@ -218,18 +216,19 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts the tables for table and match view of the client room
|
* Sorts the tables for table and match view of the client room
|
||||||
*
|
*
|
||||||
* @author LevelX2
|
* @author LevelX2
|
||||||
*/
|
*/
|
||||||
class TableListSorter implements Comparator<Table> {
|
class TableListSorter implements Comparator<Table> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(Table one, Table two) {
|
public int compare(Table one, Table two) {
|
||||||
if (!one.getState().equals(TableState.SIDEBOARDING) && !one.getState().equals(TableState.DUELING)) {
|
if (!one.getState().equals(TableState.SIDEBOARDING) && !one.getState().equals(TableState.DUELING)) {
|
||||||
if (one.getState().compareTo(two.getState()) != 0 ) {
|
if (one.getState().compareTo(two.getState()) != 0) {
|
||||||
return one.getState().compareTo(two.getState());
|
return one.getState().compareTo(two.getState());
|
||||||
}
|
}
|
||||||
} else if (!two.getState().equals(TableState.SIDEBOARDING) && !two.getState().equals(TableState.DUELING)) {
|
} else if (!two.getState().equals(TableState.SIDEBOARDING) && !two.getState().equals(TableState.DUELING)) {
|
||||||
if (one.getState().compareTo(two.getState()) != 0 ) {
|
if (one.getState().compareTo(two.getState()) != 0) {
|
||||||
return one.getState().compareTo(two.getState());
|
return one.getState().compareTo(two.getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -259,8 +258,9 @@ class TableListSorter implements Comparator<Table> {
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserNameSorter implements Comparator<UsersView> {
|
class UserNameSorter implements Comparator<UsersView> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(UsersView one, UsersView two) {
|
public int compare(UsersView one, UsersView two) {
|
||||||
return one.getUserName().compareToIgnoreCase(two.getUserName());
|
return one.getUserName().compareToIgnoreCase(two.getUserName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
|
@ -20,14 +20,14 @@
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* 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.abilities.effects;
|
package mage.abilities.effects;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
|
@ -42,7 +42,6 @@ import mage.game.stack.StackObject;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.target.TargetPermanent;
|
import mage.target.TargetPermanent;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -68,10 +67,10 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
|
||||||
public boolean checksEventType(GameEvent event, Game game) {
|
public boolean checksEventType(GameEvent event, Game game) {
|
||||||
return event.getType() == EventType.DAMAGE_PLAYER;
|
return event.getType() == EventType.DAMAGE_PLAYER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
DamageEvent damageEvent = (DamageEvent)event;
|
DamageEvent damageEvent = (DamageEvent) event;
|
||||||
UUID playerId = getSourceControllerId(event.getSourceId(), game);
|
UUID playerId = getSourceControllerId(event.getSourceId(), game);
|
||||||
if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) {
|
if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) {
|
||||||
Player target = game.getPlayer(event.getTargetId());
|
Player target = game.getPlayer(event.getTargetId());
|
||||||
|
@ -81,9 +80,11 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
|
||||||
if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
|
if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
|
||||||
redirectTarget = new TargetPermanent(filter);
|
redirectTarget = new TargetPermanent(filter);
|
||||||
if (numPlaneswalkers == 1) {
|
if (numPlaneswalkers == 1) {
|
||||||
redirectTarget.add(game.getBattlefield().getAllActivePermanents(filter, target.getId(), game).get(0).getId(), game);
|
List<Permanent> planeswalker = game.getBattlefield().getAllActivePermanents(filter, target.getId(), game);
|
||||||
}
|
if (!planeswalker.isEmpty()) {
|
||||||
else {
|
redirectTarget.add(planeswalker.get(0).getId(), game);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
player.choose(Outcome.Damage, redirectTarget, null, game);
|
player.choose(Outcome.Damage, redirectTarget, null, game);
|
||||||
}
|
}
|
||||||
if (!game.isSimulation()) {
|
if (!game.isSimulation()) {
|
||||||
|
|
|
@ -1,31 +1,30 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* 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.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -57,10 +56,10 @@ import mage.watchers.common.CommanderInfoWatcher;
|
||||||
public abstract class GameCommanderImpl extends GameImpl {
|
public abstract class GameCommanderImpl extends GameImpl {
|
||||||
|
|
||||||
static boolean CHECK_COMMANDER_DAMAGE = true;
|
static boolean CHECK_COMMANDER_DAMAGE = true;
|
||||||
|
|
||||||
private final Map<UUID, Cards> mulliganedCards = new HashMap<>();
|
private final Map<UUID, Cards> mulliganedCards = new HashMap<>();
|
||||||
// private final Set<CommanderInfoWatcher> commanderCombatWatcher = new HashSet<>();
|
// private final Set<CommanderInfoWatcher> commanderCombatWatcher = new HashSet<>();
|
||||||
|
|
||||||
protected boolean alsoHand; // replace commander going to hand
|
protected boolean alsoHand; // replace commander going to hand
|
||||||
protected boolean alsoLibrary; // replace commander going to library
|
protected boolean alsoLibrary; // replace commander going to library
|
||||||
protected boolean startingPlayerSkipsDraw = true;
|
protected boolean startingPlayerSkipsDraw = true;
|
||||||
|
@ -80,12 +79,12 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
protected void init(UUID choosingPlayerId) {
|
protected void init(UUID choosingPlayerId) {
|
||||||
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
|
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
|
||||||
//Move commander to command zone
|
//Move commander to command zone
|
||||||
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
|
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||||
Player player = getPlayer(playerId);
|
Player player = getPlayer(playerId);
|
||||||
if (player != null){
|
if (player != null) {
|
||||||
if (player.getSideboard().size() > 0){
|
if (player.getSideboard().size() > 0) {
|
||||||
Card commander = getCard((UUID)player.getSideboard().toArray()[0]);
|
Card commander = getCard((UUID) player.getSideboard().toArray()[0]);
|
||||||
if (commander != null) {
|
if (commander != null) {
|
||||||
player.setCommanderId(commander.getId());
|
player.setCommanderId(commander.getId());
|
||||||
commander.moveToZone(Zone.COMMAND, null, this, true);
|
commander.moveToZone(Zone.COMMAND, null, this, true);
|
||||||
commander.getAbilities().setControllerId(player.getId());
|
commander.getAbilities().setControllerId(player.getId());
|
||||||
|
@ -107,7 +106,6 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//20130711
|
//20130711
|
||||||
/*903.8. The Commander variant uses an alternate mulligan rule.
|
/*903.8. The Commander variant uses an alternate mulligan rule.
|
||||||
|
@ -123,12 +121,12 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
|
TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
|
||||||
target.setNotTarget(true);
|
target.setNotTarget(true);
|
||||||
target.setRequired(false);
|
target.setRequired(false);
|
||||||
if (player.choose(Outcome.Exile, player.getHand(), target, this)){
|
if (player.choose(Outcome.Exile, player.getHand(), target, this)) {
|
||||||
int numCards = target.getTargets().size();
|
int numCards = target.getTargets().size();
|
||||||
for(UUID uuid : target.getTargets()){
|
for (UUID uuid : target.getTargets()) {
|
||||||
Card card = player.getHand().get(uuid, this);
|
Card card = player.getHand().get(uuid, this);
|
||||||
if(card != null){
|
if (card != null) {
|
||||||
if(!mulliganedCards.containsKey(playerId)){
|
if (!mulliganedCards.containsKey(playerId)) {
|
||||||
mulliganedCards.put(playerId, new CardsImpl());
|
mulliganedCards.put(playerId, new CardsImpl());
|
||||||
}
|
}
|
||||||
card.moveToExile(null, "", null, this);
|
card.moveToExile(null, "", null, this);
|
||||||
|
@ -140,14 +138,15 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
if (freeMulligans > 0) {
|
if (freeMulligans > 0) {
|
||||||
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
|
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
|
||||||
int used = usedFreeMulligans.get(player.getId());
|
int used = usedFreeMulligans.get(player.getId());
|
||||||
if (used < freeMulligans ) {
|
if (used < freeMulligans) {
|
||||||
deduction = 0;
|
deduction = 0;
|
||||||
usedFreeMulligans.put(player.getId(), used+1);
|
usedFreeMulligans.put(player.getId(), used + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deduction = 0;{
|
deduction = 0;
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
usedFreeMulligans.put(player.getId(), 1);
|
usedFreeMulligans.put(player.getId(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,25 +154,25 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
fireInformEvent(new StringBuilder(player.getLogName())
|
fireInformEvent(new StringBuilder(player.getLogName())
|
||||||
.append(" mulligans ")
|
.append(" mulligans ")
|
||||||
.append(numCards)
|
.append(numCards)
|
||||||
.append(numCards == 1? " card":" cards")
|
.append(numCards == 1 ? " card" : " cards")
|
||||||
.append(deduction == 0 ? " for free and draws ":" down to ")
|
.append(deduction == 0 ? " for free and draws " : " down to ")
|
||||||
.append(Integer.toString(player.getHand().size()))
|
.append(Integer.toString(player.getHand().size()))
|
||||||
.append(player.getHand().size() <= 1? " card":" cards").toString());
|
.append(player.getHand().size() <= 1 ? " card" : " cards").toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endMulligan(UUID playerId){
|
public void endMulligan(UUID playerId) {
|
||||||
//return cards to
|
//return cards to
|
||||||
Player player = getPlayer(playerId);
|
Player player = getPlayer(playerId);
|
||||||
if(player != null && mulliganedCards.containsKey(playerId)){
|
if (player != null && mulliganedCards.containsKey(playerId)) {
|
||||||
for(Card card : mulliganedCards.get(playerId).getCards(this)){
|
for (Card card : mulliganedCards.get(playerId).getCards(this)) {
|
||||||
if(card != null){
|
if (card != null) {
|
||||||
card.moveToZone(Zone.LIBRARY, null, this, false);
|
card.moveToZone(Zone.LIBRARY, null, this, false);
|
||||||
card.setFaceDown(false, this);
|
card.setFaceDown(false, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(mulliganedCards.get(playerId).size() > 0){
|
if (mulliganedCards.get(playerId).size() > 0) {
|
||||||
player.shuffleLibrary(this);
|
player.shuffleLibrary(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,12 +185,15 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkStateBasedActions() {
|
protected boolean checkStateBasedActions() {
|
||||||
for (Player player: getPlayers().values()) {
|
for (Player player : getPlayers().values()) {
|
||||||
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId());
|
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId());
|
||||||
for(Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()){
|
if (damageWatcher == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
|
||||||
if (entrySet.getValue() > 20) {
|
if (entrySet.getValue() > 20) {
|
||||||
Player opponent = getPlayer(entrySet.getKey());
|
Player opponent = getPlayer(entrySet.getKey());
|
||||||
if (opponent != null && player.isInGame()){
|
if (opponent != null && player.isInGame()) {
|
||||||
opponent.lost(this);
|
opponent.lost(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -203,7 +205,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
@Override
|
@Override
|
||||||
public Set<UUID> getOpponents(UUID playerId) {
|
public Set<UUID> getOpponents(UUID playerId) {
|
||||||
Set<UUID> opponents = new HashSet<>();
|
Set<UUID> opponents = new HashSet<>();
|
||||||
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
|
for (UUID opponentId : this.getPlayer(playerId).getInRange()) {
|
||||||
if (!opponentId.equals(playerId)) {
|
if (!opponentId.equals(playerId)) {
|
||||||
opponents.add(opponentId);
|
opponents.add(opponentId);
|
||||||
}
|
}
|
||||||
|
@ -213,7 +215,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOpponent(Player player, UUID playerToCheck) {
|
public boolean isOpponent(Player player, UUID playerToCheck) {
|
||||||
return !player.getId().equals(playerToCheck);
|
return !player.getId().equals(playerToCheck);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAlsoHand(boolean alsoHand) {
|
public void setAlsoHand(boolean alsoHand) {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification, are
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
* permitted provided that the following conditions are met:
|
* permitted provided that the following conditions are met:
|
||||||
*
|
*
|
||||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
* conditions and the following disclaimer.
|
* conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
* provided with the distribution.
|
* provided with the distribution.
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* 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.
|
||||||
|
@ -43,15 +43,14 @@ import mage.watchers.Watcher;
|
||||||
|
|
||||||
/* 20130711
|
/* 20130711
|
||||||
*903.14a A player that’s been dealt 21 or more combat damage by the same commander
|
*903.14a A player that’s been dealt 21 or more combat damage by the same commander
|
||||||
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
|
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Plopman
|
* @author Plopman
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class CommanderInfoWatcher extends Watcher {
|
public class CommanderInfoWatcher extends Watcher {
|
||||||
|
|
||||||
public Map<UUID, Integer> damageToPlayer = new HashMap<>();
|
public final Map<UUID, Integer> damageToPlayer = new HashMap<>();
|
||||||
public boolean checkCommanderDamage;
|
public boolean checkCommanderDamage;
|
||||||
|
|
||||||
public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) {
|
public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) {
|
||||||
|
@ -59,7 +58,6 @@ public class CommanderInfoWatcher extends Watcher {
|
||||||
this.sourceId = commander;
|
this.sourceId = commander;
|
||||||
this.checkCommanderDamage = checkCommanderDamage;
|
this.checkCommanderDamage = checkCommanderDamage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CommanderInfoWatcher(final CommanderInfoWatcher watcher) {
|
public CommanderInfoWatcher(final CommanderInfoWatcher watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
|
@ -76,20 +74,21 @@ public class CommanderInfoWatcher extends Watcher {
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (checkCommanderDamage && event.getType() == EventType.DAMAGED_PLAYER && event instanceof DamagedPlayerEvent) {
|
if (checkCommanderDamage && event.getType() == EventType.DAMAGED_PLAYER && event instanceof DamagedPlayerEvent) {
|
||||||
if (sourceId.equals(event.getSourceId())) {
|
if (sourceId.equals(event.getSourceId())) {
|
||||||
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event;
|
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
|
||||||
if (damageEvent.isCombatDamage()) {
|
if (damageEvent.isCombatDamage()) {
|
||||||
UUID playerUUID = event.getTargetId();
|
UUID playerUUID = event.getTargetId();
|
||||||
Integer damage = damageToPlayer.get(playerUUID);
|
Integer damage = damageToPlayer.get(playerUUID);
|
||||||
if(damage == null){
|
if (damage == null) {
|
||||||
damage = 0;
|
damage = 0;
|
||||||
}
|
}
|
||||||
damage += damageEvent.getAmount();
|
damage += damageEvent.getAmount();
|
||||||
damageToPlayer.put(playerUUID, damage);
|
damageToPlayer.put(playerUUID, damage);
|
||||||
Player player = game.getPlayer(playerUUID);
|
Player player = game.getPlayer(playerUUID);
|
||||||
MageObject commander = game.getObject(sourceId);
|
MageObject commander = game.getObject(sourceId);
|
||||||
if (player != null && commander != null){
|
if (player != null && commander != null) {
|
||||||
if (!game.isSimulation())
|
if (!game.isSimulation()) {
|
||||||
game.informPlayers(commander.getLogName() + " did " + damage + " combat damage to " + player.getLogName() + " during the game.");
|
game.informPlayers(commander.getLogName() + " did " + damage + " combat damage to " + player.getLogName() + " during the game.");
|
||||||
|
}
|
||||||
this.addCardInfoToCommander(game);
|
this.addCardInfoToCommander(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,18 +108,18 @@ public class CommanderInfoWatcher extends Watcher {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append("<b>Commander</b>");
|
sb.append("<b>Commander</b>");
|
||||||
Integer castCount = (Integer)game.getState().getValue(sourceId + "_castCount");
|
Integer castCount = (Integer) game.getState().getValue(sourceId + "_castCount");
|
||||||
if (castCount != null) {
|
if (castCount != null) {
|
||||||
sb.append(" ").append(castCount).append(castCount == 1 ? " time":" times").append(" casted from the command zone.");
|
sb.append(" ").append(castCount).append(castCount == 1 ? " time" : " times").append(" casted from the command zone.");
|
||||||
}
|
}
|
||||||
this.addInfo(object, "Commander",sb.toString(), game);
|
this.addInfo(object, "Commander", sb.toString(), game);
|
||||||
|
|
||||||
if (checkCommanderDamage) {
|
if (checkCommanderDamage) {
|
||||||
for (Map.Entry<UUID, Integer> entry : damageToPlayer.entrySet()) {
|
for (Map.Entry<UUID, Integer> entry : damageToPlayer.entrySet()) {
|
||||||
Player damagedPlayer = game.getPlayer(entry.getKey());
|
Player damagedPlayer = game.getPlayer(entry.getKey());
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
sb.append("<b>Commander</b> did ").append(entry.getValue()).append(" combat damage to player ").append(damagedPlayer.getLogName()).append(".");
|
sb.append("<b>Commander</b> did ").append(entry.getValue()).append(" combat damage to player ").append(damagedPlayer.getLogName()).append(".");
|
||||||
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(),sb.toString(), game);
|
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(), sb.toString(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +134,6 @@ public class CommanderInfoWatcher extends Watcher {
|
||||||
|
|
||||||
public Map<UUID, Integer> getDamageToPlayer() {
|
public Map<UUID, Integer> getDamageToPlayer() {
|
||||||
return damageToPlayer;
|
return damageToPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue