Fixed NullPointerException when Accursed Witch transforms (#5571)

* Fixed NullPointerException when Accursed Witch transforms

Feedback issue: #5529
Aura replacement code tried to remove the second face from the original zone which had ownerId == null. Now, we remember the first face (the original card) and remove it from the old zone before creating a permanent out of the second face.

* Accursed Witch's death trigger now requires targetting opponent instead of using aura replacement effects

Feedback issue: #5529
Previously you could attach Infectious Curse to either player and get around hexproof
The ability text has also been updated to match the Oracle text of Accursed Witch.
This commit is contained in:
Brik Royster 2019-02-03 17:40:46 -08:00 committed by Jeff Wadsworth
parent b36465e5c9
commit fce93c66e1
3 changed files with 22 additions and 7 deletions

View file

@ -18,6 +18,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetOpponent;
import mage.util.CardUtil;
import java.util.UUID;
@ -41,7 +42,9 @@ public final class AccursedWitch extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new AccursedWitchSpellsCostReductionEffect()));
// When Accursed Witch dies, return it to the battlefield transformed under your control attached to target opponent.
this.addAbility(new TransformAbility());
this.addAbility(new DiesTriggeredAbility(new AccursedWitchReturnTransformedEffect()));
Ability ability = new DiesTriggeredAbility(new AccursedWitchReturnTransformedEffect());
ability.addTarget(new TargetOpponent());
this.addAbility(ability);
}
private AccursedWitch(final AccursedWitch card) {
@ -58,7 +61,7 @@ class AccursedWitchReturnTransformedEffect extends OneShotEffect {
AccursedWitchReturnTransformedEffect() {
super(Outcome.PutCardInPlay);
this.staticText = "Put {this} from your graveyard onto the battlefield transformed";
this.staticText = "Put {this} from your graveyard onto the battlefield transformed under your control attached to target opponent";
}
private AccursedWitchReturnTransformedEffect(final AccursedWitchReturnTransformedEffect effect) {
@ -73,14 +76,19 @@ class AccursedWitchReturnTransformedEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !(game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD)) {
Player attachTo = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || !(game.getState().getZone(source.getSourceId()) == Zone.GRAVEYARD) || attachTo == null) {
return false;
}
game.getState().setValue(TransformAbility.VALUE_KEY_ENTER_TRANSFORMED + source.getSourceId(), Boolean.TRUE);
UUID secondFaceId = game.getCard(source.getSourceId()).getSecondCardFace().getId();
game.getState().setValue("attachTo:" + secondFaceId, attachTo.getId());
//note: should check for null after game.getCard
Card card = game.getCard(source.getSourceId());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
attachTo.addAttachment(card.getId(), game);
}
}
return true;
}