Some formatting and change of handling of adjust methods of StackAbility.

This commit is contained in:
LevelX2 2014-07-14 17:41:30 +02:00
parent 125a7acb54
commit de47dbad43
2 changed files with 32 additions and 35 deletions

View file

@ -63,15 +63,16 @@ import mage.constants.AbilityWord;
*/
public class StackAbility implements StackObject, Ability {
private static List emptyList = new ArrayList();
private static List<CardType> emptyCardType = new ArrayList<>();
private static List<String> emptyString = new ArrayList<>();
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts emptyCost = new ManaCostsImpl();
private static Costs emptyCosts = new CostsImpl();
private static ManaCosts<ManaCost> emptyCost = new ManaCostsImpl<>();
private static Costs<Cost> emptyCosts = new CostsImpl<>();
private static Abilities<Ability> 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<CardType> getCardType() {
return emptyList;
return emptyCardType;
}
@Override
public List<String> getSubtype() {
return emptyList;
return emptyString;
}
@Override
@ -149,11 +150,11 @@ public class StackAbility implements StackObject, Ability {
@Override
public List<String> getSupertype() {
return emptyList;
return emptyString;
}
@Override
public Abilities getAbilities() {
public Abilities<Ability> getAbilities() {
return emptyAbilites;
}
@ -168,7 +169,7 @@ public class StackAbility implements StackObject, Ability {
}
@Override
public ManaCosts getManaCost() {
public ManaCosts<ManaCost> getManaCost() {
return emptyCost;
}
@ -203,7 +204,7 @@ public class StackAbility implements StackObject, Ability {
}
@Override
public Costs getCosts() {
public Costs<Cost> getCosts() {
return emptyCosts;
}
@ -281,7 +282,7 @@ public class StackAbility implements StackObject, Ability {
public void addAlternativeCost(AlternativeCost cost) { }
@Override
public ManaCosts getManaCosts() {
public ManaCosts<ManaCost> 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) {

View file

@ -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.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);