Code cleanup

This commit is contained in:
Oleg Agafonov 2020-01-08 05:18:21 +04:00
parent ca4a4528fb
commit 85e65c8f44
10 changed files with 42 additions and 78 deletions

View file

@ -1,10 +1,5 @@
package mage.server; package mage.server;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.constants.ManaType; import mage.constants.ManaType;
import mage.constants.TableState; import mage.constants.TableState;
@ -29,6 +24,11 @@ import mage.server.util.SystemUtil;
import mage.view.TableClientMessage; import mage.view.TableClientMessage;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -180,7 +180,7 @@ public class User {
public void lostConnection() { public void lostConnection() {
// Because watched games don't get restored after reconnection call stop watching // Because watched games don't get restored after reconnection call stop watching
for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext();) { for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext(); ) {
UUID gameId = iterator.next(); UUID gameId = iterator.next();
GameManager.instance.stopWatching(gameId, userId); GameManager.instance.stopWatching(gameId, userId);
iterator.remove(); iterator.remove();
@ -215,10 +215,10 @@ public class User {
int minutes = (int) SystemUtil.getDateDiff(connectionTime, new Date(), TimeUnit.SECONDS) / 60; int minutes = (int) SystemUtil.getDateDiff(connectionTime, new Date(), TimeUnit.SECONDS) / 60;
int hours = 0; int hours = 0;
if (minutes > 59) { if (minutes > 59) {
hours = (int) minutes / 60; hours = minutes / 60;
minutes = minutes - (hours * 60); minutes = minutes - (hours * 60);
} }
return Integer.toString(hours) + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes)); return hours + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes));
} }
public void fireCallback(final ClientCallback call) { public void fireCallback(final ClientCallback call) {
@ -329,10 +329,11 @@ public class User {
private void reconnect() { private void reconnect() {
logger.trace(userName + " started reconnect"); logger.trace(userName + " started reconnect");
//lastActivity = new Date(); // ??? comment to test can't reconnect to game on disconnect
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 (Iterator<Entry<UUID, UUID>> iterator = userTournaments.entrySet().iterator(); iterator.hasNext();) { for (Iterator<Entry<UUID, UUID>> iterator = userTournaments.entrySet().iterator(); iterator.hasNext(); ) {
Entry<UUID, UUID> next = iterator.next(); Entry<UUID, UUID> next = iterator.next();
Optional<TournamentController> tournamentController = TournamentManager.instance.getTournamentController(next.getValue()); Optional<TournamentController> tournamentController = TournamentManager.instance.getTournamentController(next.getValue());
if (tournamentController.isPresent()) { if (tournamentController.isPresent()) {
@ -442,7 +443,7 @@ public class User {
} }
gameSessions.clear(); gameSessions.clear();
logger.trace("REMOVE " + userName + " watched Games " + watchedGames.size()); logger.trace("REMOVE " + userName + " watched Games " + watchedGames.size());
for (Iterator<UUID> it = watchedGames.iterator(); it.hasNext();) { // Iterator to prevent ConcurrentModificationException for (Iterator<UUID> it = watchedGames.iterator(); it.hasNext(); ) { // Iterator to prevent ConcurrentModificationException
UUID gameId = it.next(); UUID gameId = it.next();
GameManager.instance.stopWatching(gameId, userId); GameManager.instance.stopWatching(gameId, userId);
} }
@ -658,13 +659,13 @@ public class User {
builder.append(proto.getMatches()); builder.append(proto.getMatches());
List<String> quit = new ArrayList<>(); List<String> quit = new ArrayList<>();
if (proto.getMatchesIdleTimeout() > 0) { if (proto.getMatchesIdleTimeout() > 0) {
quit.add("I:" + Integer.toString(proto.getMatchesIdleTimeout())); quit.add("I:" + proto.getMatchesIdleTimeout());
} }
if (proto.getMatchesTimerTimeout() > 0) { if (proto.getMatchesTimerTimeout() > 0) {
quit.add("T:" + Integer.toString(proto.getMatchesTimerTimeout())); quit.add("T:" + proto.getMatchesTimerTimeout());
} }
if (proto.getMatchesQuit() > 0) { if (proto.getMatchesQuit() > 0) {
quit.add("Q:" + Integer.toString(proto.getMatchesQuit())); quit.add("Q:" + proto.getMatchesQuit());
} }
if (!quit.isEmpty()) { if (!quit.isEmpty()) {
builder.append(" ("); builder.append(" (");
@ -690,13 +691,13 @@ public class User {
builder.append(proto.getTourneys()); builder.append(proto.getTourneys());
List<String> quit = new ArrayList<>(); List<String> quit = new ArrayList<>();
if (proto.getTourneysQuitDuringDrafting() > 0) { if (proto.getTourneysQuitDuringDrafting() > 0) {
quit.add("D:" + Integer.toString(proto.getTourneysQuitDuringDrafting())); quit.add("D:" + proto.getTourneysQuitDuringDrafting());
} }
if (proto.getTourneysQuitDuringConstruction() > 0) { if (proto.getTourneysQuitDuringConstruction() > 0) {
quit.add("C:" + Integer.toString(proto.getTourneysQuitDuringConstruction())); quit.add("C:" + proto.getTourneysQuitDuringConstruction());
} }
if (proto.getTourneysQuitDuringRound() > 0) { if (proto.getTourneysQuitDuringRound() > 0) {
quit.add("R:" + Integer.toString(proto.getTourneysQuitDuringRound())); quit.add("R:" + proto.getTourneysQuitDuringRound());
} }
if (!quit.isEmpty()) { if (!quit.isEmpty()) {
builder.append(" ("); builder.append(" (");

View file

@ -1,23 +1,16 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.LookLibraryAndPickControllerEffect; import mage.abilities.effects.common.LookLibraryAndPickControllerEffect;
import mage.cards.*; import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player; import java.util.UUID;
import mage.target.TargetCard;
/** /**
*
* @author Quercitron * @author Quercitron
*/ */
public final class AncestralMemories extends CardImpl { public final class AncestralMemories extends CardImpl {
@ -38,41 +31,4 @@ public final class AncestralMemories extends CardImpl {
public AncestralMemories copy() { public AncestralMemories copy() {
return new AncestralMemories(this); return new AncestralMemories(this);
} }
} }
class AncestralMemoriesEffect extends OneShotEffect {
public AncestralMemoriesEffect() {
super(Outcome.DrawCard);
this.staticText = "Look at the top seven cards of your library. Put two of them into your hand and the rest into your graveyard";
}
public AncestralMemoriesEffect(final AncestralMemoriesEffect effect) {
super(effect);
}
@Override
public AncestralMemoriesEffect copy() {
return new AncestralMemoriesEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 7));
if (!cards.isEmpty()) {
controller.lookAtCards(source, null, cards, game);
TargetCard target = new TargetCard(Math.min(2, cards.size()), Zone.LIBRARY, new FilterCard("two cards to put in your hand"));
if (controller.choose(Outcome.DrawCard, cards, target, game)) {
Cards toHand = new CardsImpl(target.getTargets());
controller.moveCards(cards, Zone.HAND, source, game);
cards.removeAll(toHand);
}
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
}
return true;
}
return false;
}
}

View file

@ -1,7 +1,5 @@
package mage.cards.t; package mage.cards.t;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.EntersBattlefieldTappedAbility; import mage.abilities.common.EntersBattlefieldTappedAbility;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -12,22 +10,28 @@ import mage.abilities.mana.GreenManaAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.permanent.token.TokenImpl; import mage.game.permanent.token.TokenImpl;
import mage.game.permanent.token.Token;
import java.util.UUID;
/** /**
*
* @author Loki * @author Loki
*/ */
public final class TreetopVillage extends CardImpl { public final class TreetopVillage extends CardImpl {
public TreetopVillage(UUID ownerId, CardSetInfo setInfo) { public TreetopVillage(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.LAND},""); super(ownerId, setInfo, new CardType[]{CardType.LAND}, "");
// Treetop Village enters the battlefield tapped.
this.addAbility(new EntersBattlefieldTappedAbility()); this.addAbility(new EntersBattlefieldTappedAbility());
// {T}: Add {G}.
this.addAbility(new GreenManaAbility()); this.addAbility(new GreenManaAbility());
// {1}{G}: Treetop Village becomes a 3/3 green Ape creature with trample until end of turn. Its still a land. (It can deal excess combat damage to the player or planeswalker its attacking.)
this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesCreatureSourceEffect(new ApeToken(), "land", Duration.EndOfTurn), new ManaCostsImpl("{1}{G}"))); this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesCreatureSourceEffect(new ApeToken(), "land", Duration.EndOfTurn), new ManaCostsImpl("{1}{G}")));
} }
@ -51,6 +55,7 @@ class ApeToken extends TokenImpl {
toughness = new MageInt(3); toughness = new MageInt(3);
this.addAbility(TrampleAbility.getInstance()); this.addAbility(TrampleAbility.getInstance());
} }
public ApeToken(final ApeToken token) { public ApeToken(final ApeToken token) {
super(token); super(token);
} }

View file

@ -250,7 +250,7 @@ public class VerifyCardDataTest {
cardsList.forEach((cardName, amount) -> { cardsList.forEach((cardName, amount) -> {
if (amount != 2) { if (amount != 2) {
String error = "Error: found non duplicated rare card - " String error = "Error: found non duplicated rare card -"
+ " set (" + set.getCode() + " - " + set.getName() + ")" + " set (" + set.getCode() + " - " + set.getName() + ")"
+ " card (" + cardName + ")"; + " card (" + cardName + ")";
doubleErrors.add(error); doubleErrors.add(error);

View file

@ -398,7 +398,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu
} }
} }
public boolean isCanLookAtNextTopLibraryCard(Game game) { public boolean canLookAtNextTopLibraryCard(Game game) {
// If the top card of your library changes while youre casting a spell, playing a land, or activating an ability, // If the top card of your library changes while youre casting a spell, playing a land, or activating an ability,
// you cant look at the new top card until you finish doing so. This means that if you cast the top card of // you cant look at the new top card until you finish doing so. This means that if you cast the top card of
// your library, you cant look at the next one until youre done paying for that spell. (2019-05-03) // your library, you cant look at the next one until youre done paying for that spell. (2019-05-03)

View file

@ -20,7 +20,6 @@ public class ChooseACardNameEffect extends OneShotEffect {
public static final String INFO_KEY = "NAMED_CARD"; public static final String INFO_KEY = "NAMED_CARD";
public enum TypeOfName { public enum TypeOfName {
ALL, ALL,
NOT_BASIC_LAND_NAME, NOT_BASIC_LAND_NAME,
NONBASIC_LAND_NAME, NONBASIC_LAND_NAME,

View file

@ -39,7 +39,7 @@ public class LookAtTopCardOfLibraryAnyTimeEffect extends ContinuousEffectImpl {
if (obj == null) { if (obj == null) {
return false; return false;
} }
if (!isCanLookAtNextTopLibraryCard(game)) { if (!canLookAtNextTopLibraryCard(game)) {
return false; return false;
} }
controller.lookAtCards("Top card of " + obj.getIdName() + " controller's library", topCard, game); controller.lookAtCards("Top card of " + obj.getIdName() + " controller's library", topCard, game);

View file

@ -44,11 +44,11 @@ public class PlayWithTheTopCardRevealedEffect extends ContinuousEffectImpl {
if (allPlayers) { if (allPlayers) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null && isCanLookAtNextTopLibraryCard(game)) { if (player != null && canLookAtNextTopLibraryCard(game)) {
player.setTopCardRevealed(true); player.setTopCardRevealed(true);
} }
} }
} else if (isCanLookAtNextTopLibraryCard(game)) { } else if (canLookAtNextTopLibraryCard(game)) {
controller.setTopCardRevealed(true); controller.setTopCardRevealed(true);
} }
return true; return true;

View file

@ -456,6 +456,8 @@ public interface Player extends MageItem, Copyable<Player> {
/** /**
* Adds the cards to the reveal window and adds the source object's id name * Adds the cards to the reveal window and adds the source object's id name
* to the title bar of the revealed cards window * to the title bar of the revealed cards window
* <p>
* Warning, if you use it from continuous effect, then check with extra call isCanLookAtNextTopLibraryCard
* *
* @param source * @param source
* @param name * @param name
@ -472,6 +474,8 @@ public interface Player extends MageItem, Copyable<Player> {
/** /**
* Adds the cards to the look window and adds the source object's id name to * Adds the cards to the look window and adds the source object's id name to
* the title bar of the lookedAt window * the title bar of the lookedAt window
* <p>
* Warning, if you use it from continuous effect, then check with extra call isCanLookAtNextTopLibraryCard
* *
* @param source * @param source
* @param name * @param name

View file

@ -14,7 +14,6 @@ import mage.watchers.Watcher;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
/** /**