forked from External/mage
Conditional target adjuster (#12585)
* Add ReplacingTargetAdjuster * Use new target adjuster * Change name to ConditionalTargetAdjuster, don't use blueprint * Take a Targets list * Add keepOldTargets option * Add missed DamagedPlayerControlsTargetAdjuster to Sigil of Sleep * Cards using updated ConditionalTargetAdjuster * BLB gift cards currently implemented * fix wrong default for keepOldTargets * Fix Urborg Repossession missing 1st target tag
This commit is contained in:
parent
78649c1a62
commit
a6e66d6209
26 changed files with 188 additions and 487 deletions
|
|
@ -0,0 +1,62 @@
|
|||
package mage.target.targetadjustment;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.target.Target;
|
||||
import mage.target.Targets;
|
||||
|
||||
/**
|
||||
* @author notgreat
|
||||
*/
|
||||
public class ConditionalTargetAdjuster implements TargetAdjuster {
|
||||
private final Condition condition;
|
||||
private final boolean keepOldTargets;
|
||||
private final Targets replacementTargets;
|
||||
|
||||
/**
|
||||
* If the condition is true, replace the target
|
||||
*
|
||||
* @param condition The condition to be checked
|
||||
* @param replacementTarget The target to use if the condition is true.
|
||||
*/
|
||||
public ConditionalTargetAdjuster(Condition condition, Target replacementTarget) {
|
||||
this(condition, false, new Targets(replacementTarget));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the condition is true, change the target list
|
||||
*
|
||||
* @param condition The condition to be checked
|
||||
* @param keepOldTargets Add to the targets list instead of replacing it entirely
|
||||
* @param replacementTarget The target to use if the condition is true. Can also take a Targets list
|
||||
*/
|
||||
public ConditionalTargetAdjuster(Condition condition, boolean keepOldTargets, Target replacementTarget) {
|
||||
this(condition, keepOldTargets, new Targets(replacementTarget));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the condition is true, change the target list with multiple targets at once
|
||||
*
|
||||
* @param condition The condition to be checked
|
||||
* @param keepOldTargets Add to the targets list instead of replacing it entirely
|
||||
* @param replacementTargets The targets list to use if the condition is true.
|
||||
*/
|
||||
public ConditionalTargetAdjuster(Condition condition, boolean keepOldTargets, Targets replacementTargets) {
|
||||
this.condition = condition;
|
||||
this.keepOldTargets = keepOldTargets;
|
||||
this.replacementTargets = replacementTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
if (condition.apply(game, ability)) {
|
||||
if (!keepOldTargets) {
|
||||
ability.getTargets().clear();
|
||||
}
|
||||
for (Target target : replacementTargets) {
|
||||
ability.addTarget(target.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue