Refactor: moved flavor word from effects list to ability/mode;

This commit is contained in:
Oleg Agafonov 2021-06-30 08:57:06 +04:00
parent 2d1e11dfa9
commit 6dafb3ad81
13 changed files with 52 additions and 40 deletions

View file

@ -31,11 +31,12 @@ public final class BalefulBeholder extends CardImpl {
// When Baleful Beholder enters the battlefield, choose one // When Baleful Beholder enters the battlefield, choose one
// Antimagic Cone Each opponent sacrifices an enchantment. // Antimagic Cone Each opponent sacrifices an enchantment.
Ability ability = new EntersBattlefieldTriggeredAbility(new SacrificeOpponentsEffect(StaticFilters.FILTER_ENCHANTMENT_PERMANENT)); Ability ability = new EntersBattlefieldTriggeredAbility(new SacrificeOpponentsEffect(StaticFilters.FILTER_ENCHANTMENT_PERMANENT));
ability.getEffects().setFlavorWord("Antimagic Cone"); ability.withFlavorWord("Antimagic Cone");
// Fear Ray Creatures you control gain menace until end of turn. // Fear Ray Creatures you control gain menace until end of turn.
ability.addMode(new Mode(new GainAbilityControlledEffect( ability.addMode(new Mode(new GainAbilityControlledEffect(
new MenaceAbility(), Duration.EndOfTurn, StaticFilters.FILTER_PERMANENT_CREATURES)).setFlavorWord("Fear Ray")); new MenaceAbility(), Duration.EndOfTurn, StaticFilters.FILTER_PERMANENT_CREATURES))
.withFlavorWord("Fear Ray"));
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -32,17 +32,17 @@ public final class DawnbringerCleric extends CardImpl {
// When Dawnbringer Cleric enters the battlefield, choose one // When Dawnbringer Cleric enters the battlefield, choose one
// Cure Wounds You gain 2 life. // Cure Wounds You gain 2 life.
Ability ability = new EntersBattlefieldTriggeredAbility(new GainLifeEffect(1)); Ability ability = new EntersBattlefieldTriggeredAbility(new GainLifeEffect(1));
ability.getEffects().setFlavorWord("Cure Wounds"); ability.withFlavorWord("Cure Wounds");
// Dispel Magic Destroy target enchantment. // Dispel Magic Destroy target enchantment.
Mode mode = new Mode(new DestroyTargetEffect()); Mode mode = new Mode(new DestroyTargetEffect());
mode.addTarget(new TargetEnchantmentPermanent()); mode.addTarget(new TargetEnchantmentPermanent());
ability.addMode(mode.setFlavorWord("Dispel Magic")); ability.addMode(mode.withFlavorWord("Dispel Magic"));
// Gentle Repose Exile target card from a graveyard. // Gentle Repose Exile target card from a graveyard.
mode = new Mode(new ExileTargetEffect()); mode = new Mode(new ExileTargetEffect());
mode.addTarget(new TargetCardInGraveyard()); mode.addTarget(new TargetCardInGraveyard());
ability.addMode(mode.setFlavorWord("Gentle Repose")); ability.addMode(mode.withFlavorWord("Gentle Repose"));
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -36,7 +36,7 @@ public final class GuildThief extends CardImpl {
// Cunning Action {3}{U}: Guild Thief can't be blocked this turn. // Cunning Action {3}{U}: Guild Thief can't be blocked this turn.
this.addAbility(new SimpleActivatedAbility( this.addAbility(new SimpleActivatedAbility(
new CantBeBlockedSourceEffect(Duration.EndOfTurn), new ManaCostsImpl<>("{3}{U}") new CantBeBlockedSourceEffect(Duration.EndOfTurn), new ManaCostsImpl<>("{3}{U}")
).setFlavorWord("Cunning Action")); ).withFlavorWord("Cunning Action"));
} }
private GuildThief(final GuildThief card) { private GuildThief(final GuildThief card) {

View file

@ -31,10 +31,12 @@ public final class InspiringBard extends CardImpl {
// Bardic Inspiration Target creature gets +2/+2 until end of turn. // Bardic Inspiration Target creature gets +2/+2 until end of turn.
Ability ability = new EntersBattlefieldTriggeredAbility(new BoostTargetEffect(2, 2)); Ability ability = new EntersBattlefieldTriggeredAbility(new BoostTargetEffect(2, 2));
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
ability.getEffects().setFlavorWord("Bardic Inspiration"); ability.withFlavorWord("Bardic Inspiration");
// Song of Rest You gain 3 life. // Song of Rest You gain 3 life.
ability.addMode(new Mode(new GainLifeEffect(3)).setFlavorWord("Song of Rest")); ability.addMode(new Mode(
new GainLifeEffect(3)
).withFlavorWord("Song of Rest"));
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -32,10 +32,12 @@ public final class PlunderingBarbarian extends CardImpl {
// Smash the Chest Destroy target artifact. // Smash the Chest Destroy target artifact.
Ability ability = new EntersBattlefieldTriggeredAbility(new DestroyTargetEffect()); Ability ability = new EntersBattlefieldTriggeredAbility(new DestroyTargetEffect());
ability.addTarget(new TargetArtifactPermanent()); ability.addTarget(new TargetArtifactPermanent());
ability.getEffects().setFlavorWord("Smash the Chest"); ability.withFlavorWord("Smash the Chest");
// Pry It Open Creature a Treasure token. // Pry It Open Creature a Treasure token.
ability.addMode(new Mode(new CreateTokenEffect(new TreasureToken())).setFlavorWord("Pry It Open")); ability.addMode(new Mode(
new CreateTokenEffect(new TreasureToken())
).withFlavorWord("Pry It Open"));
this.addAbility(ability); this.addAbility(ability);
} }

View file

@ -22,12 +22,12 @@ public final class YouFindTheVillainsLair extends CardImpl {
// Foil Their Scheme Counter target spell. // Foil Their Scheme Counter target spell.
this.getSpellAbility().addEffect(new CounterTargetEffect()); this.getSpellAbility().addEffect(new CounterTargetEffect());
this.getSpellAbility().addTarget(new TargetSpell()); this.getSpellAbility().addTarget(new TargetSpell());
this.getSpellAbility().getEffects().setFlavorWord("Foil Their Scheme"); this.getSpellAbility().withFlavorWord("Foil Their Scheme");
// Learn Their Secrets Draw two cards, then discard two cards. // Learn Their Secrets Draw two cards, then discard two cards.
this.getSpellAbility().addMode(new Mode( this.getSpellAbility().addMode(new Mode(
new DrawDiscardControllerEffect(2, 2) new DrawDiscardControllerEffect(2, 2)
).setFlavorWord("Learn Their Secrts")); ).withFlavorWord("Learn Their Secrts"));
} }
private YouFindTheVillainsLair(final YouFindTheVillainsLair card) { private YouFindTheVillainsLair(final YouFindTheVillainsLair card) {

View file

@ -25,12 +25,12 @@ public final class YouSeeAGuardApproach extends CardImpl {
// Distract the Guard Tap target creature. // Distract the Guard Tap target creature.
this.getSpellAbility().addEffect(new TapTargetEffect()); this.getSpellAbility().addEffect(new TapTargetEffect());
this.getSpellAbility().addTarget(new TargetCreaturePermanent()); this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().getEffects().setFlavorWord("Distract the Guard"); this.getSpellAbility().withFlavorWord("Distract the Guard");
// Hide Target creature you control gains hexproof until end of turn. // Hide Target creature you control gains hexproof until end of turn.
Mode mode = new Mode(new GainAbilityTargetEffect(HexproofAbility.getInstance(), Duration.EndOfTurn)); Mode mode = new Mode(new GainAbilityTargetEffect(HexproofAbility.getInstance(), Duration.EndOfTurn));
mode.addTarget(new TargetControlledCreaturePermanent()); mode.addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addMode(mode.setFlavorWord("Hide")); this.getSpellAbility().addMode(mode.withFlavorWord("Hide"));
} }
private YouSeeAGuardApproach(final YouSeeAGuardApproach card) { private YouSeeAGuardApproach(final YouSeeAGuardApproach card) {

View file

@ -22,12 +22,12 @@ public final class YouSeeAPairOfGoblins extends CardImpl {
// Choose one // Choose one
// Charge Them Creatures you control get +2/+0 until end of turn. // Charge Them Creatures you control get +2/+0 until end of turn.
this.getSpellAbility().addEffect(new BoostControlledEffect(2, 0, Duration.EndOfTurn)); this.getSpellAbility().addEffect(new BoostControlledEffect(2, 0, Duration.EndOfTurn));
this.getSpellAbility().getEffects().setFlavorWord("Charge Them"); this.getSpellAbility().withFlavorWord("Charge Them");
// Befriend Them Create two 1/1 red Goblin creature tokens. // Befriend Them Create two 1/1 red Goblin creature tokens.
this.getSpellAbility().addMode(new Mode( this.getSpellAbility().addMode(new Mode(
new CreateTokenEffect(new GoblinToken(), 2) new CreateTokenEffect(new GoblinToken(), 2)
).setFlavorWord("Befriend Them")); ).withFlavorWord("Befriend Them"));
} }
private YouSeeAPairOfGoblins(final YouSeeAPairOfGoblins card) { private YouSeeAPairOfGoblins(final YouSeeAPairOfGoblins card) {

View file

@ -466,7 +466,13 @@ public interface Ability extends Controllable, Serializable {
*/ */
Ability setAbilityWord(AbilityWord abilityWord); Ability setAbilityWord(AbilityWord abilityWord);
Ability setFlavorWord(String flavorWord); /**
* Set Flavor word for current mode
*
* @param flavorWord
* @return
*/
Ability withFlavorWord(String flavorWord);
/** /**
* Creates the message about the ability casting/triggering/activating to * Creates the message about the ability casting/triggering/activating to

View file

@ -60,7 +60,6 @@ public abstract class AbilityImpl implements Ability {
protected Zone zone; protected Zone zone;
protected String name; protected String name;
protected AbilityWord abilityWord; protected AbilityWord abilityWord;
protected String flavorWord;
protected boolean usesStack = true; protected boolean usesStack = true;
protected boolean ruleAtTheTop = false; protected boolean ruleAtTheTop = false;
protected boolean ruleVisible = true; protected boolean ruleVisible = true;
@ -118,7 +117,6 @@ public abstract class AbilityImpl implements Ability {
this.ruleAdditionalCostsVisible = ability.ruleAdditionalCostsVisible; this.ruleAdditionalCostsVisible = ability.ruleAdditionalCostsVisible;
this.worksFaceDown = ability.worksFaceDown; this.worksFaceDown = ability.worksFaceDown;
this.abilityWord = ability.abilityWord; this.abilityWord = ability.abilityWord;
this.flavorWord = ability.flavorWord;
this.sourceObjectZoneChangeCounter = ability.sourceObjectZoneChangeCounter; this.sourceObjectZoneChangeCounter = ability.sourceObjectZoneChangeCounter;
this.canFizzle = ability.canFizzle; this.canFizzle = ability.canFizzle;
this.targetAdjuster = ability.targetAdjuster; this.targetAdjuster = ability.targetAdjuster;
@ -805,8 +803,6 @@ public abstract class AbilityImpl implements Ability {
String prefix; String prefix;
if (abilityWord != null) { if (abilityWord != null) {
prefix = abilityWord.formatWord(); prefix = abilityWord.formatWord();
} else if (flavorWord != null) {
prefix = "<i>" + flavorWord + "</i> &mdash; ";
} else { } else {
prefix = null; prefix = null;
} }
@ -1072,8 +1068,9 @@ public abstract class AbilityImpl implements Ability {
return this; return this;
} }
public Ability setFlavorWord(String flavorWord) { @Override
this.flavorWord = flavorWord; public Ability withFlavorWord(String flavorWord) {
this.getModes().getMode().withFlavorWord(flavorWord);
return this; return this;
} }

View file

@ -16,6 +16,7 @@ public class Mode implements Serializable {
protected UUID id; protected UUID id;
protected final Targets targets; protected final Targets targets;
protected final Effects effects; protected final Effects effects;
protected String flavorWord;
public Mode() { public Mode() {
this((Effect) null); this((Effect) null);
@ -34,6 +35,7 @@ public class Mode implements Serializable {
this.id = mode.id; this.id = mode.id;
this.targets = mode.targets.copy(); this.targets = mode.targets.copy();
this.effects = mode.effects.copy(); this.effects = mode.effects.copy();
this.flavorWord = mode.flavorWord;
} }
public UUID setRandomId() { public UUID setRandomId() {
@ -71,8 +73,18 @@ public class Mode implements Serializable {
effects.add(effect); effects.add(effect);
} }
public Mode setFlavorWord(String flavorWord) { public String getFlavorWord() {
effects.setFlavorWord(flavorWord); return flavorWord;
}
/**
* Set Flavor word to the mode (same as ability/ancher words, but uses for lore/info and represents a possible choices)
*
* @param flavorWord
* @return
*/
public Mode withFlavorWord(String flavorWord) {
this.flavorWord = flavorWord;
return this; return this;
} }
} }

View file

@ -14,14 +14,11 @@ import java.util.Arrays;
*/ */
public class Effects extends ArrayList<Effect> { public class Effects extends ArrayList<Effect> {
private String flavorWord = null;
public Effects(Effect... effects) { public Effects(Effect... effects) {
this.addAll(Arrays.asList(effects)); this.addAll(Arrays.asList(effects));
} }
public Effects(final Effects effects) { public Effects(final Effects effects) {
this.flavorWord = effects.flavorWord;
for (Effect effect : effects) { for (Effect effect : effects) {
this.add(effect.copy()); this.add(effect.copy());
} }
@ -64,7 +61,6 @@ public class Effects extends ArrayList<Effect> {
} }
} }
//check if nextRule is a new sentence or not. //check if nextRule is a new sentence or not.
if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) { if (nextRule.startsWith("and ") || nextRule.startsWith("with ") || nextRule.startsWith("then ")) {
endString = " "; endString = " ";
@ -100,7 +96,6 @@ public class Effects extends ArrayList<Effect> {
sbText.append(currentRule); sbText.append(currentRule);
lastRule = nextRule; lastRule = nextRule;
} }
// add punctuation to very last rule. // add punctuation to very last rule.
@ -113,11 +108,12 @@ public class Effects extends ArrayList<Effect> {
sbText.append('.'); sbText.append('.');
} }
if (flavorWord != null) { // flavor word
return "<i>" + flavorWord + "</i> &mdash; " + CardUtil.getTextWithFirstCharUpperCase(sbText.toString()); if (mode.getFlavorWord() != null) {
} return "<i>" + mode.getFlavorWord() + "</i> &mdash; " + CardUtil.getTextWithFirstCharUpperCase(sbText.toString());
return sbText.toString(); };
return sbText.toString();
} }
public boolean hasOutcome(Ability source, Outcome outcome) { public boolean hasOutcome(Ability source, Outcome outcome) {
@ -195,8 +191,4 @@ public class Effects extends ArrayList<Effect> {
effect.setValue(key, value); effect.setValue(key, value);
} }
} }
public void setFlavorWord(String flavorWord) {
this.flavorWord = flavorWord;
}
} }

View file

@ -497,7 +497,7 @@ public class StackAbility extends StackObjectImpl implements Ability {
} }
@Override @Override
public Ability setFlavorWord(String flavorWord) { public Ability withFlavorWord(String flavorWord) {
throw new UnsupportedOperationException("Not supported."); throw new UnsupportedOperationException("Not supported.");
} }