foul-magics/Mage/src/main/java/mage/target/targetadjustment/ToughnessTargetAdjuster.java
ssk97 32bf3eb9bf
Genericize Target Adjusters (#12107)
* Create generic X MV adjuster

* Update XTargetsAdjuster

* Create DynamicValueTargetsAdjuster to replace VerseCounterAdjuster

* Convert XTargetsAdjuster to use DynamicValueTargetsAdjuster

* Genericize MV target adjuster

* Converting custom classes for A and B cards, fix Back in Town to only target creature cards

* Add Power and Toughness target adjusters, C cards

* Set up and use Monstrosity X DynamicValue

* Move Scry amount dynamic value to common, add D and E cards

* Convert F to I cards

* Cards K-M

* N, O cards

* Cards O-R

* S cards (check Scrap Welder)

* Cards T - Z

* Rename target adjusters

* Add filter messages, don't add 0 count targets

* Clear blueprint targets (just in case), fix target names, Temporal Firestorm is not target

* Requested renames

* Aether Burst is "up to"

* Review fixes

* Add new cards, add source to dynamic value calculation
2024-05-03 01:12:52 -04:00

50 lines
1.8 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.ToughnessPredicate;
import mage.game.Game;
import mage.target.Target;
/**
* @author TheElk801, notgreat
*/
public class ToughnessTargetAdjuster implements TargetAdjuster {
private Target blueprintTarget = null;
private final DynamicValue dynamicValue;
private final ComparisonType comparison;
/**
* Modifies the target to also require a toughness that satisfies the comparison to the dynamic value.
*
* @param value The value to be compared against
* @param compare Which comparison to use
*/
public ToughnessTargetAdjuster(DynamicValue value, ComparisonType compare) {
this.dynamicValue = value;
this.comparison = compare;
}
public ToughnessTargetAdjuster(ComparisonType comparison) {
this(ManacostVariableValue.REGULAR, comparison);
}
@Override
public void adjustTargets(Ability ability, Game game) {
if (blueprintTarget == null) {
blueprintTarget = ability.getTargets().get(0).copy();
blueprintTarget.clearChosen();
}
Target newTarget = blueprintTarget.copy();
int amount = dynamicValue.calculate(game, ability, ability.getEffects().get(0));
Filter<MageObject> filter = newTarget.getFilter();
filter.add(new ToughnessPredicate(comparison, amount));
newTarget.setTargetName(filter.getMessage() + " (Toughness " + comparison + " " + amount + ")");
ability.getTargets().clear();
ability.addTarget(newTarget);
}
}