text generation improvements (#11203)

* update ETB trigger effect text gen

* set replace for common abilities

* fix remaining

* rename method, cleanup

* more fixes, better logic
This commit is contained in:
xenohedron 2023-09-25 21:51:51 -04:00 committed by GitHub
parent 10f2ae0bbc
commit 4e561b6254
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 60 additions and 85 deletions

View file

@ -17,10 +17,6 @@ public interface TriggeredAbility extends Ability {
* This check for the relevant event types is called at first to prevent
* further actions if the current event is ignored from this triggered
* ability
*
* @param event
* @param game
* @return
*/
boolean checkEventType(GameEvent event, Game game);
@ -30,10 +26,6 @@ public interface TriggeredAbility extends Ability {
* multiple times. Because some abilities call this to check if an ability
* is relevant (e.g. Torpor Orb), so the method is called multiple times for
* the same event.
*
* @param event
* @param game
* @return
*/
boolean checkTrigger(GameEvent event, Game game);
@ -45,7 +37,10 @@ public interface TriggeredAbility extends Ability {
TriggeredAbility setDoOnlyOnceEachTurn(boolean doOnlyOnce);
TriggeredAbility setReplaceRuleText(boolean replaceRuleText);
/**
* if true, replaces "{this}" with "it" in the effect text
*/
TriggeredAbility withRuleTextReplacement(boolean replaceRuleText);
boolean checkInterveningIfClause(Game game);

View file

@ -27,7 +27,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
protected boolean leavesTheBattlefieldTrigger;
private boolean triggersOnceEachTurn = false;
private boolean doOnlyOnceEachTurn = false;
protected boolean replaceRuleText = true;
protected boolean replaceRuleText = false; // if true, replace "{this}" with "it" in effect text
private GameEvent triggerEvent = null;
private String triggerPhrase = null;
@ -131,7 +131,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
}
@Override
public TriggeredAbility setReplaceRuleText(boolean replaceRuleText) {
public TriggeredAbility withRuleTextReplacement(boolean replaceRuleText) {
this.replaceRuleText = replaceRuleText;
return this;
}
@ -220,18 +220,8 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
superRule = superRule.replaceFirst(" (become|block|deal|discard|gain|get|lose|mill|sacrifice)s? ", " $1 ");
}
}
if (replaceRuleText
&& triggerPhrase != null
&& triggerPhrase.contains("{this}")
&& !triggerPhrase.contains("other")
&& !triggerPhrase.contains(" of a ")
&& !triggerPhrase.contains(" by a ")
&& !triggerPhrase.contains(" to a ")
&& !triggerPhrase.contains(" blocks a ")
&& (superRule.startsWith("{this}")
|| superRule.startsWith("sacrifice {this}")
)) {
superRule = superRule.replace("{this} ", "it ");
if (replaceRuleText && triggerPhrase != null) {
superRule = superRule.replaceFirst("^(sacrifice )?\\{this\\}", "$1it");
}
sb.append(superRule);
if (triggersOnceEachTurn) {

View file

@ -16,6 +16,7 @@ public class AttacksAloneSourceTriggeredAbility extends TriggeredAbilityImpl {
public AttacksAloneSourceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect);
setTriggerPhrase("Whenever {this} attacks alone, ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected AttacksAloneSourceTriggeredAbility(final AttacksAloneSourceTriggeredAbility ability) {

View file

@ -24,6 +24,7 @@ public class AttacksAndIsNotBlockedTriggeredAbility extends TriggeredAbilityImpl
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
setTriggerPhrase("Whenever {this} attacks and isn't blocked, ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected AttacksAndIsNotBlockedTriggeredAbility(final AttacksAndIsNotBlockedTriggeredAbility ability) {

View file

@ -16,6 +16,7 @@ public class AttacksOrBlocksTriggeredAbility extends TriggeredAbilityImpl {
} else {
setTriggerPhrase("Whenever {this} attacks or blocks, ");
}
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected AttacksOrBlocksTriggeredAbility(final AttacksOrBlocksTriggeredAbility ability) {

View file

@ -35,6 +35,7 @@ public class AttacksTriggeredAbility extends TriggeredAbilityImpl {
this.text = text;
this.setTargetPointer = setTargetPointer;
setTriggerPhrase("Whenever {this} attacks, ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected AttacksTriggeredAbility(final AttacksTriggeredAbility ability) {

View file

@ -22,6 +22,7 @@ public class BecomesBlockedSourceTriggeredAbility extends TriggeredAbilityImpl {
super(Zone.BATTLEFIELD, effect, optional);
this.setTargetPointer = setTargetPointer;
setTriggerPhrase("Whenever {this} becomes blocked, ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected BecomesBlockedSourceTriggeredAbility(final BecomesBlockedSourceTriggeredAbility ability) {

View file

@ -19,6 +19,7 @@ public class BecomesTappedSourceTriggeredAbility extends TriggeredAbilityImpl {
public BecomesTappedSourceTriggeredAbility(Effect effect, boolean isOptional) {
super(Zone.BATTLEFIELD, effect, isOptional);
setTriggerPhrase("Whenever {this} becomes tapped, ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected BecomesTappedSourceTriggeredAbility(final BecomesTappedSourceTriggeredAbility ability) {

View file

@ -41,6 +41,7 @@ public class BecomesTargetSourceTriggeredAbility extends TriggeredAbilityImpl {
|| effect instanceof ShuffleIntoLibrarySourceEffect
|| effect instanceof ExileSourceEffect);
setTriggerPhrase((textWhen ? "When" : "Whenever") + " {this} becomes the target of " + filter.getMessage() + ", ");
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
protected BecomesTargetSourceTriggeredAbility(final BecomesTargetSourceTriggeredAbility ability) {

View file

@ -14,13 +14,14 @@ public class CycleTriggeredAbility extends ZoneChangeTriggeredAbility {
public CycleTriggeredAbility(Effect effect, boolean optional) {
super(Zone.ALL, effect, "When you cycle {this}, ", optional);
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
public CycleTriggeredAbility(Effect effect) {
this(effect, false);
}
public CycleTriggeredAbility(CycleTriggeredAbility ability) {
protected CycleTriggeredAbility(CycleTriggeredAbility ability) {
super(ability);
}

View file

@ -15,6 +15,7 @@ public class DiesSourceTriggeredAbility extends ZoneChangeTriggeredAbility {
public DiesSourceTriggeredAbility(Effect effect, boolean optional) {
super(Zone.BATTLEFIELD, Zone.GRAVEYARD, effect, "When {this} dies, ", optional);
this.replaceRuleText = true; // default true to replace "{this}" with "it"
}
public DiesSourceTriggeredAbility(Effect effect) {

View file

@ -11,27 +11,18 @@ import mage.game.events.GameEvent;
*/
public class EntersBattlefieldTriggeredAbility extends TriggeredAbilityImpl {
protected boolean ignoreRulesGeneration; // use it with custom rules (if you don't want ETB auto-generated text)
protected String etbFlavorWord = null;
public EntersBattlefieldTriggeredAbility(Effect effect) {
this(effect, false);
}
public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional) {
this(effect, optional, false);
}
public EntersBattlefieldTriggeredAbility(Effect effect, boolean optional, boolean ignoreRulesGeneration) {
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.ignoreRulesGeneration = ignoreRulesGeneration;
this.replaceRuleText = true; // default true to replace "{this}" with "it"
setTriggerPhrase("When {this} enters the battlefield, ");
}
protected EntersBattlefieldTriggeredAbility(final EntersBattlefieldTriggeredAbility ability) {
super(ability);
this.ignoreRulesGeneration = ability.ignoreRulesGeneration;
this.etbFlavorWord = ability.etbFlavorWord;
}
@Override

View file

@ -12,7 +12,6 @@ public class EntersBattlefieldUntappedTriggeredAbility extends EntersBattlefield
public EntersBattlefieldUntappedTriggeredAbility(Effect effect, boolean optional) {
super(effect, optional);
this.ignoreRulesGeneration = true;
setTriggerPhrase("When {this} enters the battlefield untapped, ");
}
@ -33,4 +32,4 @@ public class EntersBattlefieldUntappedTriggeredAbility extends EntersBattlefield
Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null && !permanent.isTapped();
}
}
}

View file

@ -5,7 +5,6 @@ import mage.abilities.effects.Effect;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.target.targetpointer.FixedTarget;
/**
@ -14,7 +13,7 @@ import mage.target.targetpointer.FixedTarget;
public class TurnedFaceUpSourceTriggeredAbility extends TriggeredAbilityImpl {
private boolean setTargetPointer;
private final boolean setTargetPointer;
public TurnedFaceUpSourceTriggeredAbility(Effect effect) {
this(effect, false);
@ -30,6 +29,7 @@ public class TurnedFaceUpSourceTriggeredAbility extends TriggeredAbilityImpl {
this.setWorksFaceDown(true);
this.setTargetPointer = setTargetPointer;
setTriggerPhrase("When {this} is turned face up, ");
this.replaceRuleText = true;
}
protected TurnedFaceUpSourceTriggeredAbility(final TurnedFaceUpSourceTriggeredAbility ability) {

View file

@ -21,7 +21,7 @@ public class FabricateAbility extends EntersBattlefieldTriggeredAbility {
private final int value;
public FabricateAbility(int value) {
super(new FabricateEffect(value), false, true);
super(new FabricateEffect(value), false);
this.value = value;
}