forked from External/mage
45 lines
1.6 KiB
Java
45 lines
1.6 KiB
Java
package mage.target.targetadjustment;
|
|
|
|
import mage.MageObject;
|
|
import mage.abilities.Ability;
|
|
import mage.abilities.dynamicvalue.DynamicValue;
|
|
import mage.constants.ComparisonType;
|
|
import mage.filter.Filter;
|
|
import mage.filter.predicate.mageobject.ManaValuePredicate;
|
|
import mage.game.Game;
|
|
import mage.target.Target;
|
|
|
|
/**
|
|
* @author TheElk801, notgreat
|
|
*/
|
|
public class ManaValueTargetAdjuster implements TargetAdjuster {
|
|
private Target blueprintTarget = null;
|
|
private final DynamicValue dynamicValue;
|
|
private final ComparisonType comparison;
|
|
|
|
/**
|
|
* Modifies the target to also require a mana value that satisfies the comparison to the dynamic value.
|
|
*
|
|
* @param value The value to be compared against
|
|
* @param compare Which comparison to use
|
|
*/
|
|
public ManaValueTargetAdjuster(DynamicValue value, ComparisonType compare) {
|
|
this.dynamicValue = value;
|
|
this.comparison = compare;
|
|
}
|
|
|
|
@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 ManaValuePredicate(comparison, amount));
|
|
newTarget.withTargetName(filter.getMessage() + " (Mana Value " + comparison + " " + amount + ")");
|
|
ability.getTargets().clear();
|
|
ability.addTarget(newTarget);
|
|
}
|
|
}
|