mirror of
https://github.com/correl/mage.git
synced 2024-12-01 11:09:56 +00:00
Some tests and minor changes.
This commit is contained in:
parent
37cbc50a58
commit
78ac6688ea
11 changed files with 226 additions and 152 deletions
|
@ -92,7 +92,8 @@ public class PlayerView implements Serializable {
|
||||||
this.experience = player.getCounters().getCount(CounterType.EXPERIENCE);
|
this.experience = player.getCounters().getCount(CounterType.EXPERIENCE);
|
||||||
this.wins = player.getMatchPlayer().getWins();
|
this.wins = player.getMatchPlayer().getWins();
|
||||||
this.winsNeeded = player.getMatchPlayer().getWinsNeeded();
|
this.winsNeeded = player.getMatchPlayer().getWinsNeeded();
|
||||||
this.deckHashCode = player.getMatchPlayer().getDeck().getDeckHashCode();
|
// If match ended immediately before, deck can be set to null so check is necessarry here
|
||||||
|
this.deckHashCode = player.getMatchPlayer().getDeck() != null ? player.getMatchPlayer().getDeck().getDeckHashCode() : 0;
|
||||||
this.libraryCount = player.getLibrary().size();
|
this.libraryCount = player.getLibrary().size();
|
||||||
this.handCount = player.getHand().size();
|
this.handCount = player.getHand().size();
|
||||||
this.manaPool = new ManaPoolView(player.getManaPool());
|
this.manaPool = new ManaPoolView(player.getManaPool());
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class MageServerImpl implements MageServer {
|
||||||
String authToken = generateAuthToken();
|
String authToken = generateAuthToken();
|
||||||
activeAuthTokens.put(email, authToken);
|
activeAuthTokens.put(email, authToken);
|
||||||
String subject = "XMage Password Reset Auth Token";
|
String subject = "XMage Password Reset Auth Token";
|
||||||
String text = "Use this auth token to reset your password: " + authToken + "\n"
|
String text = "Use this auth token to reset " + authorizedUser.name + "'s password: " + authToken + "\n"
|
||||||
+ "It's valid until the next server restart.";
|
+ "It's valid until the next server restart.";
|
||||||
boolean success;
|
boolean success;
|
||||||
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
if (!ConfigSettings.getInstance().getMailUser().isEmpty()) {
|
||||||
|
|
|
@ -333,8 +333,7 @@ public class TableController {
|
||||||
if (player == null || player.hasQuit()) {
|
if (player == null || player.hasQuit()) {
|
||||||
return true; // so the construct panel closes after submit
|
return true; // so the construct panel closes after submit
|
||||||
}
|
}
|
||||||
} else {
|
} else if (table.getMatch() != null) {
|
||||||
if (table.getMatch() != null) {
|
|
||||||
MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
|
MatchPlayer mPlayer = table.getMatch().getPlayer(playerId);
|
||||||
if (mPlayer == null || mPlayer.hasQuit()) {
|
if (mPlayer == null || mPlayer.hasQuit()) {
|
||||||
return true; // so the construct panel closes after submit
|
return true; // so the construct panel closes after submit
|
||||||
|
@ -346,7 +345,6 @@ public class TableController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
if (table.getState() != TableState.SIDEBOARDING && table.getState() != TableState.CONSTRUCTING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -390,14 +388,12 @@ public class TableController {
|
||||||
} else {
|
} else {
|
||||||
logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId);
|
logger.fatal("Tournament == null table: " + table.getId() + " userId: " + userId);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (TableState.SIDEBOARDING.equals(table.getState())) {
|
||||||
if (TableState.SIDEBOARDING.equals(table.getState())) {
|
|
||||||
match.updateDeck(playerId, deck);
|
match.updateDeck(playerId, deck);
|
||||||
} else {
|
} else {
|
||||||
// deck was meanwhile submitted so the autoupdate can be ignored
|
// deck was meanwhile submitted so the autoupdate can be ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public boolean watchTable(UUID userId) {
|
public boolean watchTable(UUID userId) {
|
||||||
if (table.isTournament()) {
|
if (table.isTournament()) {
|
||||||
|
@ -591,7 +587,9 @@ public class TableController {
|
||||||
// log about game started
|
// log about game started
|
||||||
logger.info("GAME started " + match.getGame().getId() + " [" + match.getName() + "] " + creator + " - " + opponent.toString());
|
logger.info("GAME started " + match.getGame().getId() + " [" + match.getName() + "] " + creator + " - " + opponent.toString());
|
||||||
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
|
logger.debug("- matchId: " + match.getId() + " [" + match.getName() + "]");
|
||||||
|
if (match.getGame() != null) {
|
||||||
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
logger.debug("- chatId: " + GameManager.getInstance().getChatId(match.getGame().getId()));
|
||||||
|
}
|
||||||
LogServiceImpl.instance.log(LogKeys.KEY_GAME_STARTED, String.valueOf(userPlayerMap.size()), creator, opponent.toString());
|
LogServiceImpl.instance.log(LogKeys.KEY_GAME_STARTED, String.valueOf(userPlayerMap.size()), creator, opponent.toString());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Error starting game table: " + table.getId(), ex);
|
logger.fatal("Error starting game table: " + table.getId(), ex);
|
||||||
|
@ -896,15 +894,13 @@ public class TableController {
|
||||||
logger.debug("- Match table with no match:");
|
logger.debug("- Match table with no match:");
|
||||||
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
||||||
// return false;
|
// return false;
|
||||||
} else {
|
} else if (match.isDoneSideboarding() && match.getGame() == null) {
|
||||||
if (match.isDoneSideboarding() && match.getGame() == null) {
|
|
||||||
// no sideboarding and not active game -> match seems to hang (maybe the Draw bug)
|
// no sideboarding and not active game -> match seems to hang (maybe the Draw bug)
|
||||||
logger.debug("- Match with no active game and not in sideboard state:");
|
logger.debug("- Match with no active game and not in sideboard state:");
|
||||||
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
logger.debug("-- matchId:" + match.getId() + " [" + match.getName() + "]");
|
||||||
// return false;
|
// return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// check for active players
|
// check for active players
|
||||||
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
for (Map.Entry<UUID, UUID> userPlayerEntry : userPlayerMap.entrySet()) {
|
||||||
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
MatchPlayer matchPlayer = match.getPlayer(userPlayerEntry.getValue());
|
||||||
|
|
|
@ -40,7 +40,7 @@ import org.apache.log4j.Logger;
|
||||||
*/
|
*/
|
||||||
public class GameWorker<T> implements Callable {
|
public class GameWorker<T> implements Callable {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(GameWorker.class);
|
private static final Logger LOGGER = Logger.getLogger(GameWorker.class);
|
||||||
|
|
||||||
private final GameCallback gameController;
|
private final GameCallback gameController;
|
||||||
private final Game game;
|
private final Game game;
|
||||||
|
@ -55,18 +55,26 @@ public class GameWorker<T> implements Callable {
|
||||||
@Override
|
@Override
|
||||||
public Object call() {
|
public Object call() {
|
||||||
try {
|
try {
|
||||||
logger.debug("GAME WORKER started gameId " + game.getId());
|
LOGGER.debug("GAME WORKER started gameId " + game.getId());
|
||||||
Thread.currentThread().setName("GAME " + game.getId());
|
Thread.currentThread().setName("GAME " + game.getId());
|
||||||
game.start(choosingPlayerId);
|
game.start(choosingPlayerId);
|
||||||
game.fireUpdatePlayersEvent();
|
game.fireUpdatePlayersEvent();
|
||||||
gameController.gameResult(game.getWinner());
|
gameController.gameResult(game.getWinner());
|
||||||
game.cleanUp();
|
game.cleanUp();
|
||||||
} catch (MageException ex) {
|
} catch (MageException ex) {
|
||||||
logger.fatal("GameWorker mage error [" + game.getId() + "]" + ex, ex);
|
LOGGER.fatal("GameWorker mage error [" + game.getId() + "] " + ex, ex);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.fatal("GameWorker general exception [" + game.getId() + "]" + e.getMessage(), e);
|
LOGGER.fatal("GameWorker general exception [" + game.getId() + "] " + e.getMessage(), e);
|
||||||
|
if (e instanceof NullPointerException) {
|
||||||
|
if (e.getStackTrace() == null) {
|
||||||
|
LOGGER.info("Stack trace is null");
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Null-Pointer-Exception: Stack trace");
|
||||||
|
LOGGER.info(e.getStackTrace());
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (Error err) {
|
} catch (Error err) {
|
||||||
logger.fatal("GameWorker general error [" + game.getId() + "]" + err, err);
|
LOGGER.fatal("GameWorker general error [" + game.getId() + "] " + err, err);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,10 +52,10 @@ import mage.target.common.TargetControlledCreaturePermanent;
|
||||||
*/
|
*/
|
||||||
public class AllyEncampment extends CardImpl {
|
public class AllyEncampment extends CardImpl {
|
||||||
|
|
||||||
private static final FilterSpell filter = new FilterSpell("an Ally spell");
|
private static final FilterSpell FILTER = new FilterSpell("an Ally spell");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filter.add(new SubtypePredicate("Ally"));
|
FILTER.add(new SubtypePredicate("Ally"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public AllyEncampment(UUID ownerId) {
|
public AllyEncampment(UUID ownerId) {
|
||||||
|
@ -66,7 +66,7 @@ public class AllyEncampment extends CardImpl {
|
||||||
this.addAbility(new ColorlessManaAbility());
|
this.addAbility(new ColorlessManaAbility());
|
||||||
|
|
||||||
// {T} Add one mana of any color to your mana pool. Spend this mana only to cast an Ally spell.
|
// {T} Add one mana of any color to your mana pool. Spend this mana only to cast an Ally spell.
|
||||||
this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new ConditionalSpellManaBuilder(filter), true));
|
this.addAbility(new ConditionalAnyColorManaAbility(new TapSourceCost(), 1, new ConditionalSpellManaBuilder(FILTER), true));
|
||||||
|
|
||||||
// {1}, {T}, Sacrifice Ally Encampment: Return target Ally you control to its owner's hand.
|
// {1}, {T}, Sacrifice Ally Encampment: Return target Ally you control to its owner's hand.
|
||||||
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandTargetEffect(), new GenericManaCost(1));
|
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new ReturnToHandTargetEffect(), new GenericManaCost(1));
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.UUID;
|
||||||
import mage.MageInt;
|
import mage.MageInt;
|
||||||
import mage.abilities.TriggeredAbilityImpl;
|
import mage.abilities.TriggeredAbilityImpl;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
|
||||||
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
|
||||||
import mage.abilities.effects.common.CreateTokenEffect;
|
import mage.abilities.effects.common.CreateTokenEffect;
|
||||||
import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect;
|
import mage.abilities.effects.common.continuous.SetPowerToughnessSourceEffect;
|
||||||
|
@ -40,8 +39,7 @@ import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
import mage.constants.Zone;
|
import mage.constants.Zone;
|
||||||
import mage.filter.common.FilterControlledPermanent;
|
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||||
import mage.filter.predicate.mageobject.CardTypePredicate;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
import mage.game.events.GameEvent.EventType;
|
||||||
|
@ -125,13 +123,6 @@ class VoiceOfResurgenceTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
class VoiceOfResurgenceToken extends Token {
|
class VoiceOfResurgenceToken extends Token {
|
||||||
|
|
||||||
private static final FilterControlledPermanent filter = new FilterControlledPermanent("creatures you control");
|
|
||||||
private static final DynamicValue creaturesControlled = new PermanentsOnBattlefieldCount(filter);
|
|
||||||
|
|
||||||
static {
|
|
||||||
filter.add(new CardTypePredicate(CardType.CREATURE));
|
|
||||||
}
|
|
||||||
|
|
||||||
public VoiceOfResurgenceToken() {
|
public VoiceOfResurgenceToken() {
|
||||||
super("Elemental", "X/X green and white Elemental creature with with \"This creature's power and toughness are each equal to the number of creatures you control.");
|
super("Elemental", "X/X green and white Elemental creature with with \"This creature's power and toughness are each equal to the number of creatures you control.");
|
||||||
setOriginalExpansionSetCode("DGM");
|
setOriginalExpansionSetCode("DGM");
|
||||||
|
@ -143,6 +134,7 @@ class VoiceOfResurgenceToken extends Token {
|
||||||
power = new MageInt(0);
|
power = new MageInt(0);
|
||||||
toughness = new MageInt(0);
|
toughness = new MageInt(0);
|
||||||
|
|
||||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetPowerToughnessSourceEffect(creaturesControlled, Duration.EndOfGame)));
|
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SetPowerToughnessSourceEffect(
|
||||||
|
new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent()), Duration.EndOfGame)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
* permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
* conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* provided with the distribution.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* 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
|
||||||
|
* 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
|
||||||
|
* 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
|
||||||
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
* or implied, of BetaSteward_at_googlemail.com.
|
||||||
|
*/
|
||||||
|
package org.mage.test.cards.triggers.dies;
|
||||||
|
|
||||||
|
import mage.constants.PhaseStep;
|
||||||
|
import mage.constants.Zone;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.mage.test.serverside.base.CardTestPlayerBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public class VoiceOfResurgenceTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Voice of Resurgence creates it's token under owner's control upon death
|
||||||
|
* even when it is controlled by an opponent when it dies. Happened with
|
||||||
|
* Treachery.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testDiesTriggeredAbility() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
|
||||||
|
// Enchant creature
|
||||||
|
// When Treachery enters the battlefield, untap up to five lands.
|
||||||
|
// You control enchanted creature.
|
||||||
|
addCard(Zone.HAND, playerA, "Treachery"); // {3}{U}{U}
|
||||||
|
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);
|
||||||
|
// Whenever an opponent casts a spell during your turn or when Voice of Resurgence dies,
|
||||||
|
// put a green and white Elemental creature token onto the battlefield with "This creature's power and toughness are each equal to the number of creatures you control."
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Voice of Resurgence", 1); // 2/2
|
||||||
|
addCard(Zone.HAND, playerB, "Lightning Bolt");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Treachery", "Voice of Resurgence");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Lightning Bolt", "Voice of Resurgence");
|
||||||
|
|
||||||
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
|
||||||
|
assertGraveyardCount(playerA, "Treachery", 1);
|
||||||
|
assertGraveyardCount(playerB, "Voice of Resurgence", 1);
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Elemental", 1);
|
||||||
|
assertPowerToughness(playerA, "Elemental", 2, 2);
|
||||||
|
assertTappedCount("Island", true, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -51,7 +51,7 @@ public class BeginningOfUntapTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
case YOU:
|
case YOU:
|
||||||
boolean yours = event.getPlayerId().equals(this.controllerId);
|
boolean yours = event.getPlayerId().equals(this.controllerId);
|
||||||
if (yours) {
|
if (yours) {
|
||||||
if (getTargets().size() == 0) {
|
if (getTargets().isEmpty()) {
|
||||||
for (Effect effect : this.getEffects()) {
|
for (Effect effect : this.getEffects()) {
|
||||||
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
|
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ public class BeginningOfUntapTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
case NOT_YOU:
|
case NOT_YOU:
|
||||||
Player controller = game.getPlayer(this.getControllerId());
|
Player controller = game.getPlayer(this.getControllerId());
|
||||||
if (controller != null && controller.getInRange().contains(event.getPlayerId()) && !event.getPlayerId().equals(this.getControllerId())) {
|
if (controller != null && controller.getInRange().contains(event.getPlayerId()) && !event.getPlayerId().equals(this.getControllerId())) {
|
||||||
if (getTargets().size() == 0) {
|
if (getTargets().isEmpty()) {
|
||||||
for (Effect effect : this.getEffects()) {
|
for (Effect effect : this.getEffects()) {
|
||||||
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
|
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class DiscardEachPlayerEffect extends OneShotEffect {
|
||||||
HashMap<UUID, Cards> cardsToDiscard = new HashMap<>();
|
HashMap<UUID, Cards> cardsToDiscard = new HashMap<>();
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
// choose cards to discard
|
// choose cards to discard
|
||||||
for (UUID playerId : controller.getInRange()) {
|
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
switch (targetController) {
|
switch (targetController) {
|
||||||
|
|
|
@ -57,8 +57,7 @@ public class DiscardHandAllEffect extends OneShotEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player sourcePlayer = game.getPlayer(source.getControllerId());
|
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
|
||||||
for (UUID playerId : sourcePlayer.getInRange()) {
|
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Set<Card> cards = player.getHand().getCards(game);
|
Set<Card> cards = player.getHand().getCards(game);
|
||||||
|
|
|
@ -138,24 +138,24 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
private static final int ROLLBACK_TURNS_MAX = 4;
|
private static final int ROLLBACK_TURNS_MAX = 4;
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(GameImpl.class);
|
private static final Logger LOGGER = Logger.getLogger(GameImpl.class);
|
||||||
|
|
||||||
private static final FilterPermanent filterAura = new FilterPermanent();
|
private static final FilterPermanent FILTER_AURA = new FilterPermanent();
|
||||||
private static final FilterPermanent filterEquipment = new FilterPermanent();
|
private static final FilterPermanent FILTER_EQUIPMENT = new FilterPermanent();
|
||||||
private static final FilterPermanent filterFortification = new FilterPermanent();
|
private static final FilterPermanent FILTER_FORTIFICATION = new FilterPermanent();
|
||||||
private static final FilterPermanent filterLegendary = new FilterPermanent();
|
private static final FilterPermanent FILTER_LEGENDARY = new FilterPermanent();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
filterAura.add(new CardTypePredicate(CardType.ENCHANTMENT));
|
FILTER_AURA.add(new CardTypePredicate(CardType.ENCHANTMENT));
|
||||||
filterAura.add(new SubtypePredicate("Aura"));
|
FILTER_AURA.add(new SubtypePredicate("Aura"));
|
||||||
|
|
||||||
filterEquipment.add(new CardTypePredicate(CardType.ARTIFACT));
|
FILTER_EQUIPMENT.add(new CardTypePredicate(CardType.ARTIFACT));
|
||||||
filterEquipment.add(new SubtypePredicate("Equipment"));
|
FILTER_EQUIPMENT.add(new SubtypePredicate("Equipment"));
|
||||||
|
|
||||||
filterFortification.add(new CardTypePredicate(CardType.ARTIFACT));
|
FILTER_FORTIFICATION.add(new CardTypePredicate(CardType.ARTIFACT));
|
||||||
filterFortification.add(new SubtypePredicate("Fortification"));
|
FILTER_FORTIFICATION.add(new SubtypePredicate("Fortification"));
|
||||||
|
|
||||||
filterLegendary.add(new SupertypePredicate("Legendary"));
|
FILTER_LEGENDARY.add(new SupertypePredicate("Legendary"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Random rnd = new Random();
|
private static Random rnd = new Random();
|
||||||
|
@ -230,7 +230,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
public GameImpl(final GameImpl game) {
|
public GameImpl(final GameImpl game) {
|
||||||
long t1 = 0;
|
long t1 = 0;
|
||||||
if (logger.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
t1 = System.currentTimeMillis();
|
t1 = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
this.id = game.id;
|
this.id = game.id;
|
||||||
|
@ -248,7 +248,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
this.lkiExtended.putAll(game.lkiExtended);
|
this.lkiExtended.putAll(game.lkiExtended);
|
||||||
this.shortLivingLKI.putAll(game.shortLivingLKI);
|
this.shortLivingLKI.putAll(game.shortLivingLKI);
|
||||||
this.permanentsEntering.putAll(game.permanentsEntering);
|
this.permanentsEntering.putAll(game.permanentsEntering);
|
||||||
if (logger.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
copyCount++;
|
copyCount++;
|
||||||
copyTime += (System.currentTimeMillis() - t1);
|
copyTime += (System.currentTimeMillis() - t1);
|
||||||
}
|
}
|
||||||
|
@ -577,7 +577,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
boolean result = checkIfGameIsOver();
|
boolean result = checkIfGameIsOver();
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Game over for player Id: " + playerId + " gameId " + getId());
|
LOGGER.debug("Game over for player Id: " + playerId + " gameId " + getId());
|
||||||
leave(playerId);
|
leave(playerId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -599,15 +599,15 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) {
|
if (remainingPlayers <= 1 || numLosers >= state.getPlayers().size() - 1) {
|
||||||
end();
|
end();
|
||||||
if (remainingPlayers == 0 && logger.isDebugEnabled()) {
|
if (remainingPlayers == 0 && LOGGER.isDebugEnabled()) {
|
||||||
logger.debug("DRAW for gameId: " + getId());
|
LOGGER.debug("DRAW for gameId: " + getId());
|
||||||
for (Player player : state.getPlayers().values()) {
|
for (Player player : state.getPlayers().values()) {
|
||||||
logger.debug("-- " + player.getName() + " left: " + (player.hasLeft() ? "Y" : "N") + " lost: " + (player.hasLost() ? "Y" : "N"));
|
LOGGER.debug("-- " + player.getName() + " left: " + (player.hasLeft() ? "Y" : "N") + " lost: " + (player.hasLost() ? "Y" : "N"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Player player : state.getPlayers().values()) {
|
for (Player player : state.getPlayers().values()) {
|
||||||
if (!player.hasLeft() && !player.hasLost()) {
|
if (!player.hasLeft() && !player.hasLost()) {
|
||||||
logger.debug(new StringBuilder("Player ").append(player.getName()).append(" has won gameId: ").append(this.getId()));
|
LOGGER.debug(new StringBuilder("Player ").append(player.getName()).append(" has won gameId: ").append(this.getId()));
|
||||||
player.won(this);
|
player.won(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -643,8 +643,8 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
public int bookmarkState() {
|
public int bookmarkState() {
|
||||||
if (!simulation) {
|
if (!simulation) {
|
||||||
saveState(true);
|
saveState(true);
|
||||||
if (logger.isTraceEnabled()) {
|
if (LOGGER.isTraceEnabled()) {
|
||||||
logger.trace("Bookmarking state: " + gameStates.getSize());
|
LOGGER.trace("Bookmarking state: " + gameStates.getSize());
|
||||||
}
|
}
|
||||||
savedStates.push(gameStates.getSize() - 1);
|
savedStates.push(gameStates.getSize() - 1);
|
||||||
return savedStates.size();
|
return savedStates.size();
|
||||||
|
@ -772,7 +772,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
sb.append("]");
|
sb.append("]");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
logger.info(sb.toString());
|
LOGGER.info(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -926,7 +926,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
Player startingPlayer = state.getPlayer(startingPlayerId);
|
Player startingPlayer = state.getPlayer(startingPlayerId);
|
||||||
if (startingPlayer == null) {
|
if (startingPlayer == null) {
|
||||||
logger.debug("Starting player not found. playerId:" + startingPlayerId);
|
LOGGER.debug("Starting player not found. playerId:" + startingPlayerId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StringBuilder message = new StringBuilder(choosingPlayer.getLogName()).append(" chooses that ");
|
StringBuilder message = new StringBuilder(choosingPlayer.getLogName()).append(" chooses that ");
|
||||||
|
@ -1052,12 +1052,12 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
UUID winnerIdFound = null;
|
UUID winnerIdFound = null;
|
||||||
for (Player player : state.getPlayers().values()) {
|
for (Player player : state.getPlayers().values()) {
|
||||||
if (player.hasWon()) {
|
if (player.hasWon()) {
|
||||||
logger.debug(player.getName() + " has won gameId: " + getId());
|
LOGGER.debug(player.getName() + " has won gameId: " + getId());
|
||||||
winnerIdFound = player.getId();
|
winnerIdFound = player.getId();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!player.hasLost() && !player.hasLeft()) {
|
if (!player.hasLost() && !player.hasLeft()) {
|
||||||
logger.debug(player.getName() + " has not lost so he won gameId: " + this.getId());
|
LOGGER.debug(player.getName() + " has not lost so he won gameId: " + this.getId());
|
||||||
player.won(this);
|
player.won(this);
|
||||||
winnerIdFound = player.getId();
|
winnerIdFound = player.getId();
|
||||||
break;
|
break;
|
||||||
|
@ -1089,7 +1089,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
return player.getId();
|
return player.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logger.debug("Game was not possible to pick a choosing player. GameId:" + getId());
|
LOGGER.debug("Game was not possible to pick a choosing player. GameId:" + getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,7 +1106,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public void end() {
|
public void end() {
|
||||||
if (!state.isGameOver()) {
|
if (!state.isGameOver()) {
|
||||||
logger.debug("END of gameId: " + this.getId());
|
LOGGER.debug("END of gameId: " + this.getId());
|
||||||
endTime = new Date();
|
endTime = new Date();
|
||||||
state.endGame();
|
state.endGame();
|
||||||
for (Player player : state.getPlayers().values()) {
|
for (Player player : state.getPlayers().values()) {
|
||||||
|
@ -1175,7 +1175,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.timerTimeout(this);
|
player.timerTimeout(this);
|
||||||
} else {
|
} else {
|
||||||
logger.error(new StringBuilder("timerTimeout - player not found - playerId: ").append(playerId));
|
LOGGER.error(new StringBuilder("timerTimeout - player not found - playerId: ").append(playerId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1185,7 +1185,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.idleTimeout(this);
|
player.idleTimeout(this);
|
||||||
} else {
|
} else {
|
||||||
logger.error(new StringBuilder("idleTimeout - player not found - playerId: ").append(playerId));
|
LOGGER.error(new StringBuilder("idleTimeout - player not found - playerId: ").append(playerId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1193,7 +1193,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
public synchronized void concede(UUID playerId) {
|
public synchronized void concede(UUID playerId) {
|
||||||
Player player = state.getPlayer(playerId);
|
Player player = state.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
logger.debug("Player " + player.getName() + " concedes game " + this.getId());
|
LOGGER.debug("Player " + player.getName() + " concedes game " + this.getId());
|
||||||
fireInformEvent(player.getLogName() + " has conceded.");
|
fireInformEvent(player.getLogName() + " has conceded.");
|
||||||
player.concede(this);
|
player.concede(this);
|
||||||
}
|
}
|
||||||
|
@ -1306,7 +1306,11 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Game exception gameId: " + getId(), ex);
|
LOGGER.fatal("Game exception gameId: " + getId(), ex);
|
||||||
|
if ((ex instanceof NullPointerException)
|
||||||
|
&& errorContinueCounter == 1 && ex.getStackTrace() != null) {
|
||||||
|
LOGGER.fatal(ex.getStackTrace());
|
||||||
|
}
|
||||||
this.fireErrorEvent("Game exception occurred: ", ex);
|
this.fireErrorEvent("Game exception occurred: ", ex);
|
||||||
restoreState(bookmark, "");
|
restoreState(bookmark, "");
|
||||||
bookmark = 0;
|
bookmark = 0;
|
||||||
|
@ -1325,7 +1329,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.fatal("Game exception ", ex);
|
LOGGER.fatal("Game exception ", ex);
|
||||||
this.fireErrorEvent("Game exception occurred: ", ex);
|
this.fireErrorEvent("Game exception occurred: ", ex);
|
||||||
this.end();
|
this.end();
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -1709,7 +1713,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if (perm.getSupertype().contains("World")) {
|
if (perm.getSupertype().contains("World")) {
|
||||||
worldEnchantment.add(perm);
|
worldEnchantment.add(perm);
|
||||||
}
|
}
|
||||||
if (filterAura.match(perm, this)) {
|
if (FILTER_AURA.match(perm, this)) {
|
||||||
//20091005 - 704.5n, 702.14c
|
//20091005 - 704.5n, 702.14c
|
||||||
if (perm.getAttachedTo() == null) {
|
if (perm.getAttachedTo() == null) {
|
||||||
Card card = this.getCard(perm.getId());
|
Card card = this.getCard(perm.getId());
|
||||||
|
@ -1732,7 +1736,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
if (spellAbility.getTargets().isEmpty()) {
|
if (spellAbility.getTargets().isEmpty()) {
|
||||||
Permanent enchanted = this.getPermanent(perm.getAttachedTo());
|
Permanent enchanted = this.getPermanent(perm.getAttachedTo());
|
||||||
logger.error("Aura without target: " + perm.getName() + " attached to " + (enchanted == null ? " null" : enchanted.getName()));
|
LOGGER.error("Aura without target: " + perm.getName() + " attached to " + (enchanted == null ? " null" : enchanted.getName()));
|
||||||
} else {
|
} else {
|
||||||
Target target = spellAbility.getTargets().get(0);
|
Target target = spellAbility.getTargets().get(0);
|
||||||
if (target instanceof TargetPermanent) {
|
if (target instanceof TargetPermanent) {
|
||||||
|
@ -1744,11 +1748,9 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
UUID wasAttachedTo = perm.getAttachedTo();
|
UUID wasAttachedTo = perm.getAttachedTo();
|
||||||
perm.attachTo(null, this);
|
perm.attachTo(null, this);
|
||||||
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||||
} else {
|
} else if (movePermanentToGraveyardWithInfo(perm)) {
|
||||||
if (movePermanentToGraveyardWithInfo(perm)) {
|
|
||||||
somethingHappened = true;
|
somethingHappened = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Filter auraFilter = spellAbility.getTargets().get(0).getFilter();
|
Filter auraFilter = spellAbility.getTargets().get(0).getFilter();
|
||||||
if (auraFilter instanceof FilterControlledCreaturePermanent) {
|
if (auraFilter instanceof FilterControlledCreaturePermanent) {
|
||||||
|
@ -1758,22 +1760,18 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
somethingHappened = true;
|
somethingHappened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeEnchantedBy(perm, this)) {
|
||||||
if (!auraFilter.match(attachedTo, this) || attachedTo.cantBeEnchantedBy(perm, this)) {
|
|
||||||
// handle bestow unattachment
|
// handle bestow unattachment
|
||||||
Card card = this.getCard(perm.getId());
|
Card card = this.getCard(perm.getId());
|
||||||
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
|
if (card != null && card.getCardType().contains(CardType.CREATURE)) {
|
||||||
UUID wasAttachedTo = perm.getAttachedTo();
|
UUID wasAttachedTo = perm.getAttachedTo();
|
||||||
perm.attachTo(null, this);
|
perm.attachTo(null, this);
|
||||||
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
fireEvent(new GameEvent(GameEvent.EventType.UNATTACHED, wasAttachedTo, perm.getId(), perm.getControllerId()));
|
||||||
} else {
|
} else if (movePermanentToGraveyardWithInfo(perm)) {
|
||||||
if (movePermanentToGraveyardWithInfo(perm)) {
|
|
||||||
somethingHappened = true;
|
somethingHappened = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (target instanceof TargetPlayer) {
|
} else if (target instanceof TargetPlayer) {
|
||||||
Player attachedToPlayer = getPlayer(perm.getAttachedTo());
|
Player attachedToPlayer = getPlayer(perm.getAttachedTo());
|
||||||
if (attachedToPlayer == null) {
|
if (attachedToPlayer == null) {
|
||||||
|
@ -1792,10 +1790,10 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.getState().isLegendaryRuleActive() && filterLegendary.match(perm, this)) {
|
if (this.getState().isLegendaryRuleActive() && FILTER_LEGENDARY.match(perm, this)) {
|
||||||
legendary.add(perm);
|
legendary.add(perm);
|
||||||
}
|
}
|
||||||
if (filterEquipment.match(perm, this)) {
|
if (FILTER_EQUIPMENT.match(perm, this)) {
|
||||||
//20091005 - 704.5p, 702.14d
|
//20091005 - 704.5p, 702.14d
|
||||||
if (perm.getAttachedTo() != null) {
|
if (perm.getAttachedTo() != null) {
|
||||||
Permanent creature = getPermanent(perm.getAttachedTo());
|
Permanent creature = getPermanent(perm.getAttachedTo());
|
||||||
|
@ -1810,7 +1808,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (filterFortification.match(perm, this)) {
|
if (FILTER_FORTIFICATION.match(perm, this)) {
|
||||||
if (perm.getAttachedTo() != null) {
|
if (perm.getAttachedTo() != null) {
|
||||||
Permanent land = getPermanent(perm.getAttachedTo());
|
Permanent land = getPermanent(perm.getAttachedTo());
|
||||||
if (land == null || !land.getAttachments().contains(perm.getId())) {
|
if (land == null || !land.getAttachments().contains(perm.getId())) {
|
||||||
|
@ -2093,7 +2091,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void debugMessage(String message) {
|
public void debugMessage(String message) {
|
||||||
logger.warn(message);
|
LOGGER.warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2117,7 +2115,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.trace("fireUpdatePlayersEvent");
|
LOGGER.trace("fireUpdatePlayersEvent");
|
||||||
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
|
tableEventSource.fireTableEvent(EventType.UPDATE, null, this);
|
||||||
getState().clearLookedAt();
|
getState().clearLookedAt();
|
||||||
getState().clearRevealed();
|
getState().clearRevealed();
|
||||||
|
@ -2128,7 +2126,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if (simulation) {
|
if (simulation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.trace("fireGameEndIfo");
|
LOGGER.trace("fireGameEndIfo");
|
||||||
tableEventSource.fireTableEvent(EventType.END_GAME_INFO, null, this);
|
tableEventSource.fireTableEvent(EventType.END_GAME_INFO, null, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2214,10 +2212,10 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
Player player = getPlayer(playerId);
|
Player player = getPlayer(playerId);
|
||||||
if (player == null || player.hasLeft()) {
|
if (player == null || player.hasLeft()) {
|
||||||
logger.debug("Player already left " + (player != null ? player.getName() : playerId));
|
LOGGER.debug("Player already left " + (player != null ? player.getName() : playerId));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("Start leave game: " + player.getName());
|
LOGGER.debug("Start leave game: " + player.getName());
|
||||||
player.leave();
|
player.leave();
|
||||||
if (checkIfGameIsOver()) {
|
if (checkIfGameIsOver()) {
|
||||||
// no need to remove objects if only one player is left so the game is over
|
// no need to remove objects if only one player is left so the game is over
|
||||||
|
@ -2532,9 +2530,9 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
try {
|
try {
|
||||||
Integer amount = Integer.parseInt(s[1]);
|
Integer amount = Integer.parseInt(s[1]);
|
||||||
player.setLife(amount, this);
|
player.setLife(amount, this);
|
||||||
logger.info("Setting player's life: ");
|
LOGGER.info("Setting player's life: ");
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
logger.fatal("error setting life", e);
|
LOGGER.fatal("error setting life", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue