fixed various instances of getting source name (fixes #8531, fixes #8528)

This commit is contained in:
Evan Kranzler 2021-12-24 19:30:31 -05:00
parent 8791f30b4a
commit a6fcaab698
29 changed files with 54 additions and 94 deletions

View file

@ -89,11 +89,10 @@ public class ExileFromGraveCost extends CostImpl {
}
Cards cardsToExile = new CardsImpl();
cardsToExile.addAll(exiledCards);
Card sourceCard = game.getCard(source.getSourceId());
controller.moveCardsToExile(
cardsToExile.getCards(game), source, game, true,
CardUtil.getExileZoneId(game, source),
sourceCard.getName()
CardUtil.getSourceName(game, source)
);
if (setTargetPointer) {
source.getEffects().setTargetPointer(new FixedTargets(cardsToExile, game));

View file

@ -1,6 +1,5 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Cards;
@ -45,8 +44,7 @@ public class ExileAllEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
if (controller == null) {
return false;
}
Cards cards = new CardsImpl();
@ -54,7 +52,7 @@ public class ExileAllEffect extends OneShotEffect {
filter, source.getControllerId(), source.getSourceId(), game
).stream().forEach(cards::add);
if (forSource) {
return controller.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), sourceObject.getName());
return controller.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
return controller.moveCards(cards, Zone.EXILED, source, game);

View file

@ -1,7 +1,6 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
@ -55,7 +54,6 @@ public class ExileFromZoneTargetEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
MageObject mageObject = source.getSourceObject(game);
if (player == null) {
return false;
}
@ -75,7 +73,7 @@ public class ExileFromZoneTargetEffect extends OneShotEffect {
target.chooseTarget(Outcome.Exile, player.getId(), source, game);
Cards cards = new CardsImpl(target.getTargets());
if (withSource) {
return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), mageObject.getName());
return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
}
return player.moveCards(cards, Zone.EXILED, source, game);
}

View file

@ -58,8 +58,7 @@ public class ExileTopXMayPlayUntilEndOfTurnEffect extends OneShotEffect {
if (cards.isEmpty()) {
return true;
}
Card sourceCard = game.getCard(source.getSourceId());
controller.moveCardsToExile(cards, source, game, true, CardUtil.getExileZoneId(game, source), sourceCard.getName());
controller.moveCardsToExile(cards, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
// remove cards that could not be moved to exile
cards.removeIf(card -> !Zone.EXILED.equals(game.getState().getZone(card.getId())));
if (!cards.isEmpty()) {

View file

@ -1,6 +1,5 @@
package mage.abilities.effects.common;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
@ -29,11 +28,10 @@ public class MistmeadowWitchEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
MageObject sourceObject = source.getSourceObject(game);
if (player == null || permanent == null || sourceObject == null) {
if (player == null || permanent == null) {
return false;
}
player.moveCardsToExile(permanent, source, game, true, CardUtil.getExileZoneId(game, source), sourceObject.getName());
player.moveCardsToExile(permanent, source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnFromExileEffect(Zone.BATTLEFIELD, "return the exiled card to the battlefield under its owner's control")), source);
return true;
}

View file

@ -1229,6 +1229,11 @@ public final class CardUtil {
return false;
}
public static String getSourceName(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
return sourceObject != null ? sourceObject.getName() : "";
}
/**
* Generates source log name to insert into log messages
*