From 886b96072e95cb29d0eba19341d27cd0d24a8035 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 18 Apr 2019 08:44:44 +0400 Subject: [PATCH] God-Eternal Bontu - fixed game freeze with NPE error --- Mage.Sets/src/mage/cards/f/FuneralMarch.java | 27 ++++++++--------- .../src/mage/cards/w/WormsOfTheEarth.java | 29 +++++++------------ .../GodEternalDiesTriggeredAbility.java | 11 +++---- .../abilities/keyword/UnearthAbility.java | 11 +++---- 4 files changed, 35 insertions(+), 43 deletions(-) diff --git a/Mage.Sets/src/mage/cards/f/FuneralMarch.java b/Mage.Sets/src/mage/cards/f/FuneralMarch.java index e5b80c6489..9de029d752 100644 --- a/Mage.Sets/src/mage/cards/f/FuneralMarch.java +++ b/Mage.Sets/src/mage/cards/f/FuneralMarch.java @@ -1,7 +1,5 @@ - package mage.cards.f; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.ZoneChangeTriggeredAbility; import mage.abilities.effects.Effect; @@ -23,14 +21,15 @@ import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; import mage.target.targetpointer.FixedTarget; +import java.util.UUID; + /** - * * @author L_J */ public final class FuneralMarch extends CardImpl { public FuneralMarch(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{B}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{B}{B}"); this.subtype.add(SubType.AURA); // Enchant creature @@ -73,17 +72,19 @@ class FuneralMarchTriggeredAbility extends ZoneChangeTriggeredAbility { public boolean checkTrigger(GameEvent event, Game game) { Permanent enchantment = game.getPermanentOrLKIBattlefield(this.getSourceId()); if (enchantment != null && enchantment.getAttachedTo() != null && event.getTargetId().equals(enchantment.getAttachedTo())) { - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - if ((fromZone == null || zEvent.getFromZone() == fromZone) && (toZone == null || zEvent.getToZone() == toZone)) { - for (Effect effect : getEffects()) { - if (zEvent.getTarget() != null) { - Permanent attachedTo = (Permanent) game.getLastKnownInformation(enchantment.getAttachedTo(), Zone.BATTLEFIELD, enchantment.getAttachedToZoneChangeCounter()); - if (attachedTo != null) { - effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId())); + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if ((fromZone == null || zEvent.getFromZone() == fromZone) && (toZone == null || zEvent.getToZone() == toZone)) { + for (Effect effect : getEffects()) { + if (zEvent.getTarget() != null) { + Permanent attachedTo = (Permanent) game.getLastKnownInformation(enchantment.getAttachedTo(), Zone.BATTLEFIELD, enchantment.getAttachedToZoneChangeCounter()); + if (attachedTo != null) { + effect.setTargetPointer(new FixedTarget(attachedTo.getControllerId())); + } } - } + } + return true; } - return true; } } return false; diff --git a/Mage.Sets/src/mage/cards/w/WormsOfTheEarth.java b/Mage.Sets/src/mage/cards/w/WormsOfTheEarth.java index 35685256a9..128d05dbd8 100644 --- a/Mage.Sets/src/mage/cards/w/WormsOfTheEarth.java +++ b/Mage.Sets/src/mage/cards/w/WormsOfTheEarth.java @@ -1,38 +1,33 @@ - package mage.cards.w; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.costs.Cost; import mage.abilities.costs.common.SacrificeTargetCost; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.CardType; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.TargetController; -import mage.constants.Zone; +import mage.constants.*; import mage.filter.common.FilterControlledLandPermanent; import mage.game.Game; -import mage.game.permanent.Permanent; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.common.TargetControlledPermanent; +import java.util.UUID; + /** - * * @author L_J */ public final class WormsOfTheEarth extends CardImpl { public WormsOfTheEarth(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{B}{B}{B}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}{B}{B}"); // Players can't play lands. this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new WormsOfTheEarthPlayEffect())); @@ -60,7 +55,7 @@ class WormsOfTheEarthPlayEffect extends ContinuousRuleModifyingEffectImpl { super(Duration.WhileOnBattlefield, Outcome.Neutral); this.staticText = "Players can't play lands"; } - + public WormsOfTheEarthPlayEffect(final WormsOfTheEarthPlayEffect effect) { super(effect); } @@ -69,7 +64,7 @@ class WormsOfTheEarthPlayEffect extends ContinuousRuleModifyingEffectImpl { public WormsOfTheEarthPlayEffect copy() { return new WormsOfTheEarthPlayEffect(this); } - + @Override public boolean apply(Game game, Ability source) { return true; @@ -104,7 +99,7 @@ class WormsOfTheEarthEnterEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean checksEventType(GameEvent event, Game game) { - return GameEvent.EventType.ZONE_CHANGE == event.getType(); + return event.getType() == GameEvent.EventType.ZONE_CHANGE; } @Override @@ -112,9 +107,7 @@ class WormsOfTheEarthEnterEffect extends ContinuousRuleModifyingEffectImpl { ZoneChangeEvent zEvent = (ZoneChangeEvent) event; if (zEvent.getToZone() == Zone.BATTLEFIELD) { Card card = game.getCard(zEvent.getTargetId()); - if (card != null && card.isLand()) { - return true; - } + return card != null && card.isLand(); } return false; } @@ -142,7 +135,7 @@ class WormsOfTheEarthDestroyEffect extends OneShotEffect { if (player != null) { if (player.chooseUse(outcome, "Do you want to destroy " + sourcePermanent.getLogName() + "? (sacrifice two lands or have it deal 5 damage to you)", source, game)) { cost.clearPaid(); - if (cost.canPay(source, source.getSourceId(), player.getId(), game) + if (cost.canPay(source, source.getSourceId(), player.getId(), game) && player.chooseUse(Outcome.Sacrifice, "Will you sacrifice two lands? (otherwise you'll be dealt 5 damage)", source, game)) { if (!cost.pay(source, game, source.getSourceId(), player.getId(), false, null)) { player.damage(5, source.getSourceId(), game, false, true); diff --git a/Mage/src/main/java/mage/abilities/common/GodEternalDiesTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/GodEternalDiesTriggeredAbility.java index aa41b77453..a7e9205f71 100644 --- a/Mage/src/main/java/mage/abilities/common/GodEternalDiesTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/GodEternalDiesTriggeredAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.common; import mage.MageObjectReference; @@ -28,10 +27,12 @@ public class GodEternalDiesTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkEventType(GameEvent event, Game game) { - ZoneChangeEvent zEvent = (ZoneChangeEvent) event; - return zEvent.getFromZone() == Zone.BATTLEFIELD - && (zEvent.getToZone() == Zone.GRAVEYARD - || zEvent.getToZone() == Zone.EXILED); + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + return zEvent.getFromZone() == Zone.BATTLEFIELD + && (zEvent.getToZone() == Zone.GRAVEYARD || zEvent.getToZone() == Zone.EXILED); + } + return false; } @Override diff --git a/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java b/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java index 31e6d3424e..ef3dad3208 100644 --- a/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/UnearthAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.keyword; import mage.abilities.Ability; @@ -19,19 +18,17 @@ import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; /** - * * @author BetaSteward_at_googlemail.com - * - * + *

+ *

* 702.82. Unearth - * + *

* 702.82a Unearth is an activated ability that functions while the card with * unearth is in a graveyard. "Unearth [cost]" means "[Cost]: Return this card * from your graveyard to the battlefield. It gains haste. Exile it at the * beginning of the next end step. If it would leave the battlefield, exile it * instead of putting it anywhere else. Activate this ability only any time you * could cast a sorcery." - * */ public class UnearthAbility extends ActivatedAbilityImpl { @@ -111,7 +108,7 @@ class UnearthLeavesBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean checksEventType(GameEvent event, Game game) { - return EventType.ZONE_CHANGE == event.getType(); + return event.getType() == EventType.ZONE_CHANGE; } @Override