Fix ThreeDogGalaxyNewsDJTokenEffect bug from variable shadowing

This commit is contained in:
Steven Knipe 2025-08-14 17:17:52 -07:00
parent 3ecf58a3e1
commit 5adff9bd51

View file

@ -18,14 +18,12 @@ import mage.constants.SubType;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterAttackingCreature; import mage.filter.common.FilterAttackingCreature;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.filter.predicate.mageobject.AnotherPredicate; import mage.filter.predicate.mageobject.AnotherPredicate;
import mage.filter.predicate.permanent.AttachedToSourcePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
/** /**
@ -61,24 +59,7 @@ class ThreeDogGalaxyNewsDJEffect extends OneShotEffect {
private static final FilterPermanent filter = new FilterPermanent(SubType.AURA, "Aura attached to this creature"); private static final FilterPermanent filter = new FilterPermanent(SubType.AURA, "Aura attached to this creature");
static { static {
filter.add(ThreeDogGalaxyNewsDJPredicate.instance); filter.add(AttachedToSourcePredicate.instance);
}
enum ThreeDogGalaxyNewsDJPredicate implements ObjectSourcePlayerPredicate<Permanent> {
instance;
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return input
.getSource()
.getSourceObjectIfItStillExists(game) != null
&& Optional
.ofNullable(input)
.map(ObjectSourcePlayer::getObject)
.map(Permanent::getAttachedTo)
.map(input.getSourceId()::equals)
.orElse(false);
}
} }
ThreeDogGalaxyNewsDJEffect() { ThreeDogGalaxyNewsDJEffect() {
@ -133,18 +114,18 @@ class ThreeDogGalaxyNewsDJTokenEffect extends OneShotEffect {
filter.add(AnotherPredicate.instance); filter.add(AnotherPredicate.instance);
} }
private final Permanent permanent; private final Permanent sacPermanent;
ThreeDogGalaxyNewsDJTokenEffect(Permanent permanent) { ThreeDogGalaxyNewsDJTokenEffect(Permanent permanent) {
super(Outcome.Benefit); super(Outcome.Benefit);
this.permanent = permanent != null ? permanent.copy() : null; this.sacPermanent = permanent != null ? permanent.copy() : null;
staticText = "for each other attacking creature you control, " + staticText = "for each other attacking creature you control, " +
"create a token that's a copy of that Aura attached to that creature"; "create a token that's a copy of that Aura attached to that creature";
} }
private ThreeDogGalaxyNewsDJTokenEffect(final ThreeDogGalaxyNewsDJTokenEffect effect) { private ThreeDogGalaxyNewsDJTokenEffect(final ThreeDogGalaxyNewsDJTokenEffect effect) {
super(effect); super(effect);
this.permanent = effect.permanent != null ? effect.permanent.copy() : null; this.sacPermanent = effect.sacPermanent != null ? effect.sacPermanent.copy() : null;
} }
@Override @Override
@ -154,15 +135,15 @@ class ThreeDogGalaxyNewsDJTokenEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
if (permanent == null) { if (sacPermanent == null) {
return false; return false;
} }
for (Permanent permanent : game.getBattlefield().getActivePermanents( for (Permanent attacker : game.getBattlefield().getActivePermanents(
filter, source.getControllerId(), source, game filter, source.getControllerId(), source, game
)) { )) {
new CreateTokenCopyTargetEffect() new CreateTokenCopyTargetEffect()
.setSavedPermanent(permanent) .setSavedPermanent(sacPermanent)
.setAttachedTo(permanent.getId()) .setAttachedTo(attacker.getId())
.apply(game, source); .apply(game, source);
} }
return true; return true;