Merge pull request #13683 from magefree/from-card

Update effects that find a permanent from a card put to battlefield
This commit is contained in:
xenohedron 2025-05-29 01:00:56 -04:00 committed by GitHub
commit 77830dd24a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
133 changed files with 465 additions and 395 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

@ -13,6 +13,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetCreaturePermanent;
import mage.util.CardUtil;
/**
* @author LevelX2
@ -42,7 +43,7 @@ public class BecomesAuraAttachToManifestSourceEffect extends OneShotEffect {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
new ManifestEffect(1).apply(game, source);
Permanent enchantedCreature = game.getPermanent(card.getId());
Permanent enchantedCreature = CardUtil.getPermanentFromCardPutToBattlefield(card, game);
if (enchantedCreature != null) {
enchantedCreature.addAttachment(enchantment.getId(), source, game);
FilterCreaturePermanent filter = new FilterCreaturePermanent();

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

@ -13,6 +13,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
public class ReturnCreatureFromGraveyardToBattlefieldAndGainHasteEffect extends OneShotEffect {
@ -39,7 +40,7 @@ public class ReturnCreatureFromGraveyardToBattlefieldAndGainHasteEffect extends
Card card = game.getCard(source.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
Permanent permanent = CardUtil.getPermanentFromCardPutToBattlefield(card, game);
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));

View file

@ -30,6 +30,7 @@ import mage.target.TargetPlayer;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetCreaturePermanent;
import mage.target.targetpointer.FixedTarget;
import mage.util.CardUtil;
import mage.util.RandomUtil;
/**
@ -158,7 +159,7 @@ class ThroneOfTheDeadThreeEffect extends OneShotEffect {
}
if (card != null) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent permanent = game.getPermanent(card.getId());
Permanent permanent = CardUtil.getPermanentFromCardPutToBattlefield(card, game);
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(3), source, game);
game.addEffect(new GainAbilityTargetEffect(HexproofAbility.getInstance(), Duration.UntilYourNextTurn)

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
*