Improved and fixed cards texts:

* fixed wrong texts for draw card abilities;
 * added multi-effects text generation instead copy-paste (concatBy).
This commit is contained in:
Oleg Agafonov 2019-01-04 23:51:42 +04:00
parent 83cf370cc6
commit f6585ef734
23 changed files with 144 additions and 140 deletions

View file

@ -1,8 +1,5 @@
package mage.abilities.effects;
import java.io.Serializable;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.constants.EffectType;
@ -10,8 +7,10 @@ import mage.constants.Outcome;
import mage.game.Game;
import mage.target.targetpointer.TargetPointer;
import java.io.Serializable;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface Effect extends Serializable {
@ -64,4 +63,7 @@ public interface Effect extends Serializable {
Effect copy();
Effect concatBy(String concatPrefix);
String getConcatPrefix();
}

View file

@ -1,9 +1,5 @@
package mage.abilities.effects;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.abilities.MageSingleton;
import mage.abilities.Mode;
import mage.constants.EffectType;
@ -11,8 +7,11 @@ import mage.constants.Outcome;
import mage.target.targetpointer.FirstTargetPointer;
import mage.target.targetpointer.TargetPointer;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class EffectImpl implements Effect {
@ -23,7 +22,7 @@ public abstract class EffectImpl implements Effect {
protected TargetPointer targetPointer = FirstTargetPointer.getInstance();
protected String staticText = "";
protected Map<String, Object> values;
protected boolean applyEffectsAfter = false;
protected String concatPrefix = ""; // combines multiple effects in text rule
public EffectImpl(Outcome outcome) {
this.id = UUID.randomUUID();
@ -36,6 +35,7 @@ public abstract class EffectImpl implements Effect {
this.staticText = effect.staticText;
this.effectType = effect.effectType;
this.targetPointer = effect.targetPointer.copy();
this.concatPrefix = effect.concatPrefix;
if (effect.values != null) {
values = new HashMap<>();
Map<String, Object> map = effect.values;
@ -43,7 +43,6 @@ public abstract class EffectImpl implements Effect {
values.put(entry.getKey(), entry.getValue());
}
}
this.applyEffectsAfter = effect.applyEffectsAfter;
}
@Override
@ -112,4 +111,15 @@ public abstract class EffectImpl implements Effect {
}
return values.get(key);
}
@Override
public Effect concatBy(String concatPrefix) {
this.concatPrefix = concatPrefix;
return this;
}
@Override
public String getConcatPrefix() {
return this.concatPrefix;
}
}

View file

@ -42,6 +42,7 @@ public class Effects extends ArrayList<Effect> {
public String getText(Mode mode) {
StringBuilder sbText = new StringBuilder();
String lastRule = null;
int effectNum = 0;
for (Effect effect : this) {
String endString = "";
String nextRule = effect.getText(mode);
@ -50,9 +51,16 @@ public class Effects extends ArrayList<Effect> {
if (nextRule == null || nextRule.isEmpty()) {
continue;
}
effectNum++;
// concat effects (default: each effect with a new sentence)
String concatPrefix = effect.getConcatPrefix();
if (effectNum > 1 && !concatPrefix.isEmpty() && !concatPrefix.equals(".")) {
nextRule = concatPrefix + " " + nextRule;
}
if (nextRule != null) {
if (nextRule.startsWith("and ") || nextRule.startsWith("with ")) {
if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) {
endString = " ";
} else if (nextRule.startsWith(",") || nextRule.startsWith(" ")) {
endString = "";

View file

@ -38,6 +38,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
super(effect);
this.useLKI = effect.useLKI;
this.useController = effect.useController;
this.copyThatSpellName = effect.copyThatSpellName;
}
public Effect withSpellName(String copyThatSpellName) {

View file

@ -1,9 +1,7 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.MultikickerCount;
import mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
@ -18,20 +16,32 @@ import mage.util.CardUtil;
public class DrawCardSourceControllerEffect extends OneShotEffect {
protected DynamicValue amount;
protected String whoDrawCard = "";
public DrawCardSourceControllerEffect(int amount) {
this(new StaticValue(amount));
this(amount, "");
}
public DrawCardSourceControllerEffect(int amount, String whoDrawCard) {
this(new StaticValue(amount), whoDrawCard);
}
public DrawCardSourceControllerEffect(DynamicValue amount) {
this(amount, "");
}
public DrawCardSourceControllerEffect(DynamicValue amount, String whoDrawCard) {
super(Outcome.DrawCard);
this.amount = amount.copy();
this.whoDrawCard = whoDrawCard;
setText();
}
public DrawCardSourceControllerEffect(final DrawCardSourceControllerEffect effect) {
super(effect);
this.amount = effect.amount.copy();
this.whoDrawCard = effect.whoDrawCard;
setText();
}
@Override
@ -53,7 +63,7 @@ public class DrawCardSourceControllerEffect extends OneShotEffect {
StringBuilder sb = new StringBuilder();
boolean oneCard = (amount instanceof StaticValue && amount.calculate(null, null, this) == 1)
|| amount instanceof PermanentsOnBattlefieldCount || amount.toString().equals("1") || amount.toString().equals("a");
sb.append("draw ").append(oneCard ? "a" : CardUtil.numberToText(amount.toString())).append(" card");
sb.append(whoDrawCard.isEmpty() ? "" : whoDrawCard + " ").append("draw ").append(oneCard ? "a" : CardUtil.numberToText(amount.toString())).append(" card");
if (!oneCard) {
sb.append('s');
}