From f0ff8154f32e368b4c72ff110886e9636a46cbd7 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 1 Feb 2020 12:17:04 +0400 Subject: [PATCH] * Can't cast prevention effects - fixed that UI marked affected cards as playable, but they're not; --- .../main/java/mage/players/PlayerImpl.java | 52 +++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 47ab5bbfc9..942826f2bb 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -3286,12 +3286,25 @@ public abstract class PlayerImpl implements Player, Serializable { boolean isPlayLand = (ability instanceof PlayLandAbility); // as original controller - // land restrictions + + // play land restrictions if (isPlayLand && game.getContinuousEffects().preventedByRuleModification( GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability.getSourceId(), this.getId()), ability, game, true)) { continue; } + // cast spell restrictions 1 + if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( + GameEvent.getEvent(EventType.CAST_SPELL, ability.getSourceId(), + ability.getSourceId(), this.getId()), ability, game, true)) { + continue; + } + // cast spell restrictions 2 + if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( + GameEvent.getEvent(EventType.CAST_SPELL_LATE, ability.getSourceId(), + ability.getSourceId(), this.getId()), ability, game, true)) { + continue; + } MageObjectReference permittingObject; if (isPlaySpell || isPlayLand) { @@ -3307,6 +3320,7 @@ public abstract class PlayerImpl implements Player, Serializable { || (fromZone == Zone.GRAVEYARD && canPlayCardsFromGraveyard()); // as affected controller + UUID savedControllerId = ability.getControllerId(); ability.setControllerId(this.getId()); try { @@ -3351,19 +3365,37 @@ public abstract class PlayerImpl implements Player, Serializable { } boolean fromAll = fromZone.equals(Zone.ALL); - if (hidden && (fromAll || fromZone == Zone.HAND)) { for (Card card : hand.getCards(game)) { for (Ability ability : card.getAbilities(game)) { // gets this activated ability from hand? (Morph?) if (ability.getZone().match(Zone.HAND)) { + boolean isPlaySpell = (ability instanceof SpellAbility); + boolean isPlayLand = (ability instanceof PlayLandAbility); + + // play land restrictions + if (isPlayLand && game.getContinuousEffects().preventedByRuleModification( + GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), + ability.getSourceId(), this.getId()), ability, game, true)) { + continue; + } + // cast spell restrictions 1 + if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( + GameEvent.getEvent(EventType.CAST_SPELL, ability.getSourceId(), + ability.getSourceId(), this.getId()), ability, game, true)) { + continue; + } + // cast spell restrictions 2 + if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( + GameEvent.getEvent(EventType.CAST_SPELL_LATE, ability.getSourceId(), + ability.getSourceId(), this.getId()), ability, game, true)) { + continue; + } + + // if have alternative cost if (ability instanceof ActivatedAbility) { - if (!(ability instanceof PlayLandAbility) - || !game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), - ability.getSourceId(), playerId), ability, game, true)) { - if (canPlay((ActivatedAbility) ability, availableMana, card, game)) { - playable.add(ability); - } + // normal ability + if (canPlay((ActivatedAbility) ability, availableMana, card, game)) { + playable.add(ability); } } else if (ability instanceof AlternativeSourceCosts) { if (card.isLand()) { @@ -3377,6 +3409,8 @@ public abstract class PlayerImpl implements Player, Serializable { } } } + } else { + // unknown type } } }