refactor: added code example for rules auto-replacement in creature's ETB (related to #12791)

This commit is contained in:
Oleg Agafonov 2025-02-09 13:51:22 +04:00
parent 1774c2ec36
commit 0d0661cc92
4 changed files with 26 additions and 1 deletions

View file

@ -104,4 +104,6 @@ public interface TriggeredAbility extends Ability {
GameEvent getTriggerEvent(); GameEvent getTriggerEvent();
TriggeredAbility setTriggerPhrase(String triggerPhrase); TriggeredAbility setTriggerPhrase(String triggerPhrase);
String getTriggerPhrase();
} }

View file

@ -132,6 +132,11 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return this; return this;
} }
@Override
public String getTriggerPhrase() {
return this.triggerPhrase;
}
@Override @Override
public void setTriggerEvent(GameEvent triggerEvent) { public void setTriggerEvent(GameEvent triggerEvent) {
this.triggerEvent = triggerEvent; this.triggerEvent = triggerEvent;

View file

@ -17,7 +17,11 @@ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional) { public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional) {
super(Zone.ALL, effect, optional); // Zone.All because a creature with trigger can be put into play and be sacrificed during the resolution of an effect (discard Obstinate Baloth with Smallpox) super(Zone.ALL, effect, optional); // Zone.All because a creature with trigger can be put into play and be sacrificed during the resolution of an effect (discard Obstinate Baloth with Smallpox)
this.withRuleTextReplacement(true); // default true to replace "{this}" with "it" this.withRuleTextReplacement(true); // default true to replace "{this}" with "it" or "this creature"
// warning, it's impossible to add text auto-replacement for creatures here (When this creature enters),
// so it was implemented in CardImpl.addAbility instead
// see https://github.com/magefree/mage/issues/12791
setTriggerPhrase("When {this} enters, "); setTriggerPhrase("When {this} enters, ");
} }

View file

@ -343,6 +343,20 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
} }
} }
} }
// rules fix: workaround to add text auto-replacement for creature's ETB
if (this.isCreature() && ability.getRule().startsWith("When {this} enters") && ability instanceof TriggeredAbility) {
TriggeredAbility triggeredAbility = ((TriggeredAbility) ability);
if (triggeredAbility.getTriggerPhrase() != null) {
// TODO: delete or enable after wizards update all cards, not last sets only, see https://github.com/magefree/mage/issues/12791
//triggeredAbility.setTriggerPhrase(triggeredAbility.getTriggerPhrase().replace("{this}", "this creature"));
}
}
// verify check: all creatures with ETB must use "When this creature enters" instead "When {this} enters"
if (this.isCreature() && ability.getRule().startsWith("When {this} enters")) {
// see above
//throw new IllegalArgumentException("Wrong code usage: creature's ETB ability must use text like \"When this creature enters\"");
}
} }
protected void addAbility(Ability ability, Watcher watcher) { protected void addAbility(Ability ability, Watcher watcher) {