Skip to content

Commit

Permalink
Fix trigger targeting itself (#6973)
Browse files Browse the repository at this point in the history
Co-authored-by: tool4EvEr <[email protected]>
  • Loading branch information
tool4ever and tool4EvEr authored Feb 5, 2025
1 parent c44b105 commit dee2150
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ else if (sa.hasParam("DefinedMagnet")) {
source = changingTgtSA.getTargetCard();
}
Predicate<GameObject> filter = sa.hasParam("TargetRestriction") ? GameObjectPredicates.restriction(sa.getParam("TargetRestriction").split(","), activator, source, sa) : null;
// TODO Creature.Other might not work yet as it should
TargetChoices newTarget = chooser.getController().chooseNewTargetsFor(changingTgtSA, filter, false);
changingTgtSI.updateTarget(newTarget, sa.getHostCard());
}
Expand Down
7 changes: 4 additions & 3 deletions forge-game/src/main/java/forge/game/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1717,15 +1717,16 @@ public final Card playLandNoCheck(final Card land, SpellAbility cause) {
final Card c = game.getAction().moveTo(getZone(ZoneType.Battlefield), land, cause);
game.updateLastStateForCard(c);

// play a sound
game.fireEvent(new GameEventLandPlayed(this, land));

// Run triggers
runParams.put(AbilityKey.SpellAbility, cause);
game.getTriggerHandler().runTrigger(TriggerType.LandPlayed, runParams, false);

game.getStack().unfreezeStack();
addLandPlayedThisTurn();

// play a sound
game.fireEvent(new GameEventLandPlayed(this, land));

return c;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import forge.game.staticability.StaticAbilityMustTarget;
import forge.game.trigger.Trigger;
import forge.game.trigger.TriggerType;
import forge.game.trigger.WrappedAbility;
import forge.game.zone.ZoneType;

//only SpellAbility can go on the stack
Expand Down Expand Up @@ -1072,11 +1073,9 @@ public String getCostDescription() {
}

public void rebuiltDescription() {

// SubAbilities don't have Costs or Cost descriptors

String sb = getCostDescription() +
getParam("SpellDescription");
String sb = getCostDescription() + getParam("SpellDescription");
setDescription(sb);
}

Expand Down Expand Up @@ -1991,7 +1990,11 @@ public final List<GameObject> getUniqueTargets() {
return targets;
}

public boolean canTargetSpellAbility(final SpellAbility topSA) {
public boolean canTargetSpellAbility(SpellAbility topSA) {
if (topSA.isWrapper()) {
topSA = ((WrappedAbility) topSA).getWrappedAbility();
}

final TargetRestrictions tgt = getTargetRestrictions();

if (this.equals(topSA)) {
Expand Down
20 changes: 14 additions & 6 deletions forge-game/src/main/java/forge/game/trigger/WrappedAbility.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public String yieldKey() {
// a real solution would include only the triggering information that actually is used, but that's a major change
@Override
public String toUnsuppressedString() {
String desc = this.getStackDescription(); /* use augmented stack description as string for wrapped things */
String desc = this.getStackDescription(false); /* use augmented stack description as string for wrapped things */
String card = getHostCard().toString();
if (!desc.contains(card) && desc.contains(" this ")) { /* a hack for Evolve and similar that don't have CARDNAME */
return card + ": " + desc;
Expand All @@ -332,15 +332,23 @@ public String toUnsuppressedString() {

@Override
public String getStackDescription() {
return getStackDescription(true);
}

public String getStackDescription(boolean withTargets) {
final Trigger regtrig = getTrigger();
if (regtrig == null) return "";
final StringBuilder sb =
new StringBuilder(regtrig.replaceAbilityText(regtrig.toString(true), this, true));
List<TargetChoices> allTargets = sa.getAllTargetChoices();
if (!allTargets.isEmpty() && !ApiType.Charm.equals(sa.getApi())) {
sb.append(" (Targeting: ");
sb.append(allTargets);
sb.append(")");

// prevent text growing too long when SA target other in a chain and also potential StackOverflow
if (withTargets) {
List<TargetChoices> allTargets = sa.getAllTargetChoices();
if (!allTargets.isEmpty() && !ApiType.Charm.equals(sa.getApi())) {
sb.append(" (Targeting: ");
sb.append(allTargets);
sb.append(")");
}
}

String important = regtrig.getImportantStackObjects(this);
Expand Down

0 comments on commit dee2150

Please sign in to comment.