mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
refactor: added code example for rules auto-replacement in creature's ETB (related to #12791)
This commit is contained in:
parent
1774c2ec36
commit
0d0661cc92
4 changed files with 26 additions and 1 deletions
|
|
@ -104,4 +104,6 @@ public interface TriggeredAbility extends Ability {
|
|||
GameEvent getTriggerEvent();
|
||||
|
||||
TriggeredAbility setTriggerPhrase(String triggerPhrase);
|
||||
|
||||
String getTriggerPhrase();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,11 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTriggerPhrase() {
|
||||
return this.triggerPhrase;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTriggerEvent(GameEvent triggerEvent) {
|
||||
this.triggerEvent = triggerEvent;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@ public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
|
|||
|
||||
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)
|
||||
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, ");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue