forked from External/mage
* Implement Time Reaper, start rework * Create DamagedPlayerControlsTargetAdjuster, convert Aberrant to use it * Always add targets for EachOpponentPermanentTargetsAdjuster * Improve target name, finish Time Reaper * Convert some cards * Improve documentation, more cards * More cards, fix cards that needed to use owner instead of controller * Fix unfinished AlelaCunningConqueror changes * more cards * All remaining cards * Fix target type * Remove outdated attempt at TargetController.SOURCE_EFFECT_TARGET_POINTER * Finish removal of SOURCE_EFFECT_TARGET_POINTER * Change targetAdjuster blueprint target to be set inside setTargetAdjuster, add error checking * Always add Target Adjuster after Target * Add comment * Fix TolarianContemptTest to skip opponent with no valid targets * Forgot to git add the new abstract GenericTargetAdjuster * Test now possible after merge, fix missed ChangeOfPlans adjuster order * Text and optional-ness fixes * Always set target pointer
46 lines
1.6 KiB
Java
46 lines
1.6 KiB
Java
package mage.target.targetadjustment;
|
|
|
|
import mage.MageObject;
|
|
import mage.abilities.Ability;
|
|
import mage.abilities.dynamicvalue.DynamicValue;
|
|
import mage.abilities.dynamicvalue.common.ManacostVariableValue;
|
|
import mage.constants.ComparisonType;
|
|
import mage.filter.Filter;
|
|
import mage.filter.predicate.mageobject.PowerPredicate;
|
|
import mage.game.Game;
|
|
import mage.target.Target;
|
|
|
|
/**
|
|
* @author TheElk801, notgreat
|
|
*/
|
|
public class PowerTargetAdjuster extends GenericTargetAdjuster {
|
|
private final DynamicValue dynamicValue;
|
|
private final ComparisonType comparison;
|
|
|
|
/**
|
|
* Modifies the target to also require a power that satisfies the comparison to the dynamic value.
|
|
*
|
|
* @param value The value to be compared against
|
|
* @param compare Which comparison to use
|
|
*/
|
|
public PowerTargetAdjuster(DynamicValue value, ComparisonType compare) {
|
|
this.dynamicValue = value;
|
|
this.comparison = compare;
|
|
}
|
|
|
|
public PowerTargetAdjuster(ComparisonType comparison) {
|
|
this(ManacostVariableValue.REGULAR, comparison);
|
|
}
|
|
|
|
|
|
@Override
|
|
public void adjustTargets(Ability ability, Game game) {
|
|
Target newTarget = blueprintTarget.copy();
|
|
int amount = dynamicValue.calculate(game, ability, ability.getEffects().get(0));
|
|
Filter<MageObject> filter = newTarget.getFilter();
|
|
filter.add(new PowerPredicate(comparison, amount));
|
|
newTarget.withTargetName(filter.getMessage() + " (Power " + comparison + " " + amount + ")");
|
|
ability.getTargets().clear();
|
|
ability.addTarget(newTarget);
|
|
}
|
|
}
|