mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 14:32:06 -08:00
refactor: add new simpler technique for intervening if conditions on triggered abilities (#13037)
too many usages to fix all at once, plus condition text needs updating, but this will give a cleaner option for new implementations
This commit is contained in:
parent
fb71ce8c85
commit
8a8773971d
19 changed files with 153 additions and 122 deletions
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
|
||||
|
|
@ -54,6 +54,8 @@ public interface TriggeredAbility extends Ability {
|
|||
*/
|
||||
TriggeredAbility withRuleTextReplacement(boolean replaceRuleText);
|
||||
|
||||
TriggeredAbility withInterveningIf(Condition condition);
|
||||
|
||||
boolean checkInterveningIfClause(Game game);
|
||||
|
||||
boolean isOptional();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.common.*;
|
||||
import mage.constants.AbilityType;
|
||||
|
|
@ -25,6 +26,7 @@ import java.util.UUID;
|
|||
public abstract class TriggeredAbilityImpl extends AbilityImpl implements TriggeredAbility {
|
||||
|
||||
private boolean optional;
|
||||
private Condition interveningIfCondition;
|
||||
private boolean leavesTheBattlefieldTrigger;
|
||||
private int triggerLimitEachTurn = Integer.MAX_VALUE; // for "triggers only once|twice each turn"
|
||||
private boolean doOnlyOnceEachTurn = false;
|
||||
|
|
@ -54,6 +56,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
protected TriggeredAbilityImpl(final TriggeredAbilityImpl ability) {
|
||||
super(ability);
|
||||
this.optional = ability.optional;
|
||||
this.interveningIfCondition = ability.interveningIfCondition;
|
||||
this.leavesTheBattlefieldTrigger = ability.leavesTheBattlefieldTrigger;
|
||||
this.triggerLimitEachTurn = ability.triggerLimitEachTurn;
|
||||
this.doOnlyOnceEachTurn = ability.doOnlyOnceEachTurn;
|
||||
|
|
@ -174,9 +177,15 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TriggeredAbility withInterveningIf(Condition interveningIfCondition) {
|
||||
this.interveningIfCondition = interveningIfCondition;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkInterveningIfClause(Game game) {
|
||||
return true;
|
||||
return interveningIfCondition == null || interveningIfCondition.apply(game, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -239,6 +248,17 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
|
||||
sb.append(triggerPhrase == null ? "" : triggerPhrase);
|
||||
|
||||
if (interveningIfCondition != null) {
|
||||
String conditionText = interveningIfCondition.toString();
|
||||
if (replaceRuleText && triggerPhrase != null && triggerPhrase.contains("{this}")) {
|
||||
conditionText = conditionText.replace("{this}", "it");
|
||||
}
|
||||
if (!conditionText.startsWith("if ")) {
|
||||
sb.append("if ");
|
||||
}
|
||||
sb.append(conditionText).append(", ");
|
||||
}
|
||||
|
||||
String superRule = super.getRule(true);
|
||||
if (!superRule.isEmpty()) {
|
||||
String ruleLow = superRule.toLowerCase(Locale.ENGLISH);
|
||||
|
|
@ -273,7 +293,7 @@ public abstract class TriggeredAbilityImpl extends AbilityImpl implements Trigge
|
|||
break;
|
||||
default:
|
||||
// No card with that behavior yet, so feel free to change the text once one exist
|
||||
sb.append(CardUtil.numberToText(triggerLimitEachTurn) + " times");
|
||||
sb.append(CardUtil.numberToText(triggerLimitEachTurn)).append(" times");
|
||||
}
|
||||
sb.append(" each turn.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,4 +16,9 @@ public enum FatefulHourCondition implements Condition {
|
|||
Player player = game.getPlayer(source.getControllerId());
|
||||
return player != null && player.getLife() <= 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "you have 5 or less life";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.constants.Zone;
|
||||
|
|
@ -42,4 +40,10 @@ public enum SuspendedCondition implements Condition {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{this} is suspended";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue