refactor text gen to use target pointers, part x of y

This commit is contained in:
xenohedron 2024-01-21 02:25:10 -05:00
parent 7be16bdaac
commit 23ca66e3ce
23 changed files with 53 additions and 422 deletions

View file

@ -40,13 +40,8 @@ public class CopyTargetStackAbilityEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append("copy ");
if (!mode.getTargets().isEmpty()) {
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
}
sb.append(". You may choose new targets for the copy");
return sb.toString();
return "copy " + getTargetPointer().describeTargets(mode.getTargets(), "that spell")
+ ". You may choose new targets for the copy";
}
}

View file

@ -49,7 +49,8 @@ public class DestroyAllNamedPermanentsEffect extends OneShotEffect {
@Override
public String getText(Mode mode) {
return "Destroy target " + mode.getTargets().get(0).getTargetName() + " and all other permanents with the same name as that permanent";
return "Destroy " + getTargetPointer().describeTargets(mode.getTargets(), "that permanent")
+ " and all other permanents with the same name as that permanent";
}
}

View file

@ -51,13 +51,7 @@ public class MillCardsTargetEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
if (!mode.getTargets().isEmpty()) {
sb.append("target ");
sb.append(mode.getTargets().get(0).getTargetName());
} else {
sb.append("that player");
}
StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), "that player"));
sb.append(" mills ");
String message = numberCards.getMessage();
if (message.isEmpty()) {

View file

@ -44,7 +44,7 @@ public class MillHalfLibraryTargetEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "target " + (mode.getTargets().isEmpty() ? "that player" : mode.getTargets().get(0).getTargetName()) +
return getTargetPointer().describeTargets(mode.getTargets(), "that player") +
" mills half their library, rounded " + (roundUp ? "up" : "down");
}
}

View file

@ -59,12 +59,7 @@ public class PreventDamageToTargetEffect extends PreventionEffectImpl {
} else {
sb.append("prevent the next ").append(amountToPrevent).append(" damage that would be dealt to ");
}
String targetName = mode.getTargets().get(0).getTargetName();
if (targetName.contains("any")) {
sb.append(targetName);
} else {
sb.append("target ").append(targetName);
}
sb.append(getTargetPointer().describeTargets(mode.getTargets(), "it"));
if (!duration.toString().isEmpty()) {
sb.append(' ');
if (duration == Duration.EndOfTurn) {

View file

@ -70,11 +70,7 @@ public class PreventNextDamageFromChosenSourceToTargetEffect extends PreventionE
}
StringBuilder sb = new StringBuilder("The next time a ").append(targetSource.getFilter().getMessage());
sb.append(" of your choice would deal damage to ");
String targetName = mode.getTargets().get(0).getTargetName();
if (!targetName.contains("target ") && !targetName.endsWith("any target")) {
sb.append("target ");
}
sb.append(targetName);
sb.append(getTargetPointer().describeTargets(mode.getTargets(), "it"));
if (duration == Duration.EndOfTurn) {
sb.append(" this turn");
}

View file

@ -45,12 +45,7 @@ public class CantAttackBlockTargetEffect extends RestrictionEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder("target ");
if (mode.getTargets().isEmpty()) {
sb.append("creature");
} else {
sb.append(mode.getTargets().get(0).getTargetName());
}
StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), "that creature"));
sb.append(" can't attack or block ");
if (duration == Duration.EndOfTurn) {
sb.append("this turn");

View file

@ -69,8 +69,7 @@ public class GoadTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "goad target " + (!mode.getTargets().isEmpty() ? mode.getTargets().get(0).getTargetName() : " creature")
return "goad " + getTargetPointer().describeTargets(mode.getTargets(), "that creature")
+ ". <i>(Until your next turn, that creature attacks each combat if able and attacks a player other than you if able.)</i>";
}
}

View file

@ -155,12 +155,7 @@ public class BecomesBasicLandTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder("target ");
if (!mode.getTargets().isEmpty()) {
sb.append(mode.getTargets().get(0).getTargetName());
} else {
sb.append("land");
}
StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), "target land"));
sb.append(" becomes ");
if (chooseLandType) {
sb.append("the basic land type of your choice");

View file

@ -48,6 +48,6 @@ public class GainAllCreatureTypesTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "target " + mode.getTargets().get(0).getTargetName() + " gains all creature types " + duration.toString();
return getTargetPointer().describeTargets(mode.getTargets(), "it") + " gains all creature types " + duration.toString();
}
}

View file

@ -1,159 +0,0 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.Mode;
import mage.abilities.condition.Condition;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.util.CardUtil;
import java.util.UUID;
/**
* @author Merlingilb
*/
public class GainControlAndUntapTargetEffect extends ContinuousEffectImpl {
protected UUID controllingPlayerId;
private boolean fixedControl;
private boolean firstControlChange = true;
private final Condition condition;
public GainControlAndUntapTargetEffect(Duration duration) {
this(duration, false, null);
}
/**
* @param duration
* @param fixedControl Controlling player is fixed even if the controller of
* the ability changes later
*/
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl) {
this(duration, fixedControl, null);
}
/**
* @param duration
* @param controllingPlayerId Player that controls the target creature
*/
public GainControlAndUntapTargetEffect(Duration duration, UUID controllingPlayerId) {
this(duration, true, controllingPlayerId);
}
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId) {
this(duration, fixedControl, controllingPlayerId, null);
}
public GainControlAndUntapTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId, Condition condition) {
super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl);
this.controllingPlayerId = controllingPlayerId;
this.fixedControl = fixedControl;
this.condition = condition;
}
protected GainControlAndUntapTargetEffect(final GainControlAndUntapTargetEffect effect) {
super(effect);
this.controllingPlayerId = effect.controllingPlayerId;
this.fixedControl = effect.fixedControl;
this.condition = effect.condition;
}
@Override
public GainControlAndUntapTargetEffect copy() {
return new GainControlAndUntapTargetEffect(this);
}
@Override
public void init(Ability source, Game game) {
if (this.controllingPlayerId == null && fixedControl) {
this.controllingPlayerId = source.getControllerId();
}
super.init(source, game);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
discard(); // controller no longer exists
return false;
}
boolean oneTargetStillExists = false;
for (UUID permanentId : getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent == null) {
continue;
}
oneTargetStillExists = true;
if (permanent.isControlledBy(controllingPlayerId)) {
permanent.untap(game);
continue;
}
boolean controlChanged = false;
if (controllingPlayerId != null) {
if (permanent.changeControllerId(controllingPlayerId, game, source)) {
permanent.untap(game);
controlChanged = true;
}
} else {
if (permanent.changeControllerId(source.getControllerId(), game, source)) {
permanent.untap(game);
controlChanged = true;
}
}
if (source instanceof ActivatedAbility
&& firstControlChange && !controlChanged) {
// If it was not possible to get control of target permanent by the activated ability the first time it took place
// the effect failed (e.g. because of Guardian Beast) and must be discarded
// This does not handle correctly multiple targets at once
discard();
}
if (condition != null && !condition.apply(game, source)) {
discard();
}
}
// no valid target exists and the controller is no longer in the game, effect can be discarded
if (!oneTargetStillExists || !controller.isInGame()) {
discard();
}
firstControlChange = false;
return true;
}
@Override
public String getText(Mode mode) {
if (!staticText.isEmpty()) {
return staticText;
}
if (mode.getTargets().isEmpty()) {
return "gain control of target permanent until end of turn. Untap it.";
}
Target target = mode.getTargets().get(0);
StringBuilder sb = new StringBuilder("gain control of ");
if (target.getMaxNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("up to ");
}
sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ");
} else if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
}
sb.append(mode.getTargets().get(0).getTargetName());
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
sb.append("and untap it");
return sb.toString();
}
}

View file

@ -76,20 +76,7 @@ public class GainProtectionFromColorTargetEffect extends GainAbilityTargetEffect
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
if (!mode.getTargets().isEmpty()) {
if (mode.getTargets().get(0).getTargetName().contains("target")) {
sb.append(mode.getTargets().get(0).getTargetName());
} else {
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
}
}
if (sb.length() > 0) {
sb.append(" ");
}
sb.append("gains protection from the color of your choice " + duration.toString());
return sb.toString();
return getTargetPointer().describeTargets(mode.getTargets(), "it")
+ " gains protection from the color of your choice " + duration.toString();
}
}

View file

@ -1,100 +0,0 @@
package mage.abilities.effects.common.continuous;
import java.util.HashSet;
import java.util.Set;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.choices.ChoiceImpl;
import mage.constants.Duration;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
/**
* @author a
*/
public class LoseAbilityOrAnotherAbilityTargetEffect extends LoseAbilityTargetEffect {
protected Ability ability2;
public LoseAbilityOrAnotherAbilityTargetEffect(Ability ability, Ability ability2) {
this(ability, ability2, Duration.WhileOnBattlefield);
}
public LoseAbilityOrAnotherAbilityTargetEffect(Ability ability, Ability ability2, Duration duration) {
super(ability, duration);
this.ability2 = ability2;
}
protected LoseAbilityOrAnotherAbilityTargetEffect(final LoseAbilityOrAnotherAbilityTargetEffect effect) {
super(effect);
this.ability2 = effect.ability2.copy();
}
@Override
public LoseAbilityOrAnotherAbilityTargetEffect copy() {
return new LoseAbilityOrAnotherAbilityTargetEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (permanent != null) {
ChoiceImpl chooseAbility = new ChoiceImpl();
chooseAbility.setMessage("Choose an ability to remove");
Set<String> choice = new HashSet<>();
if (permanent.getAbilities().contains(ability)) {
choice.add(ability.getRule());
}
if (permanent.getAbilities().contains(ability2)) {
choice.add(ability2.getRule());
}
chooseAbility.setChoices(choice);
Player player = game.getPlayer(source.getControllerId());
if (player.choose(outcome, chooseAbility, game)) {
String chosenAbility = chooseAbility.getChoice();
if (chosenAbility.equals(ability.getRule())) {
permanent.removeAbility(ability, source.getSourceId(), game);
} else if (chosenAbility.equals(ability2.getRule())) {
permanent.removeAbility(ability2, source.getSourceId(), game);
}
} else {
return false;
}
}
return true;
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
Target target = mode.getTargets().get(0);
if (target.getNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("Up to");
}
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" loses ");
} else {
sb.append("Target ").append(target.getTargetName()).append(" loses ");
}
sb.append(ability.getRule());
sb.append(" or ");
sb.append(ability2.getRule());
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
return sb.toString();
}
}

View file

@ -10,7 +10,7 @@ import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.util.CardUtil;
/**
* @author jeffwadsworth
@ -52,20 +52,8 @@ public class LoseAbilityTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
Target target = mode.getTargets().get(0);
if (target.getNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("Up to");
}
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" loses ");
} else {
sb.append("Target ").append(target.getTargetName()).append(" loses ");
}
sb.append(ability.getRule());
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
return sb.toString();
return getTargetPointer().describeTargets(mode.getTargets(), "it")
+ " loses " + CardUtil.stripReminderText(ability.getRule())
+ (duration.toString().isEmpty() ? "" : ' ' + duration.toString());
}
}

View file

@ -2,13 +2,13 @@
package mage.abilities.effects.common.continuous;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -50,9 +50,8 @@ public class LoseAllAbilitiesTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append("Target ").append(mode.getTargets().get(0).getTargetName()).append(" loses all abilities ").append(duration.toString());
return sb.toString();
return getTargetPointer().describeTargets(mode.getTargets(), "it")
+ " loses all abilities " + (duration.toString().isEmpty() ? "" : ' ' + duration.toString());
}
}
}

View file

@ -43,6 +43,7 @@ public class LoseAllCreatureTypesTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "target " + mode.getTargets().get(0).getTargetName() + " loses all creature types " + duration.toString();
return getTargetPointer().describeTargets(mode.getTargets(), "it") + " loses all creature types"
+ (duration.toString().isEmpty() ? "" : ' ' + duration.toString());
}
}

View file

@ -548,12 +548,6 @@ public final class StaticFilters {
FILTER_OPPONENTS_PERMANENT_NON_LAND.setLockedFilter(true);
}
public static final FilterNoncreaturePermanent FILTER_PERMANENT_NON_CREATURE = new FilterNoncreaturePermanent();
static {
FILTER_PERMANENT_NON_CREATURE.setLockedFilter(true);
}
public static final FilterCreaturePermanent FILTER_OPPONENTS_PERMANENT_CREATURE = new FilterOpponentsCreaturePermanent();
static {

View file

@ -1,33 +0,0 @@
package mage.filter.common;
import mage.constants.CardType;
import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates;
/**
* @author Merlingilb
*/
public class FilterNoncreaturePermanent extends FilterPermanent {
public FilterNoncreaturePermanent() {
this("noncreature permanent");
}
public FilterNoncreaturePermanent(String name) {
super(name);
this.add(Predicates.not(CardType.CREATURE.getPredicate()));
}
protected FilterNoncreaturePermanent(final FilterNoncreaturePermanent filter) {
super(filter);
}
@Override
public FilterNoncreaturePermanent copy() {
return new FilterNoncreaturePermanent(this);
}
}