- Refactored Tidehollow Sculler. The cast exception issue.

This commit is contained in:
Jeff 2019-01-18 09:00:19 -06:00
parent 232781cc1f
commit fed062fe9a

View file

@ -1,4 +1,3 @@
package mage.cards.t; package mage.cards.t;
import java.util.UUID; import java.util.UUID;
@ -32,7 +31,7 @@ import mage.util.CardUtil;
public final class TidehollowSculler extends CardImpl { public final class TidehollowSculler extends CardImpl {
public TidehollowSculler(UUID ownerId, CardSetInfo setInfo) { public TidehollowSculler(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{W}{B}"); super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{W}{B}");
this.subtype.add(SubType.ZOMBIE); this.subtype.add(SubType.ZOMBIE);
this.power = new MageInt(2); this.power = new MageInt(2);
@ -80,23 +79,30 @@ class TidehollowScullerExileEffect extends OneShotEffect {
// 6/7/2013 If Tidehollow Sculler leaves the battlefield before its first ability has resolved, // 6/7/2013 If Tidehollow Sculler leaves the battlefield before its first ability has resolved,
// its second ability will trigger. This ability will do nothing when it resolves. // its second ability will trigger. This ability will do nothing when it resolves.
// Then its first ability will resolve and exile the chosen card forever. // Then its first ability will resolve and exile the chosen card forever.
Permanent sourcePermanent = (Permanent) source.getSourceObject(game); Permanent sourcePermanent = (Permanent) source.getSourcePermanentIfItStillExists(game);
if (controller != null && opponent != null && sourcePermanent != null) { if (controller != null
&& opponent != null
&& sourcePermanent != null) {
opponent.revealCards(sourcePermanent.getName(), opponent.getHand(), game); opponent.revealCards(sourcePermanent.getName(), opponent.getHand(), game);
TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card to exile")); TargetCard target = new TargetCard(Zone.HAND, new FilterNonlandCard("nonland card to exile"));
if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) { if (controller.choose(Outcome.Exile, opponent.getHand(), target, game)) {
Card card = opponent.getHand().get(target.getFirstTarget(), game); Card card = opponent.getHand().get(target.getFirstTarget(), game);
if (card != null) { if (card != null) {
controller.moveCardToExileWithInfo(card, CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()), sourcePermanent.getIdName(), source.getSourceId(), game, Zone.HAND, true); controller.moveCardsToExile(
card,
source,
game,
true,
CardUtil.getExileZoneId(game,
source.getSourceId(),
source.getSourceObjectZoneChangeCounter()),
sourcePermanent.getIdName());
} }
} }
return true; return true;
} }
return false; return false;
} }
} }
class TidehollowScullerLeaveEffect extends OneShotEffect { class TidehollowScullerLeaveEffect extends OneShotEffect {
@ -120,8 +126,11 @@ class TidehollowScullerLeaveEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game); MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) { if (controller != null && sourceObject != null) {
int zoneChangeCounter = (sourceObject instanceof PermanentToken) ? source.getSourceObjectZoneChangeCounter() : source.getSourceObjectZoneChangeCounter() - 1; int zoneChangeCounter = (sourceObject instanceof PermanentToken)
ExileZone exZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter)); ? source.getSourceObjectZoneChangeCounter()
: source.getSourceObjectZoneChangeCounter() - 1;
ExileZone exZone = game.getExile().getExileZone(
CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter));
if (exZone != null) { if (exZone != null) {
controller.moveCards(exZone, Zone.HAND, source, game); controller.moveCards(exZone, Zone.HAND, source, game);
} }