* Morph - Fixed handling (card shown face down after cancel of morph cast).

This commit is contained in:
LevelX2 2014-09-13 11:23:01 +02:00
parent 5578e4c158
commit 85baf357e3
3 changed files with 22 additions and 24 deletions

View file

@ -113,15 +113,18 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
this(card, createCosts(morphCost)); this(card, createCosts(morphCost));
} }
public MorphAbility(Card card, Costs morphCosts) { public MorphAbility(Card card, Costs<Cost> morphCosts) {
super(Zone.HAND, null); super(Zone.HAND, null);
card.setMorphCard(true); card.setMorphCard(true);
this.setWorksFaceDown(true); this.setWorksFaceDown(true);
name = ABILITY_KEYWORD; name = ABILITY_KEYWORD;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(ABILITY_KEYWORD).append(" "); sb.append(ABILITY_KEYWORD).append(" ");
if (!(morphCosts instanceof ManaCosts)) { for (Cost cost :morphCosts) {
sb.append("- "); if (!(cost instanceof ManaCosts)) {
sb.append("- ");
break;
}
} }
sb.append(morphCosts.getText()).append(" "); sb.append(morphCosts.getText()).append(" ");
sb.append(REMINDER_TEXT); sb.append(REMINDER_TEXT);
@ -181,16 +184,14 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
public boolean askToActivateAlternativeCosts(Ability ability, Game game) { public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
if (ability instanceof SpellAbility) { if (ability instanceof SpellAbility) {
Player player = game.getPlayer(controllerId); Player player = game.getPlayer(controllerId);
if (player != null) { Spell spell = game.getStack().getSpell(ability.getId());
if (player != null && spell != null) {
this.resetMorph(); this.resetMorph();
spell.setFaceDown(true); // so only the back is visible
for (AlternativeCost2 alternateCastingCost: alternateCosts) { for (AlternativeCost2 alternateCastingCost: alternateCosts) {
if (alternateCastingCost.canPay(ability, sourceId, controllerId, game) && if (alternateCastingCost.canPay(ability, sourceId, controllerId, game) &&
player.chooseUse(Outcome.Benefit, new StringBuilder("Cast this card as a 2/2 face-down creature for ").append(alternateCastingCost.getText(true)).append(" ?").toString(), game)) { player.chooseUse(Outcome.Benefit, new StringBuilder("Cast this card as a 2/2 face-down creature for ").append(alternateCastingCost.getText(true)).append(" ?").toString(), game)) {
activateMorph(alternateCastingCost, game);
Spell spell = game.getStack().getSpell(ability.getId());
if (spell != null) {
spell.setFaceDown(true);
} activateMorph(alternateCastingCost, game);
ability.getManaCostsToPay().clear(); ability.getManaCostsToPay().clear();
ability.getCosts().clear(); ability.getCosts().clear();
for (Iterator it = ((Costs) alternateCastingCost).iterator(); it.hasNext();) { for (Iterator it = ((Costs) alternateCastingCost).iterator(); it.hasNext();) {
@ -202,14 +203,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
} }
} }
} else { } else {
Card card = game.getCard(getSourceId()); // face down was set to true in PlayerImpl.cast, reset it here if not cast face down spell.setFaceDown(false);
if (card != null) {
card.setFaceDown(false);
}
Spell spell = game.getStack().getSpell(ability.getId());
if (spell != null) {
spell.setFaceDown(false);
}
} }
} }
} }

View file

@ -79,6 +79,7 @@ public class Spell implements StackObject, Card {
private UUID controllerId; private UUID controllerId;
private boolean copiedSpell; private boolean copiedSpell;
private boolean faceDown;
public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) { public Spell(Card card, SpellAbility ability, UUID controllerId, Zone fromZone) {
this.card = card; this.card = card;
@ -119,6 +120,7 @@ public class Spell implements StackObject, Card {
this.controllerId = spell.controllerId; this.controllerId = spell.controllerId;
this.fromZone = spell.fromZone; this.fromZone = spell.fromZone;
this.copiedSpell = spell.copiedSpell; this.copiedSpell = spell.copiedSpell;
this.faceDown = spell.faceDown;
} }
@ -255,6 +257,9 @@ public class Spell implements StackObject, Card {
} }
} else { } else {
updateOptionalCosts(0); updateOptionalCosts(0);
if (isFaceDown()) {
card.setFaceDown(true);
}
result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId); result = card.putOntoBattlefield(game, fromZone, ability.getId(), controllerId);
return result; return result;
} }
@ -680,22 +685,24 @@ public class Spell implements StackObject, Card {
@Override @Override
public void setFaceDown(boolean value) { public void setFaceDown(boolean value) {
card.setFaceDown(value); faceDown = value;
} }
@Override @Override
public boolean turnFaceUp(Game game, UUID playerId) { public boolean turnFaceUp(Game game, UUID playerId) {
return card.turnFaceUp(game, playerId); setFaceDown(false);
return true;
} }
@Override @Override
public boolean turnFaceDown(Game game, UUID playerId) { public boolean turnFaceDown(Game game, UUID playerId) {
return card.turnFaceDown(game, playerId); setFaceDown(true);
return true;
} }
@Override @Override
public boolean isFaceDown() { public boolean isFaceDown() {
return card.isFaceDown(); return faceDown;
} }
@Override @Override

View file

@ -794,9 +794,6 @@ public abstract class PlayerImpl implements Player, Serializable {
//20091005 - 601.2a //20091005 - 601.2a
Card card = game.getCard(ability.getSourceId()); Card card = game.getCard(ability.getSourceId());
if (card != null) { if (card != null) {
if (card.isMorphCard() && !noMana) { //TODO: move to other place
card.setFaceDown(true);
}
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId))) { if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability.getSourceId(), playerId))) {
int bookmark = game.bookmarkState(); int bookmark = game.bookmarkState();
Zone fromZone = game.getState().getZone(card.getId()); Zone fromZone = game.getState().getZone(card.getId());