* replaces all [source} by {this}. ATTENTION !!!: Only supporting [this} from now on in rule text.

This commit is contained in:
LevelX2 2020-08-22 12:52:49 +02:00
parent d51acbf090
commit c16fb75668
91 changed files with 229 additions and 236 deletions

View file

@ -1,5 +1,10 @@
package mage.abilities;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.MageIdentifier;
import mage.MageObject;
import mage.abilities.costs.*;
import mage.abilities.costs.common.PayLifeCost;
@ -31,12 +36,6 @@ import mage.util.ThreadLocalStringBuilder;
import mage.watchers.Watcher;
import org.apache.log4j.Logger;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import mage.MageIdentifier;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -74,7 +73,7 @@ public abstract class AbilityImpl implements Ability {
protected List<Hint> hints = new ArrayList<>();
protected Outcome customOutcome = null; // uses for AI decisions instead effects
protected MageIdentifier identifier; // used to identify specific ability (e.g. to match with corresponding watcher)
public AbilityImpl(AbilityType abilityType, Zone zone) {
this.id = UUID.randomUUID();
this.originalId = id;
@ -801,7 +800,6 @@ public abstract class AbilityImpl implements Ability {
String replace = rule;
if (rule != null && source != null && !source.isEmpty()) {
replace = rule.replace("{this}", source);
replace = replace.replace("{source}", source);
}
return replace;
}
@ -1318,5 +1316,5 @@ public abstract class AbilityImpl implements Ability {
public AbilityImpl setIdentifier(MageIdentifier identifier) {
this.identifier = identifier;
return this;
}
}
}

View file

@ -1,5 +1,6 @@
package mage.abilities;
import java.util.*;
import mage.abilities.costs.OptionalAdditionalModeSourceCosts;
import mage.cards.Card;
import mage.constants.Outcome;
@ -11,8 +12,6 @@ import mage.players.Player;
import mage.target.common.TargetOpponent;
import mage.util.RandomUtil;
import java.util.*;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -446,10 +445,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
}
public String getText(String sourceName) {
String text = getText();
text = text.replace("{this}", sourceName);
text = text.replace("{source}", sourceName);
return text;
return getText().replace("{this}", sourceName);
}
public boolean isEachModeOnlyOnce() {

View file

@ -32,7 +32,7 @@ public enum ProwlCostWasPaidCondition implements Condition {
@Override
public String toString() {
return "{source}'s prowl cost was paid";
return "{this}'s prowl cost was paid";
}
}

View file

@ -55,6 +55,6 @@ public class SourcePermanentPowerCount implements DynamicValue {
@Override
public String getMessage() {
return "{source}'s power";
return "{this}'s power";
}
}

View file

@ -52,6 +52,6 @@ public class SourcePermanentToughnessValue implements DynamicValue {
@Override
public String getMessage() {
return "{source}'s toughness";
return "{this}'s toughness";
}
}

View file

@ -19,7 +19,7 @@ public class DamageAllEffect extends OneShotEffect {
private FilterPermanent filter;
private DynamicValue amount;
private String sourceName = "{source}";
private String sourceName = "{this}";
public DamageAllEffect(int amount, FilterPermanent filter) {
this(StaticValue.get(amount), filter);

View file

@ -19,7 +19,7 @@ import mage.game.permanent.Permanent;
public class DamageAttachedEffect extends OneShotEffect {
protected DynamicValue amount;
private String sourceName = "{source}";
private String sourceName = "{this}";
public DamageAttachedEffect(int amount) {
super(Outcome.Damage);

View file

@ -19,7 +19,7 @@ public class DamageControllerEffect extends OneShotEffect {
protected DynamicValue amount;
protected boolean preventable;
private String sourceName = "{source}";
private String sourceName = "{this}";
public DamageControllerEffect(int amount, String whoDealDamageName) {
this(amount, true, whoDealDamageName);

View file

@ -22,7 +22,7 @@ public class DamageEverythingEffect extends OneShotEffect {
private DynamicValue amount;
private FilterPermanent filter;
private UUID damageSource;
private String sourceName = "{source}";
private String sourceName = "{this}";
public DamageEverythingEffect(int amount) {
this(StaticValue.get(amount), new FilterCreaturePermanent());

View file

@ -22,7 +22,7 @@ import java.util.UUID;
public class DamageMultiEffect extends OneShotEffect {
protected DynamicValue amount;
private String sourceName = "{source}";
private String sourceName = "{this}";
private final Set<MageObjectReference> damagedSet = new HashSet<>();
public DamageMultiEffect(int amount) {

View file

@ -17,7 +17,7 @@ import java.util.UUID;
public class DamagePlayersEffect extends OneShotEffect {
private DynamicValue amount;
private TargetController controller;
private String sourceName = "{source}";
private String sourceName = "{this}";
public DamagePlayersEffect(int amount) {
this(Outcome.Damage, StaticValue.get(amount));

View file

@ -47,7 +47,7 @@ public class DamageSelfEffect extends OneShotEffect {
return staticText;
}
StringBuilder sb = new StringBuilder();
sb.append("{source} deals ").append(amount).append(" damage to itself");
sb.append("{this} deals ").append(amount).append(" damage to itself");
return sb.toString();
}
}

View file

@ -24,7 +24,7 @@ public class DamageTargetEffect extends OneShotEffect {
protected boolean preventable;
protected String targetDescription;
protected boolean useOnlyTargetPointer;
protected String sourceName = "{source}";
protected String sourceName = "{this}";
public DamageTargetEffect(int amount) {
this(StaticValue.get(amount), true);

View file

@ -1,5 +1,6 @@
package mage.abilities.effects.common;
import java.util.Locale;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.Mode;
@ -13,8 +14,6 @@ import mage.game.Game;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.Locale;
public class DoIfCostPaid extends OneShotEffect {
protected Effects executingEffects = new Effects();
@ -85,11 +84,10 @@ public class DoIfCostPaid extends OneShotEffect {
}
message = getCostText() + (effectText.isEmpty() ? "" : " and " + effectText) + "?";
message = Character.toUpperCase(message.charAt(0)) + message.substring(1);
CardUtil.replaceSourceName(message, mageObject.getName());
} else {
message = chooseUseText;
}
message = CardUtil.replaceSourceName(message, mageObject.getLogName());
message = CardUtil.replaceSourceName(message, mageObject.getName());
boolean result = true;
Outcome payOutcome = executingEffects.getOutcome(source, this.outcome);
if (cost.canPay(source, source.getSourceId(), player.getId(), game)

View file

@ -18,7 +18,7 @@ public class DontUntapAsLongAsSourceTappedEffect extends ConditionalContinuousRu
public DontUntapAsLongAsSourceTappedEffect() {
super(new DontUntapInControllersUntapStepTargetEffect(Duration.Custom), SourceTappedCondition.instance);
staticText = "It doesn't untap during its controller's untap step for as long as {source} remains tapped.";
staticText = "It doesn't untap during its controller's untap step for as long as {this} remains tapped.";
}
public DontUntapAsLongAsSourceTappedEffect(final DontUntapAsLongAsSourceTappedEffect effect) {

View file

@ -60,7 +60,7 @@ public class PreventDamageToSourceEffect extends PreventionEffectImpl {
} else {
sb.append("Prevent the next ").append(amountToPrevent).append(" damage that would be dealt to ");
}
sb.append("{source} ");
sb.append("{this} ");
if (duration == EndOfTurn) {
sb.append("this turn");
} else {

View file

@ -27,7 +27,7 @@ public class ProtectionChosenColorAttachedEffect extends ContinuousEffectImpl {
public ProtectionChosenColorAttachedEffect(boolean notRemoveItself) {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
this.notRemoveItself = notRemoveItself;
staticText = "{source} has protection from the chosen color" + (notRemoveItself ? ". This effect doesn't remove {this}" : "");
staticText = "{this} has protection from the chosen color" + (notRemoveItself ? ". This effect doesn't remove {this}" : "");
}
public ProtectionChosenColorAttachedEffect(final ProtectionChosenColorAttachedEffect effect) {

View file

@ -25,7 +25,7 @@ public class ProtectionChosenColorSourceEffect extends ContinuousEffectImpl {
public ProtectionChosenColorSourceEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
staticText = "{source} has protection from the chosen color";
staticText = "{this} has protection from the chosen color";
}
public ProtectionChosenColorSourceEffect(final ProtectionChosenColorSourceEffect effect) {

View file

@ -12,7 +12,7 @@ public enum Duration {
EndOfTurn("until end of turn", true, true),
UntilYourNextTurn("until your next turn", true, true),
UntilEndOfYourNextTurn("until the end of your next turn", true, true),
UntilSourceLeavesBattlefield("until {source} leaves the battlefield", true, false), // supported for continuous layered effects
UntilSourceLeavesBattlefield("until {this} leaves the battlefield", true, false), // supported for continuous layered effects
EndOfCombat("until end of combat", true, true),
EndOfStep("until end of phase step", true, true),
Custom("", true, true);

View file

@ -1,5 +1,11 @@
package mage.util;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageObject;
import mage.Mana;
import mage.abilities.Abilities;
@ -25,13 +31,6 @@ import mage.players.Player;
import mage.target.Target;
import mage.util.functions.CopyTokenFunction;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author nantuko
*/
@ -40,10 +39,10 @@ public final class CardUtil {
private static final String SOURCE_EXILE_ZONE_TEXT = "SourceExileZone";
static final String[] numberStrings = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty"};
static final String[] ordinalStrings = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eightth", "ninth",
"tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth"};
"tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth"};
public static final SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.SSS");
@ -242,7 +241,8 @@ public final class CardUtil {
* @param spellAbility
* @param manaCostsToReduce costs to reduce
* @param convertToGeneric colored mana does reduce generic mana if no
* appropriate colored mana is in the costs included
* appropriate colored mana is in the costs
* included
*/
public static void adjustCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce, boolean convertToGeneric) {
ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
@ -462,9 +462,7 @@ public final class CardUtil {
}
public static String replaceSourceName(String message, String sourceName) {
message = message.replace("{this}", sourceName);
message = message.replace("{source}", sourceName);
return message;
return message.replace("{this}", sourceName);
}
public static String booleanToFlipName(boolean flip) {
@ -767,8 +765,12 @@ public final class CardUtil {
// +0/-1 must be -0/-1
String signedP = String.format("%1$+d", power);
String signedT = String.format("%1$+d", toughness);
if (signedP.equals("+0") && signedT.startsWith("-")) signedP = "-0";
if (signedT.equals("+0") && signedP.startsWith("-")) signedT = "-0";
if (signedP.equals("+0") && signedT.startsWith("-")) {
signedP = "-0";
}
if (signedT.equals("+0") && signedP.startsWith("-")) {
signedT = "-0";
}
return signedP + "/" + signedT;
}