forked from External/mage
[WHO] Time Reaper, Add target adjuster for "that player controls/owns" damage trigger targets (#12528)
* 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
This commit is contained in:
parent
bccf323c0f
commit
7cb669603f
172 changed files with 891 additions and 2219 deletions
|
|
@ -0,0 +1,61 @@
|
|||
package mage.target.targetadjustment;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.filter.Filter;
|
||||
import mage.filter.predicate.card.OwnerIdPredicate;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.targetpointer.FirstTargetPointer;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author notgreat
|
||||
*/
|
||||
public class DamagedPlayerControlsTargetAdjuster extends GenericTargetAdjuster {
|
||||
private final boolean owner;
|
||||
|
||||
/**
|
||||
* Use with {@link mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility} with setTargetPointer enabled,
|
||||
* or {@link mage.abilities.common.OneOrMoreDealDamageTriggeredAbility} with "SetTargetPointer.PLAYER" or similar.
|
||||
* Adjusts the target to only target something the damaged player controls (or owns with alternative constructor)
|
||||
* And then removes the effects' target pointer that the triggered ability set
|
||||
*/
|
||||
public DamagedPlayerControlsTargetAdjuster() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public DamagedPlayerControlsTargetAdjuster(boolean owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefaultTargets(Ability ability) {
|
||||
super.addDefaultTargets(ability);
|
||||
CardUtil.AssertNoControllerOwnerPredicates(blueprintTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
UUID opponentId = ability.getEffects().get(0).getTargetPointer().getFirst(game, ability);
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
ability.getTargets().clear();
|
||||
ability.getAllEffects().setTargetPointer(new FirstTargetPointer());
|
||||
if (opponent == null) {
|
||||
return;
|
||||
}
|
||||
Target newTarget = blueprintTarget.copy();
|
||||
Filter filter = newTarget.getFilter();
|
||||
if (owner) {
|
||||
filter.add(new OwnerIdPredicate(opponentId));
|
||||
newTarget.withTargetName(filter.getMessage() + " (owned by " + opponent.getLogName() + ")");
|
||||
} else {
|
||||
filter.add(new ControllerIdPredicate(opponentId));
|
||||
newTarget.withTargetName(filter.getMessage() + " (controlled by " + opponent.getLogName() + ")");
|
||||
}
|
||||
ability.addTarget(newTarget);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,17 +4,18 @@ import mage.abilities.Ability;
|
|||
import mage.filter.Filter;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author notgreat
|
||||
*/
|
||||
public class EachOpponentPermanentTargetsAdjuster implements TargetAdjuster {
|
||||
private TargetPermanent blueprintTarget = null;
|
||||
public class EachOpponentPermanentTargetsAdjuster extends GenericTargetAdjuster {
|
||||
|
||||
/**
|
||||
* Duplicates the permanent target for each opponent.
|
||||
* Filtering of permanent's controllers will be handled inside, so
|
||||
|
|
@ -24,23 +25,27 @@ public class EachOpponentPermanentTargetsAdjuster implements TargetAdjuster {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
if (blueprintTarget == null) {
|
||||
blueprintTarget = (TargetPermanent) ability.getTargets().get(0).copy();
|
||||
public void addDefaultTargets(Ability ability) {
|
||||
super.addDefaultTargets(ability);
|
||||
if (!(blueprintTarget instanceof TargetPermanent)) {
|
||||
throw new IllegalArgumentException("EachOpponentPermanentTargetsAdjuster must use Permanent target - " + blueprintTarget);
|
||||
}
|
||||
CardUtil.AssertNoControllerOwnerPredicates(blueprintTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
ability.getTargets().clear();
|
||||
for (UUID opponentId : game.getOpponents(ability.getControllerId())) {
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent == null) {
|
||||
continue;
|
||||
}
|
||||
TargetPermanent newTarget = blueprintTarget.copy();
|
||||
Filter<Permanent> filter = newTarget.getFilter();
|
||||
Target newTarget = blueprintTarget.copy();
|
||||
Filter filter = newTarget.getFilter();
|
||||
filter.add(new ControllerIdPredicate(opponentId));
|
||||
if (!newTarget.possibleTargets(ability.getControllerId(), ability, game).isEmpty()) {
|
||||
newTarget.withTargetName(filter.getMessage() + " controlled by " + opponent.getLogName());
|
||||
ability.addTarget(newTarget);
|
||||
}
|
||||
newTarget.withTargetName(filter.getMessage() + " controlled by " + opponent.getLogName());
|
||||
ability.addTarget(newTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package mage.target.targetadjustment;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.target.Target;
|
||||
|
||||
public abstract class GenericTargetAdjuster implements TargetAdjuster {
|
||||
protected Target blueprintTarget = null;
|
||||
|
||||
@Override
|
||||
public void addDefaultTargets(Ability ability) {
|
||||
if (blueprintTarget == null) {
|
||||
blueprintTarget = ability.getTargets().get(0).copy();
|
||||
} else {
|
||||
throw new IllegalStateException("Wrong code usage: target adjuster already has blueprint target - " + blueprintTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,8 +12,7 @@ import mage.target.Target;
|
|||
/**
|
||||
* @author TheElk801, notgreat
|
||||
*/
|
||||
public class ManaValueTargetAdjuster implements TargetAdjuster {
|
||||
private Target blueprintTarget = null;
|
||||
public class ManaValueTargetAdjuster extends GenericTargetAdjuster {
|
||||
private final DynamicValue dynamicValue;
|
||||
private final ComparisonType comparison;
|
||||
|
||||
|
|
@ -30,10 +29,6 @@ public class ManaValueTargetAdjuster implements TargetAdjuster {
|
|||
|
||||
@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();
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ import mage.target.Target;
|
|||
/**
|
||||
* @author TheElk801, notgreat
|
||||
*/
|
||||
public class PowerTargetAdjuster implements TargetAdjuster {
|
||||
private Target blueprintTarget = null;
|
||||
public class PowerTargetAdjuster extends GenericTargetAdjuster {
|
||||
private final DynamicValue dynamicValue;
|
||||
private final ComparisonType comparison;
|
||||
|
||||
|
|
@ -33,12 +32,9 @@ public class PowerTargetAdjuster implements TargetAdjuster {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -13,4 +13,10 @@ public interface TargetAdjuster extends Serializable {
|
|||
|
||||
// Warning: This is not Copyable, do not use changeable data inside (only use static objects like Filter)
|
||||
void adjustTargets(Ability ability, Game game);
|
||||
|
||||
/**
|
||||
* Add default blueprint target to the ability
|
||||
*/
|
||||
default void addDefaultTargets(Ability ability) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ import mage.target.Target;
|
|||
/**
|
||||
* @author TheElk801, notgreat
|
||||
*/
|
||||
public class TargetsCountAdjuster implements TargetAdjuster {
|
||||
private Target blueprintTarget = null;
|
||||
public class TargetsCountAdjuster extends GenericTargetAdjuster {
|
||||
private final DynamicValue dynamicValue;
|
||||
|
||||
/**
|
||||
|
|
@ -26,10 +25,6 @@ public class TargetsCountAdjuster implements TargetAdjuster {
|
|||
|
||||
@Override
|
||||
public void adjustTargets(Ability ability, Game game) {
|
||||
if (blueprintTarget == null) {
|
||||
blueprintTarget = ability.getTargets().get(0).copy();
|
||||
blueprintTarget.clearChosen();
|
||||
}
|
||||
Target newTarget = blueprintTarget.copy();
|
||||
int count = dynamicValue.calculate(game, ability, ability.getEffects().get(0));
|
||||
newTarget.setMaxNumberOfTargets(count);
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ import mage.target.Target;
|
|||
/**
|
||||
* @author TheElk801, notgreat
|
||||
*/
|
||||
public class ToughnessTargetAdjuster implements TargetAdjuster {
|
||||
private Target blueprintTarget = null;
|
||||
public class ToughnessTargetAdjuster extends GenericTargetAdjuster {
|
||||
private final DynamicValue dynamicValue;
|
||||
private final ComparisonType comparison;
|
||||
|
||||
|
|
@ -35,10 +34,6 @@ public class ToughnessTargetAdjuster implements TargetAdjuster {
|
|||
|
||||
@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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue