Remove ConditionalTriggeredAbility and add trigger condition into triggered abilities (#13656)

* remove ConditionalTriggeredAbility

* a few small fixes

* merge fix

* simplify phrase handling

* add documentation

* a few text fixes

* update wording
This commit is contained in:
Evan Kranzler 2025-05-23 07:03:14 -04:00 committed by GitHub
parent c42c58c67d
commit 8f83a807f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
47 changed files with 332 additions and 544 deletions

View file

@ -27,6 +27,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
private boolean optional;
private Condition interveningIfCondition;
private Condition triggerCondition;
private boolean leavesTheBattlefieldTrigger;
private int triggerLimitEachTurn = Integer.MAX_VALUE; // for "triggers only once|twice each turn"
private int triggerLimitEachGame = Integer.MAX_VALUE; // for "triggers only once|twice"
@ -57,6 +58,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
super(ability);
this.optional = ability.optional;
this.interveningIfCondition = ability.interveningIfCondition;
this.triggerCondition = ability.triggerCondition;
this.leavesTheBattlefieldTrigger = ability.leavesTheBattlefieldTrigger;
this.triggerLimitEachTurn = ability.triggerLimitEachTurn;
this.triggerLimitEachGame = ability.triggerLimitEachGame;
@ -69,7 +71,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
@Override
public void trigger(Game game, UUID controllerId, GameEvent triggeringEvent) {
//20091005 - 603.4
if (checkInterveningIfClause(game)) {
if (checkInterveningIfClause(game) && checkTriggerCondition(game)) {
updateTurnCount(game);
updateGameCount(game);
game.addTriggeredAbility(this, triggeringEvent);
@ -228,6 +230,28 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
return interveningIfCondition == null || interveningIfCondition.apply(game, this);
}
@Override
public TriggeredAbility withTriggerCondition(Condition condition) {
this.triggerCondition = condition;
if (this.triggerPhrase != null && !condition.toString().isEmpty()) {
this.setTriggerPhrase(
this.triggerPhrase.substring(0, this.triggerPhrase.length() - 2) + ' ' +
(condition.toString().startsWith("during") ? "" : "while ") + condition + ", "
);
}
return this;
}
@Override
public Condition getTriggerCondition() {
return triggerCondition;
}
@Override
public boolean checkTriggerCondition(Game game) {
return triggerCondition == null || triggerCondition.apply(game, this);
}
@Override
public boolean resolve(Game game) {
if (!checkInterveningIfClause(game)) {