From 6a9a4c78ca13f649b7058605daa7a1e4099a4e56 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 9 May 2023 16:14:05 +0400 Subject: [PATCH] Shared Fate - fixed game error (NPE error) --- Mage.Sets/src/mage/cards/s/SharedFate.java | 32 ++++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/Mage.Sets/src/mage/cards/s/SharedFate.java b/Mage.Sets/src/mage/cards/s/SharedFate.java index 9f65e6ff70..ec19c3977c 100644 --- a/Mage.Sets/src/mage/cards/s/SharedFate.java +++ b/Mage.Sets/src/mage/cards/s/SharedFate.java @@ -1,6 +1,5 @@ package mage.cards.s; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.AsThoughEffectImpl; @@ -18,6 +17,8 @@ import mage.players.PlayerList; import mage.target.common.TargetOpponent; import mage.util.CardUtil; +import java.util.UUID; + /** * @author emerald000 / HCrescent */ @@ -42,6 +43,14 @@ public final class SharedFate extends CardImpl { public SharedFate copy() { return new SharedFate(this); } + + static String prepareExileKey(Game game, Ability source, Permanent sourcePermanent, UUID affectedControllerId) { + return String.format("%s_%d_%s", + source.getSourceId().toString(), + sourcePermanent == null ? 0 : sourcePermanent.getZoneChangeCounter(game), + affectedControllerId.toString() + ); + } } class SharedFateReplacementEffect extends ReplacementEffectImpl { @@ -83,9 +92,9 @@ class SharedFateReplacementEffect extends ReplacementEffectImpl { if (!playersInRange.contains(chosenPlayer.getId())) { game.informPlayers( - "Nothing exiled. " + playerToDraw.getLogName() - + " chose to exile from " + chosenPlayer.getLogName() + "'s library. " - + "That player is outside of " + controller.getLogName() + "'s range of influence." + "Nothing exiled. " + playerToDraw.getLogName() + + " chose to exile from " + chosenPlayer.getLogName() + "'s library. " + + "That player is outside of " + controller.getLogName() + "'s range of influence." ); return false; } @@ -97,10 +106,9 @@ class SharedFateReplacementEffect extends ReplacementEffectImpl { return false; } - playerToDraw.moveCardsToExile( - card, source, game, false, - CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + playerToDraw.getId().toString(), game), - sourcePermanent.getIdName() + "-" + sourcePermanent.getZoneChangeCounter(game) + " (" + playerToDraw.getName() + ')'); + UUID exileId = CardUtil.getExileZoneId(SharedFate.prepareExileKey(game, source, sourcePermanent, playerToDraw.getId()), game); + String exileName = sourcePermanent.getIdName() + "-" + sourcePermanent.getZoneChangeCounter(game) + " (" + playerToDraw.getName() + ')'; + playerToDraw.moveCardsToExile(card, source, game, false, exileId, exileName); card.setFaceDown(true, game); return true; } @@ -140,8 +148,8 @@ class SharedFatePlayEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { if (game.getState().getZone(objectId) == Zone.EXILED) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + affectedControllerId.toString(), game); + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); + UUID exileId = CardUtil.getExileZoneId(SharedFate.prepareExileKey(game, source, sourcePermanent, affectedControllerId), game); ExileZone exileZone = game.getExile().getExileZone(exileId); return exileZone != null && exileZone.contains(objectId); } @@ -173,8 +181,8 @@ class SharedFateLookEffect extends AsThoughEffectImpl { @Override public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) { if (game.getState().getZone(objectId) == Zone.EXILED) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + affectedControllerId.toString(), game); + Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); + UUID exileId = CardUtil.getExileZoneId(SharedFate.prepareExileKey(game, source, sourcePermanent, affectedControllerId), game); ExileZone exileZone = game.getExile().getExileZone(exileId); if (exileZone != null && exileZone.contains(objectId)) { Card card = game.getCard(objectId);