Added common interface to conditional effects (#9208)

This commit is contained in:
Alex Vasile 2022-07-04 20:28:54 -04:00 committed by GitHub
parent 5c54eccffd
commit 78f3547644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 62 additions and 1 deletions

View file

@ -95,4 +95,9 @@ public class ConditionalAsThoughEffect extends AsThoughEffectImpl {
public ConditionalAsThoughEffect copy() {
return new ConditionalAsThoughEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -192,4 +192,9 @@ public class ConditionalContinuousEffect extends ContinuousEffectImpl {
if (this.otherwiseEffect != null) res.add(this.otherwiseEffect);
return res;
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -125,4 +125,8 @@ public class ConditionalContinuousRuleModifyingEffect extends ContinuousRuleModi
return effect.getInfoMessage(source, event, game); //To change body of generated methods, choose Tools | Templates.
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -83,4 +83,9 @@ public class ConditionalCostModificationEffect extends CostModificationEffectImp
public ConditionalCostModificationEffect copy() {
return new ConditionalCostModificationEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -85,4 +85,9 @@ public class ConditionalManaEffect extends ManaEffect {
}
return mana;
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -82,4 +82,9 @@ public class ConditionalOneShotEffect extends OneShotEffect {
}
return effects.getText(mode) + ". If " + condition.toString() + ", " + otherwiseEffects.getText(mode);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -137,4 +137,8 @@ public class ConditionalPreventionEffect extends PreventionEffectImpl {
return new ConditionalPreventionEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -16,7 +16,7 @@ import mage.game.events.GameEvent;
*
* @author LevelX2
*/
public class ConditionalReplacementEffect extends ReplacementEffectImpl {
public class ConditionalReplacementEffect extends ReplacementEffectImpl {
protected ReplacementEffect effect;
protected ReplacementEffect otherwiseEffect;
@ -127,4 +127,9 @@ public class ConditionalReplacementEffect extends ReplacementEffectImpl {
public ConditionalReplacementEffect copy() {
return new ConditionalReplacementEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -150,4 +150,8 @@ public class ConditionalRequirementEffect extends RequirementEffect {
return new ConditionalRequirementEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -149,4 +149,8 @@ public class ConditionalRestrictionEffect extends RestrictionEffect {
return new ConditionalRestrictionEffect(this);
}
@Override
public Condition getCondition() {
return condition;
}
}

View file

@ -2,6 +2,7 @@ package mage.abilities.effects;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.condition.Condition;
import mage.constants.EffectType;
import mage.constants.Outcome;
import mage.game.Game;
@ -67,4 +68,18 @@ public interface Effect extends Serializable, Copyable<Effect> {
Effect concatBy(String concatPrefix);
String getConcatPrefix();
/**
* Used to check if this is a conditional version without needed any Java reflection hacks or chained instanceof checks.
* Only conditions on the activation of the ability are checked, and not on how the effects can be used.
* E.g. For a conditional mana ability this will only return the condition under which it can be activated,
* and NOT the conditions on the mane produced.
*
* Assumed that if the returned condition is null then this is not a conditional version, or that it does not matter.
*
* @return
*/
public default Condition getCondition() {
return null;
}
}