Fixed typos in tests and additional refactor

This commit is contained in:
Oleg Agafonov 2020-08-29 19:04:26 +04:00
parent 4d8369afbc
commit ede06098e0
7 changed files with 652 additions and 648 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,17 +1,11 @@
package mage.server; package mage.server;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.MageException; import mage.MageException;
import mage.constants.Constants; import mage.constants.Constants;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.interfaces.callback.ClientCallbackMethod; import mage.interfaces.callback.ClientCallbackMethod;
import mage.players.net.UserData; import mage.players.net.UserData;
import mage.players.net.UserGroup; import mage.players.net.UserGroup;
import static mage.server.DisconnectReason.LostConnection;
import mage.server.game.GamesRoom; import mage.server.game.GamesRoom;
import mage.server.game.GamesRoomManager; import mage.server.game.GamesRoomManager;
import mage.server.util.ConfigSettings; import mage.server.util.ConfigSettings;
@ -23,6 +17,14 @@ import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException; import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler; import org.jboss.remoting.callback.InvokerCallbackHandler;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static mage.server.DisconnectReason.LostConnection;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -201,9 +203,11 @@ public class Session {
} }
} }
} }
Optional<User> selectUser = UserManager.instance.createUser(userName, host, authorizedUser); Optional<User> selectUser = UserManager.instance.createUser(userName, host, authorizedUser);
boolean reconnect = false; boolean reconnect = false;
if (!selectUser.isPresent()) { // user already exists if (!selectUser.isPresent()) {
// user already connected
selectUser = UserManager.instance.getUserByName(userName); selectUser = UserManager.instance.getUserByName(userName);
if (selectUser.isPresent()) { if (selectUser.isPresent()) {
User user = selectUser.get(); User user = selectUser.get();
@ -222,6 +226,9 @@ public class Session {
} else { } else {
return "User name " + userName + " already in use (or your IP address changed)"; return "User name " + userName + " already in use (or your IP address changed)";
} }
} else {
// code never goes here
return "Can't find connected user name " + userName;
} }
} }
User user = selectUser.get(); User user = selectUser.get();
@ -240,7 +247,6 @@ public class Session {
} }
return null; return null;
} }
public void connectAdmin() { public void connectAdmin() {

View file

@ -1,17 +1,5 @@
package mage.server; package mage.server;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import mage.MageException; import mage.MageException;
import mage.cards.decks.DeckCardLists; import mage.cards.decks.DeckCardLists;
import mage.constants.TableState; import mage.constants.TableState;
@ -31,6 +19,18 @@ import mage.server.game.GamesRoomManager;
import mage.server.util.ThreadExecutor; import mage.server.util.ThreadExecutor;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -244,7 +244,7 @@ public enum TableManager {
/** /**
* Starts the Match from a non tournament table * Starts the Match from a non tournament table
* *
* @param userId table owner * @param userId table owner
* @param roomId * @param roomId
* @param tableId * @param tableId
*/ */
@ -415,7 +415,7 @@ public enum TableManager {
if (table.getState() != TableState.FINISHED if (table.getState() != TableState.FINISHED
&& ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // removeUserFromAllTablesAndChat only if table started longer than 30 seconds ago && ((System.currentTimeMillis() - table.getStartTime().getTime()) / 1000) > 30) { // removeUserFromAllTablesAndChat only if table started longer than 30 seconds ago
// removeUserFromAllTablesAndChat tables and games not valid anymore // removeUserFromAllTablesAndChat tables and games not valid anymore
logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() == null ? table.getCreateTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : "")); logger.debug(table.getId() + " [" + table.getName() + "] " + formatter.format(table.getStartTime() != null ? table.getStartTime() : table.getCreateTime()) + " (" + table.getState().toString() + ") " + (table.isTournament() ? "- Tournament" : ""));
getController(table.getId()).ifPresent(tableController -> { getController(table.getId()).ifPresent(tableController -> {
if ((table.isTournament() && !tableController.isTournamentStillValid()) if ((table.isTournament() && !tableController.isTournamentStillValid())
|| (!table.isTournament() && !tableController.isMatchTableStillValid())) { || (!table.isTournament() && !tableController.isMatchTableStillValid())) {

View file

@ -1,9 +1,5 @@
package mage.cards.v; package mage.cards.v;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
@ -17,8 +13,11 @@ import mage.game.Game;
import mage.players.Library; import mage.players.Library;
import mage.players.Player; import mage.players.Player;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.UUID;
/** /**
*
* @author noahg * @author noahg
*/ */
public final class VigeanIntuition extends CardImpl { public final class VigeanIntuition extends CardImpl {
@ -74,48 +73,55 @@ class VigeanIntuitionEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId()); MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (sourceObject == null || player == null) {
return false;
}
Library library = player.getLibrary(); Library library = player.getLibrary();
if (player != null && sourceObject != null && library != null) { if (library == null) {
Choice choiceImpl = new ChoiceImpl(); return false;
choiceImpl.setChoices(choice); }
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
CardType type = null;
String choosenType = choiceImpl.getChoice();
if (choosenType.equals(CardType.ARTIFACT.toString())) { Choice choiceImpl = new ChoiceImpl();
type = CardType.ARTIFACT; choiceImpl.setChoices(choice);
} else if (choosenType.equals(CardType.LAND.toString())) { if (player.choose(Outcome.Neutral, choiceImpl, game)) {
type = CardType.LAND; String choosenType = choiceImpl.getChoice();
} else if (choosenType.equals(CardType.CREATURE.toString())) { if (choosenType == null || choosenType.isEmpty()) {
type = CardType.CREATURE; return false;
} else if (choosenType.equals(CardType.ENCHANTMENT.toString())) { }
type = CardType.ENCHANTMENT; CardType type = null;
} else if (choosenType.equals(CardType.INSTANT.toString())) { if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.INSTANT; type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.SORCERY.toString())) { } else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.SORCERY; type = CardType.LAND;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) { } else if (choosenType.equals(CardType.CREATURE.toString())) {
type = CardType.PLANESWALKER; type = CardType.CREATURE;
} else if (choosenType.equals(CardType.TRIBAL.toString())) { } else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
type = CardType.TRIBAL; type = CardType.ENCHANTMENT;
} } else if (choosenType.equals(CardType.INSTANT.toString())) {
type = CardType.INSTANT;
} else if (choosenType.equals(CardType.SORCERY.toString())) {
type = CardType.SORCERY;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
type = CardType.PLANESWALKER;
} else if (choosenType.equals(CardType.TRIBAL.toString())) {
type = CardType.TRIBAL;
}
if (type != null) { if (type != null) {
Set<Card> top = library.getTopCards(game, 4); Set<Card> top = library.getTopCards(game, 4);
player.revealCards(source, new CardsImpl(top), game); player.revealCards(source, new CardsImpl(top), game);
Cards putInHand = new CardsImpl(); Cards putInHand = new CardsImpl();
Cards putInGraveyard = new CardsImpl(); Cards putInGraveyard = new CardsImpl();
for (Card card : top) { for (Card card : top) {
if (card != null && card.getCardType().contains(type)) { if (card != null && card.getCardType().contains(type)) {
putInHand.add(card); putInHand.add(card);
} else { } else {
putInGraveyard.add(card); putInGraveyard.add(card);
}
} }
player.moveCards(putInHand, Zone.HAND, source, game);
player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
return true;
} }
player.moveCards(putInHand, Zone.HAND, source, game);
player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
return true;
} }
} }
return false; return false;

View file

@ -30,7 +30,7 @@ public class PaintersServantTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerB, "Lightning Bolt"); addCard(Zone.HAND, playerB, "Lightning Bolt");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Painter's Servant"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Painter's Servant");
setChoice(playerA, "Blue"); setChoice(playerA, "Blue");

View file

@ -1,4 +1,3 @@
package org.mage.test.cards.continuous; package org.mage.test.cards.continuous;
import mage.cards.Card; import mage.cards.Card;
@ -11,7 +10,6 @@ import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase; import org.mage.test.serverside.base.CardTestPlayerBase;
/** /**
*
* @author LevelX2 * @author LevelX2
*/ */
public class SubTypeChangingEffectsTest extends CardTestPlayerBase { public class SubTypeChangingEffectsTest extends CardTestPlayerBase {
@ -29,7 +27,7 @@ public class SubTypeChangingEffectsTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerB, "Silvercoat Lion"); addCard(Zone.HAND, playerB, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Conspiracy"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Conspiracy");
setChoice(playerA, "Orc"); setChoice(playerA, "Orc");
@ -105,7 +103,7 @@ public class SubTypeChangingEffectsTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerB, "Silvercoat Lion"); addCard(Zone.HAND, playerB, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Conspiracy"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Conspiracy");
setChoice(playerA, "Orc"); setChoice(playerA, "Orc");
@ -159,7 +157,7 @@ public class SubTypeChangingEffectsTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerB, "Silvercoat Lion"); addCard(Zone.HAND, playerB, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arcane Adaptation"); castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Arcane Adaptation");
setChoice(playerA, "Orc"); setChoice(playerA, "Orc");
@ -246,7 +244,7 @@ public class SubTypeChangingEffectsTest extends CardTestPlayerBase {
addCard(Zone.HAND, playerB, "Silvercoat Lion"); addCard(Zone.HAND, playerB, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion");
addCard(Zone.GRAVEYARD, playerA, "Silvercoat Lion"); addCard(Zone.GRAVEYARD, playerB, "Silvercoat Lion");
castSpell(1, PhaseStep.UPKEEP, playerA, "Advent of the Wurm"); castSpell(1, PhaseStep.UPKEEP, playerA, "Advent of the Wurm");

View file

@ -51,7 +51,6 @@ public class BecomesCreatureTypeTargetEffect extends ContinuousEffectImpl {
super(effect); super(effect);
this.subtypes.addAll(effect.subtypes); this.subtypes.addAll(effect.subtypes);
this.loseOther = effect.loseOther; this.loseOther = effect.loseOther;
this.loseOther = effect.loseOther;
} }
@Override @Override