forked from External/mage
minor simplification to ConditionalTargetAdjuster
protect internal Targets list
This commit is contained in:
parent
e8808c3ae3
commit
d9287adea3
1 changed files with 9 additions and 20 deletions
|
|
@ -11,7 +11,7 @@ import mage.target.Targets;
|
|||
*/
|
||||
public class ConditionalTargetAdjuster implements TargetAdjuster {
|
||||
private final Condition condition;
|
||||
private final boolean keepOldTargets;
|
||||
private final boolean keepExistingTargets;
|
||||
private final Targets replacementTargets;
|
||||
|
||||
/**
|
||||
|
|
@ -21,37 +21,26 @@ public class ConditionalTargetAdjuster implements TargetAdjuster {
|
|||
* @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));
|
||||
this(condition, false, 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.
|
||||
* @param condition The condition to be checked
|
||||
* @param keepExistingTargets if true, don't clear existing targets when adding the new ones
|
||||
* @param replacementTargets Targets to be added if the condition is true
|
||||
*/
|
||||
public ConditionalTargetAdjuster(Condition condition, boolean keepOldTargets, Targets replacementTargets) {
|
||||
public ConditionalTargetAdjuster(Condition condition, boolean keepExistingTargets, Target... replacementTargets) {
|
||||
this.condition = condition;
|
||||
this.keepOldTargets = keepOldTargets;
|
||||
this.replacementTargets = replacementTargets;
|
||||
this.keepExistingTargets = keepExistingTargets;
|
||||
this.replacementTargets = new Targets(replacementTargets);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
if (condition.apply(game, ability)) {
|
||||
if (!keepOldTargets) {
|
||||
if (!keepExistingTargets) {
|
||||
ability.getTargets().clear();
|
||||
}
|
||||
for (Target target : replacementTargets) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue