Fixed Suspend to work with cards without mana costs. Improved dredge rule texts (issue #157)

This commit is contained in:
LevelX2 2013-03-16 19:48:04 +01:00
parent dcacb90ba9
commit c5776a6ded
3 changed files with 29 additions and 13 deletions

View file

@ -78,7 +78,9 @@ public class SpellAbility extends ActivatedAbilityImpl<SpellAbility> {
if (!controllerId.equals(playerId)) { if (!controllerId.equals(playerId)) {
return false; return false;
} }
if (this.getManaCosts().isEmpty()) {
return false;
}
if (costs.canPay(sourceId, controllerId, game) && canChooseTarget(game)) { if (costs.canPay(sourceId, controllerId, game) && canChooseTarget(game)) {
return true; return true;
} }

View file

@ -58,11 +58,6 @@ public class DredgeAbility extends SimpleStaticAbility {
public DredgeAbility copy() { public DredgeAbility copy() {
return new DredgeAbility(this); return new DredgeAbility(this);
} }
@Override
public String getRule() {
return "Dredge " + super.getRule();
}
} }
class DredgeEffect extends ReplacementEffectImpl<DredgeEffect> { class DredgeEffect extends ReplacementEffectImpl<DredgeEffect> {
@ -72,7 +67,8 @@ class DredgeEffect extends ReplacementEffectImpl<DredgeEffect> {
public DredgeEffect(int value) { public DredgeEffect(int value) {
super(Duration.WhileInGraveyard, Outcome.ReturnToHand); super(Duration.WhileInGraveyard, Outcome.ReturnToHand);
this.amount = value; this.amount = value;
this.staticText = Integer.toString(value); this.staticText = new StringBuilder("Dredge ").append(Integer.toString(value))
.append(" <i>(If you would draw a card, instead you may put exactly three cards from the top of your library into your graveyard. If you do, return this card from your graveyard to your hand. Otherwise, draw a card.)</i>").toString();
} }
public DredgeEffect(final DredgeEffect effect) { public DredgeEffect(final DredgeEffect effect) {
@ -96,12 +92,10 @@ class DredgeEffect extends ReplacementEffectImpl<DredgeEffect> {
if (sourceCard == null) { if (sourceCard == null) {
return false; return false;
} }
StringBuilder sb = new StringBuilder();
sb.append("Put exactly ").append(amount).append(" cards from the top of your library into your graveyard?");
sb.append(" If you do, return ").append(sourceCard.getName()).append(" from your graveyard to your hand. Otherwise, draw a card.");
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null && player.getLibrary().size() >= amount && player.chooseUse(outcome, sb.toString(), game)) { if (player != null && player.getLibrary().size() >= amount
&& player.chooseUse(outcome, new StringBuilder("Dredge ").append(sourceCard.getName()).
append(" (").append(amount).append(" cards go from top of library to graveyard)").toString(), game)) {
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Card card = player.getLibrary().removeFromTop(game); Card card = player.getLibrary().removeFromTop(game);
if (card != null) { if (card != null) {

View file

@ -29,6 +29,7 @@
package mage.abilities.keyword; package mage.abilities.keyword;
import java.util.UUID; import java.util.UUID;
import mage.Constants.AsThoughEffectType;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Duration; import mage.Constants.Duration;
import mage.Constants.Layer; import mage.Constants.Layer;
@ -36,6 +37,7 @@ import mage.Constants.Outcome;
import mage.Constants.SubLayer; import mage.Constants.SubLayer;
import mage.Constants.TargetController; import mage.Constants.TargetController;
import mage.Constants.Zone; import mage.Constants.Zone;
import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl; import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
@ -170,6 +172,18 @@ public class SuspendAbility extends ActivatedAbilityImpl<SuspendAbility> {
this.ruleText = ability.getRule(); this.ruleText = ability.getRule();
} }
@Override
public boolean canActivate(UUID playerId, Game game) {
MageObject object = game.getObject(sourceId);
if ((object.getCardType().contains(CardType.INSTANT) ||
object.getAbilities().containsKey(FlashAbility.getInstance().getId()) ||
game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.CAST, game) ||
game.canPlaySorcery(playerId))) {
return true;
}
return false;
}
@Override @Override
public String getRule() { public String getRule() {
return ruleText; return ruleText;
@ -205,7 +219,13 @@ class SuspendExileEffect extends OneShotEffect<SuspendExileEffect> {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (card != null && card.getSpellAbility().canActivate(source.getControllerId(), game) && card.getSpellAbility().isInUseableZone(game, card, false)) { if (card != null && controller != null) {
// check if user really wants to suspend the card (only if spell can't be casted because else the choose ability dialog appears)
if (!card.getSpellAbility().canActivate(source.getControllerId(), game)) {
if (!controller.chooseUse(outcome, new StringBuilder("Suspend ").append(card.getName()).append("?").toString(), game)) {
return false;
}
}
UUID exileId = (UUID) game.getState().getValue("SuspendExileId" + source.getControllerId().toString()); UUID exileId = (UUID) game.getState().getValue("SuspendExileId" + source.getControllerId().toString());
if (exileId == null) { if (exileId == null) {
exileId = UUID.randomUUID(); exileId = UUID.randomUUID();