GameView: do not store Game anymore, get it from Match

This commit is contained in:
Hans Mackowiak
2020-11-28 19:02:33 +01:00
parent 70e75bde91
commit 88c017f962
18 changed files with 274 additions and 238 deletions

View File

@@ -128,6 +128,7 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
wantUnique = true;
break;
default:
}
catalogManager = new CardManager(getCDetailPicture(), wantUnique, false);
@@ -163,6 +164,7 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
case TinyLeaders:
this.controller = new DeckController<>(FModel.getDecks().getTinyLeaders(), this, newCreator);
break;
default:
}
getBtnAddBasicLands().setCommand(new UiCommand() {
@@ -189,6 +191,7 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
case TinyLeaders:
case Brawl:
return CardLimit.Singleton;
default:
}
}
return CardLimit.None; //if not enforcing deck legality, don't enforce default limit
@@ -488,6 +491,7 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
default:
break;
}
default:
}
this.sectionMode = sectionMode;
@@ -508,7 +512,6 @@ public final class CEditorConstructed extends CDeckEditor<Deck> {
/* (non-Javadoc)
* @see forge.gui.deckeditor.ACEditorBase#show(forge.Command)
*/
@SuppressWarnings("serial")
@Override
public void update() {
this.getCatalogManager().setup(ItemManagerConfig.CARD_CATALOG);

View File

@@ -60,7 +60,7 @@ public enum CSubmenuQuestPrefs implements ICDoc {
|| QPref.WILD_OPPONENTS_MULTIPLIER.equals(i0.getQPref())) {
Double val = null;
try {
val = new Double(i0.getText());
val = Double.valueOf(i0.getText());
} catch (Exception e) {
}
validationError = val == null ? localizer.getMessage("lblEnteraDecimal") : null;

View File

@@ -271,7 +271,7 @@ public final class CMatchUI
if (!isInGame()) {
return;
}
final Deck deck = getGameView().getDeck(getCurrentPlayer().getLobbyPlayerName());
final Deck deck = getGameView().getDeck(getCurrentPlayer());
if (deck != null) {
FDeckViewer.show(deck);
}

View File

@@ -85,7 +85,8 @@ public final class Main {
System.exit(0);
}
@Override
@SuppressWarnings("deprecation")
@Override
protected void finalize() throws Throwable {
try {
ExceptionHandler.unregisterErrorHandling();

View File

@@ -84,10 +84,6 @@ public class PlayerControllerForTests extends PlayerController {
return player;
}
public Game getGame() {
return game;
}
@Override
public void playSpellAbilityForFree(SpellAbility copySA, boolean mayChoseNewTargets) {
throw new IllegalStateException("Callers of this method currently assume that it performs extra functionality!");
@@ -202,7 +198,7 @@ public class PlayerControllerForTests extends PlayerController {
}
@Override
public Player chooseStartingPlayer(boolean isFirstGame) {
public Player chooseStartingPlayer(boolean isFirstgame) {
return this.player;
}
@@ -320,7 +316,7 @@ public class PlayerControllerForTests extends PlayerController {
if (playerActions == null) {
return;
}
DeclareAttackersAction declareAttackers = playerActions.getNextActionIfApplicable(player, game, DeclareAttackersAction.class);
DeclareAttackersAction declareAttackers = playerActions.getNextActionIfApplicable(player, getGame(), DeclareAttackersAction.class);
if (declareAttackers == null) {
return;
}
@@ -330,11 +326,11 @@ public class PlayerControllerForTests extends PlayerController {
//TODO: banding (don't really care at the moment...)
for (Map.Entry<CardSpecification, PlayerSpecification> playerAttackAssignment : declareAttackers.getPlayerAttackAssignments().entrySet()) {
Player defender = getPlayerBeingAttacked(game, player, playerAttackAssignment.getValue());
Player defender = getPlayerBeingAttacked(getGame(), player, playerAttackAssignment.getValue());
attack(combat, playerAttackAssignment.getKey(), defender);
}
for (Map.Entry<CardSpecification, CardSpecification> planeswalkerAttackAssignment: declareAttackers.getPlaneswalkerAttackAssignments().entrySet()) {
Card defender = CardSpecificationHandler.INSTANCE.find(game.getCardsInGame(), planeswalkerAttackAssignment.getKey());
Card defender = CardSpecificationHandler.INSTANCE.find(getGame().getCardsInGame(), planeswalkerAttackAssignment.getKey());
attack(combat, planeswalkerAttackAssignment.getKey(), defender);
}
@@ -345,12 +341,12 @@ public class PlayerControllerForTests extends PlayerController {
private Player getPlayerBeingAttacked(Game game, Player attacker, PlayerSpecification defenderSpecification) {
if (defenderSpecification != null) {
return PlayerSpecificationHandler.INSTANCE.find(game.getPlayers(), defenderSpecification);
return PlayerSpecificationHandler.INSTANCE.find(getGame().getPlayers(), defenderSpecification);
}
if (game.getPlayers().size() != 2) {
if (getGame().getPlayers().size() != 2) {
throw new IllegalStateException("Can't use implicit defender specification in this situation!");
}
for (Player player : game.getPlayers()) {
for (Player player : getGame().getPlayers()) {
if (!attacker.equals(player)) {
return player;
}
@@ -372,7 +368,7 @@ public class PlayerControllerForTests extends PlayerController {
if (playerActions == null) {
return;
}
DeclareBlockersAction declareBlockers = playerActions.getNextActionIfApplicable(player, game, DeclareBlockersAction.class);
DeclareBlockersAction declareBlockers = playerActions.getNextActionIfApplicable(player, getGame(), DeclareBlockersAction.class);
if (declareBlockers == null) {
return;
}
@@ -384,7 +380,7 @@ public class PlayerControllerForTests extends PlayerController {
for (Map.Entry<CardSpecification, Collection<CardSpecification>> blockingAssignment : declareBlockers.getBlockingAssignments().asMap().entrySet()) {
Card attacker = CardSpecificationHandler.INSTANCE.find(combat.getAttackers(), blockingAssignment.getKey());
for (CardSpecification blockerSpecification : blockingAssignment.getValue()) {
Card blocker = CardSpecificationHandler.INSTANCE.find(game, blockerSpecification);
Card blocker = CardSpecificationHandler.INSTANCE.find(getGame(), blockerSpecification);
if (!CombatUtil.canBlock(attacker, blocker)) {
throw new IllegalStateException(blocker + " can't block " + blocker);
}
@@ -402,14 +398,14 @@ public class PlayerControllerForTests extends PlayerController {
//TODO: This method has to return the spellability chosen by player
// It should not play the sa right from here. The code has been left as it is to quickly adapt to changed playercontroller interface
if (playerActions != null) {
CastSpellFromHandAction castSpellFromHand = playerActions.getNextActionIfApplicable(player, game, CastSpellFromHandAction.class);
CastSpellFromHandAction castSpellFromHand = playerActions.getNextActionIfApplicable(player, getGame(), CastSpellFromHandAction.class);
if (castSpellFromHand != null) {
castSpellFromHand.castSpellFromHand(player, game);
castSpellFromHand.castSpellFromHand(player, getGame());
}
ActivateAbilityAction activateAbilityAction = playerActions.getNextActionIfApplicable(player, game, ActivateAbilityAction.class);
ActivateAbilityAction activateAbilityAction = playerActions.getNextActionIfApplicable(player, getGame(), ActivateAbilityAction.class);
if (activateAbilityAction != null) {
activateAbilityAction.activateAbility(player, game);
activateAbilityAction.activateAbility(player, getGame());
}
}
return null;
@@ -526,7 +522,7 @@ public class PlayerControllerForTests extends PlayerController {
public void orderAndPlaySimultaneousSa(List<SpellAbility> activePlayerSAs) {
for (final SpellAbility sa : activePlayerSAs) {
prepareSingleSa(sa.getHostCard(),sa,true);
ComputerUtil.playStack(sa, player, game);
ComputerUtil.playStack(sa, player, getGame());
}
}
@@ -544,7 +540,7 @@ public class PlayerControllerForTests extends PlayerController {
@Override
public void playTrigger(Card host, WrappedAbility wrapperAbility, boolean isMandatory) {
prepareSingleSa(host, wrapperAbility, isMandatory);
ComputerUtil.playNoStack(wrapperAbility.getActivatingPlayer(), wrapperAbility, game);
ComputerUtil.playNoStack(wrapperAbility.getActivatingPlayer(), wrapperAbility, getGame());
}
@Override
@@ -557,9 +553,9 @@ public class PlayerControllerForTests extends PlayerController {
// if (spell.canPlayFromEffectAI(player, !optional, noManaCost) || !optional) { -- could not save this part
if (spell.canPlay() || !optional) {
if (noManaCost) {
ComputerUtil.playSpellAbilityWithoutPayingManaCost(player, tgtSA, game);
ComputerUtil.playSpellAbilityWithoutPayingManaCost(player, tgtSA, getGame());
} else {
ComputerUtil.playStack(tgtSA, player, game);
ComputerUtil.playStack(tgtSA, player, getGame());
}
} else
return false; // didn't play spell