From de47dbad434846611aafe840789ebac6d696d7e8 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 14 Jul 2014 17:41:30 +0200 Subject: [PATCH] Some formatting and change of handling of adjust methods of StackAbility. --- Mage/src/mage/game/stack/StackAbility.java | 37 ++++++++++++++-------- Mage/src/mage/players/PlayerImpl.java | 30 +++++------------- 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Mage/src/mage/game/stack/StackAbility.java b/Mage/src/mage/game/stack/StackAbility.java index 2ed2bbd837..69ba7abf21 100644 --- a/Mage/src/mage/game/stack/StackAbility.java +++ b/Mage/src/mage/game/stack/StackAbility.java @@ -63,15 +63,16 @@ import mage.constants.AbilityWord; */ public class StackAbility implements StackObject, Ability { - private static List emptyList = new ArrayList(); + private static List emptyCardType = new ArrayList<>(); + private static List emptyString = new ArrayList<>(); private static ObjectColor emptyColor = new ObjectColor(); - private static ManaCosts emptyCost = new ManaCostsImpl(); - private static Costs emptyCosts = new CostsImpl(); + private static ManaCosts emptyCost = new ManaCostsImpl<>(); + private static Costs emptyCosts = new CostsImpl<>(); private static Abilities emptyAbilites = new AbilitiesImpl<>(); private final Ability ability; private UUID controllerId; - private String name = ""; + private String name; private String expansionSetCode; public StackAbility(Ability ability, UUID controllerId) { @@ -134,12 +135,12 @@ public class StackAbility implements StackObject, Ability { @Override public List getCardType() { - return emptyList; + return emptyCardType; } @Override public List getSubtype() { - return emptyList; + return emptyString; } @Override @@ -149,11 +150,11 @@ public class StackAbility implements StackObject, Ability { @Override public List getSupertype() { - return emptyList; + return emptyString; } @Override - public Abilities getAbilities() { + public Abilities getAbilities() { return emptyAbilites; } @@ -168,7 +169,7 @@ public class StackAbility implements StackObject, Ability { } @Override - public ManaCosts getManaCost() { + public ManaCosts getManaCost() { return emptyCost; } @@ -203,7 +204,7 @@ public class StackAbility implements StackObject, Ability { } @Override - public Costs getCosts() { + public Costs getCosts() { return emptyCosts; } @@ -281,7 +282,7 @@ public class StackAbility implements StackObject, Ability { public void addAlternativeCost(AlternativeCost cost) { } @Override - public ManaCosts getManaCosts() { + public ManaCosts getManaCosts() { return ability.getManaCosts(); } @@ -318,10 +319,20 @@ public class StackAbility implements StackObject, Ability { } @Override - public void adjustChoices(Ability ability, Game game) {} + public void adjustChoices(Ability ability, Game game) { + Card card = game.getCard(ability.getSourceId()); + if (card != null) { + card.adjustChoices(ability, game); + } + } @Override - public void adjustCosts(Ability ability, Game game) {} + public void adjustCosts(Ability ability, Game game) { + Card card = game.getCard(ability.getSourceId()); + if (card != null) { + card.adjustCosts(ability, game); + } + } @Override public void adjustTargets(Ability ability, Game game) { diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 37157e76d9..bbe45f6ece 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -874,34 +874,20 @@ public abstract class PlayerImpl implements Player, Serializable { } //20091005 - 603.3c, 603.3d int bookmark = game.bookmarkState(); - //FIXME: remove try\catch once we find out the reason for NPE on server TriggeredAbility ability = source.copy(); -// try { -// ability = source.copy(); -// } catch (NullPointerException npe) { -// log.fatal("NPE for source=" + source); -// log.fatal("NPE for source=" + source.getRule()); -// throw npe; -// } - if (ability != null && ability.canChooseTarget(game)) { + if (ability != null && ability.canChooseTarget(game)) { if (ability.isUsesStack()) { game.getStack().push(new StackAbility(ability, playerId)); - if (ability.activate(game, false)) { - if (ability.getRuleVisible()) { - game.informPlayers(ability.getGameLogMessage(game)); - } - game.removeBookmark(bookmark); - return true; + } + if (ability.activate(game, false)) { + if (ability.getRuleVisible()) { + game.informPlayers(ability.getGameLogMessage(game)); } - } else { - if (ability.activate(game, false)) { - if (ability.getRuleVisible()) { - game.informPlayers(ability.getGameLogMessage(game)); - } + if (!ability.isUsesStack()) { ability.resolve(game); - game.removeBookmark(bookmark); - return true; } + game.removeBookmark(bookmark); + return true; } } game.restoreState(bookmark);