From fef04007d44fa92fa6732095995b9dc34255b93f Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Sun, 4 Sep 2022 20:19:29 -0400 Subject: [PATCH] [ZNR] Fix NPE for Yasharn. Closes #9465 --- .../mage/cards/y/YasharnImplacableEarth.java | 155 +++++++++--------- 1 file changed, 80 insertions(+), 75 deletions(-) diff --git a/Mage.Sets/src/mage/cards/y/YasharnImplacableEarth.java b/Mage.Sets/src/mage/cards/y/YasharnImplacableEarth.java index 5b042531e79..1fb9702080e 100644 --- a/Mage.Sets/src/mage/cards/y/YasharnImplacableEarth.java +++ b/Mage.Sets/src/mage/cards/y/YasharnImplacableEarth.java @@ -144,86 +144,91 @@ class YasharnImplacableEarthEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - boolean canTargetLand = true; Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId()); - if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY - || event.getType() == GameEvent.EventType.CAST_SPELL) { - if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY) { - if (permanent == null) { - return false; - } - } - Optional ability = game.getAbility(event.getTargetId(), event.getSourceId()); - for (Cost cost : ability.get().getCosts()) { - if (cost instanceof PayLifeCost - || cost instanceof PayVariableLifeCost) { - return true; // can't pay with life - } - if (cost instanceof SacrificeSourceCost - && !permanent.isLand()) { - return true; - } - if (cost instanceof SacrificeTargetCost) { - SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost; - Filter filter = sacrificeCost.getTargets().get(0).getFilter(); - for (Object predicate : filter.getPredicates()) { - if (predicate instanceof CardType.CardTypePredicate) { - if (!predicate.toString().equals("CardType(Land)")) { - canTargetLand = false; - } - } - } - return !canTargetLand; // must be nonland target - } - if (cost instanceof SacrificeAllCost) { - SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost; - Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); - for (Object predicate : filter.getPredicates()) { - if (predicate instanceof CardType.CardTypePredicate) { - if (!predicate.toString().equals("CardType(Land)")) { - canTargetLand = false; - } - } - } - return !canTargetLand; // must be nonland target - } - if (cost instanceof SacrificeAttachedCost) { - SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost; - Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); - for (Object predicate : filter.getPredicates()) { - if (predicate instanceof CardType.CardTypePredicate) { - if (!predicate.toString().equals("CardType(Land)")) { - canTargetLand = false; - } - } - } - return !canTargetLand; // must be nonland target - } - if (cost instanceof SacrificeAttachmentCost) { - SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost; - Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); - for (Object predicate : filter.getPredicates()) { - if (predicate instanceof CardType.CardTypePredicate) { - if (!predicate.toString().equals("CardType(Land)")) { - canTargetLand = false; - } - } - } - return !canTargetLand; // must be nonland target - } + if (event.getType() != GameEvent.EventType.ACTIVATE_ABILITY + && event.getType() != GameEvent.EventType.CAST_SPELL) { + return false; + } - if (cost instanceof SacrificeXTargetCost) { - SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost; - Filter filter = sacrificeCost.getFilter(); - for (Object predicate : filter.getPredicates()) { - if (predicate instanceof CardType.CardTypePredicate) { - if (!predicate.toString().equals("CardType(Land)")) { - canTargetLand = false; - } + if (event.getType() == GameEvent.EventType.ACTIVATE_ABILITY || permanent == null) { + return false; + } + + boolean canTargetLand = true; + Optional ability = game.getAbility(event.getTargetId(), event.getSourceId()); + if (!ability.isPresent()) { + return false; + } + + for (Cost cost : ability.get().getCosts()) { + if (cost instanceof PayLifeCost + || cost instanceof PayVariableLifeCost) { + return true; // can't pay with life + } + if (cost instanceof SacrificeSourceCost + && !permanent.isLand()) { + return true; + } + if (cost instanceof SacrificeTargetCost) { + SacrificeTargetCost sacrificeCost = (SacrificeTargetCost) cost; + Filter filter = sacrificeCost.getTargets().get(0).getFilter(); + for (Object predicate : filter.getPredicates()) { + if (predicate instanceof CardType.CardTypePredicate) { + if (!predicate.toString().equals("CardType(Land)")) { + canTargetLand = false; } } - return !canTargetLand; // must be nonland target } + return !canTargetLand; // must be nonland target + } + if (cost instanceof SacrificeAllCost) { + SacrificeAllCost sacrificeAllCost = (SacrificeAllCost) cost; + Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); + for (Object predicate : filter.getPredicates()) { + if (predicate instanceof CardType.CardTypePredicate) { + if (!predicate.toString().equals("CardType(Land)")) { + canTargetLand = false; + } + } + } + return !canTargetLand; // must be nonland target + } + if (cost instanceof SacrificeAttachedCost) { + SacrificeAttachedCost sacrificeAllCost = (SacrificeAttachedCost) cost; + Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); + for (Object predicate : filter.getPredicates()) { + if (predicate instanceof CardType.CardTypePredicate) { + if (!predicate.toString().equals("CardType(Land)")) { + canTargetLand = false; + } + } + } + return !canTargetLand; // must be nonland target + } + if (cost instanceof SacrificeAttachmentCost) { + SacrificeAttachmentCost sacrificeAllCost = (SacrificeAttachmentCost) cost; + Filter filter = sacrificeAllCost.getTargets().get(0).getFilter(); + for (Object predicate : filter.getPredicates()) { + if (predicate instanceof CardType.CardTypePredicate) { + if (!predicate.toString().equals("CardType(Land)")) { + canTargetLand = false; + } + } + } + return !canTargetLand; // must be nonland target + } + + if (cost instanceof SacrificeXTargetCost) { + SacrificeXTargetCost sacrificeCost = (SacrificeXTargetCost) cost; + Filter filter = sacrificeCost.getFilter(); + for (Object predicate : filter.getPredicates()) { + if (predicate instanceof CardType.CardTypePredicate) { + if (!predicate.toString().equals("CardType(Land)")) { + canTargetLand = false; + } + } + } + return !canTargetLand; // must be nonland target } } return false;