refactor: introduce new helper method

to find permanent from card after moved to battlefield
This commit is contained in:
xenohedron 2025-04-17 19:12:50 -04:00 committed by Failure
parent 8147ebe531
commit 692a843b86
4 changed files with 12 additions and 3 deletions

View file

@ -192,7 +192,7 @@ class AnimateDeadPutOntoBattlefieldEffect extends OneShotEffect {
player.moveCards(card, Zone.BATTLEFIELD, source, game, tapped, false, false, null);
game.processAction();
Permanent creature = game.getPermanent(CardUtil.getDefaultCardSideForBattlefield(game, card).getId());
Permanent creature = CardUtil.getPermanentFromCardPutToBattlefield(card, game);
if (creature == null) {
return true;
}

View file

@ -60,7 +60,7 @@ public class PutCardIntoPlayWithHasteAndSacrificeEffect extends OneShotEffect {
return false;
}
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(CardUtil.getDefaultCardSideForBattlefield(game, card).getId());
Permanent permanent = CardUtil.getPermanentFromCardPutToBattlefield(card, game);
if (permanent == null) {
return false;
}

View file

@ -1315,6 +1315,15 @@ public final class CardUtil {
return permCard;
}
/**
* If a card object is moved to the battlefield, object id can be different (e.g. MDFC).
* Use this method to get the permanent object from the card object after move to battlefield.
* Can return null if not found on the battlefield.
*/
public static Permanent getPermanentFromCardPutToBattlefield(Card card, Game game) {
return game.getPermanent(CardUtil.getDefaultCardSideForBattlefield(game, card).getId());
}
/**
* Return card name for same name searching
*