From fd281ca4837de209acdc42bb3e3ae72ae3f88961 Mon Sep 17 00:00:00 2001 From: "Alex W. Jackson" Date: Sat, 8 Oct 2022 20:48:59 -0400 Subject: [PATCH] Improve text generation for some common draw, discard and mill effects --- .../src/mage/cards/t/TamiyoTheMoonSage.java | 2 +- .../src/mage/cards/u/UrborgLhurgoyf.java | 8 ++--- .../dynamicvalue/common/MultikickerCount.java | 2 +- .../DrawCardSourceControllerEffect.java | 33 ++++++------------- .../common/MillCardsControllerEffect.java | 17 ++++++---- .../discard/DiscardControllerEffect.java | 12 +++---- .../common/discard/DiscardTargetEffect.java | 19 ++++------- Mage/src/main/java/mage/util/CardUtil.java | 3 +- 8 files changed, 37 insertions(+), 59 deletions(-) diff --git a/Mage.Sets/src/mage/cards/t/TamiyoTheMoonSage.java b/Mage.Sets/src/mage/cards/t/TamiyoTheMoonSage.java index 6b2f271d4f..9a37497176 100644 --- a/Mage.Sets/src/mage/cards/t/TamiyoTheMoonSage.java +++ b/Mage.Sets/src/mage/cards/t/TamiyoTheMoonSage.java @@ -82,7 +82,7 @@ class TappedCreaturesControlledByTargetCount implements DynamicValue { @Override public String toString() { - return "a"; + return "1"; } @Override diff --git a/Mage.Sets/src/mage/cards/u/UrborgLhurgoyf.java b/Mage.Sets/src/mage/cards/u/UrborgLhurgoyf.java index 9bcd268768..5ae1108e88 100644 --- a/Mage.Sets/src/mage/cards/u/UrborgLhurgoyf.java +++ b/Mage.Sets/src/mage/cards/u/UrborgLhurgoyf.java @@ -1,7 +1,7 @@ package mage.cards.u; import mage.MageInt; -import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.common.AsEntersBattlefieldAbility; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.dynamicvalue.IntPlusDynamicValue; import mage.abilities.dynamicvalue.DynamicValue; @@ -40,11 +40,7 @@ public final class UrborgLhurgoyf extends CardImpl { this.addAbility(kickerAbility); // As Urborg Lhurgoyf enters the battlefield, mill three cards for each time it was kicked. - this.addAbility(new EntersBattlefieldAbility( - new MillCardsControllerEffect(millValue), null, - "As {this} enters the battlefield, " + - "mill three cards for each time it was kicked.", "" - )); + this.addAbility(new AsEntersBattlefieldAbility(new MillCardsControllerEffect(millValue))); // Urborg Lhurgoyf's power is equal to the number of creature cards in your graveyard and its toughness is equal to that number plus 1. this.addAbility(new SimpleStaticAbility( diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/MultikickerCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/MultikickerCount.java index 5766208290..0860d2e847 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/MultikickerCount.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/MultikickerCount.java @@ -26,7 +26,7 @@ public enum MultikickerCount implements DynamicValue { @Override public String toString() { - return "a"; + return "1"; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/common/DrawCardSourceControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/DrawCardSourceControllerEffect.java index 70b2943580..bb92131714 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/DrawCardSourceControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/DrawCardSourceControllerEffect.java @@ -17,7 +17,6 @@ import mage.util.CardUtil; public class DrawCardSourceControllerEffect extends OneShotEffect { protected DynamicValue amount; - protected String whoDrawCard = ""; public DrawCardSourceControllerEffect(int amount) { this(amount, ""); @@ -34,13 +33,12 @@ public class DrawCardSourceControllerEffect extends OneShotEffect { public DrawCardSourceControllerEffect(DynamicValue amount, String whoDrawCard) { super(Outcome.DrawCard); this.amount = amount.copy(); - this.whoDrawCard = whoDrawCard; + createStaticText(whoDrawCard); } public DrawCardSourceControllerEffect(final DrawCardSourceControllerEffect effect) { super(effect); this.amount = effect.amount.copy(); - this.whoDrawCard = effect.whoDrawCard; } @Override @@ -59,28 +57,17 @@ public class DrawCardSourceControllerEffect extends OneShotEffect { return false; } - @Override - public String getText(Mode mode) { - if (staticText != null && !staticText.isEmpty()) { - return staticText; - } - 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(whoDrawCard.isEmpty() ? "" : whoDrawCard - + " ").append("draw ").append(oneCard ? "a" - : CardUtil.numberToText(amount.toString())).append(" card"); - if (!oneCard) { - sb.append('s'); - } + private void createStaticText(String whoDrawCard) { + StringBuilder sb = new StringBuilder(whoDrawCard); + sb.append(whoDrawCard.isEmpty() ? "draw " : " draw "); + String value = amount.toString(); + sb.append(CardUtil.numberToText(value, "a")); + sb.append(value.equals("1") ? " card" : " cards"); String message = amount.getMessage(); if (!message.isEmpty()) { - sb.append(" for each "); + sb.append(value.equals("X") ? ", where X is " : " for each "); + sb.append(message); } - sb.append(message); - return sb.toString(); + staticText = sb.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/MillCardsControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/MillCardsControllerEffect.java index 6ec19874f6..58de3c44e5 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/MillCardsControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/MillCardsControllerEffect.java @@ -25,6 +25,7 @@ public class MillCardsControllerEffect extends OneShotEffect { public MillCardsControllerEffect(DynamicValue numberCards) { super(Outcome.Discard); this.numberCards = numberCards; + setText(); } public MillCardsControllerEffect(final MillCardsControllerEffect effect) { @@ -45,12 +46,16 @@ public class MillCardsControllerEffect extends OneShotEffect { ).isEmpty(); } - @Override - public String getText(Mode mode) { - if (numberCards instanceof StaticValue) { - return "mill " + (((StaticValue) numberCards).getValue() > 1 ? - CardUtil.numberToText(numberCards.toString()) + " cards" : "a card"); + private void setText() { + StringBuilder sb = new StringBuilder("mill "); + String value = numberCards.toString(); + sb.append(CardUtil.numberToText(value, "a")); + sb.append(value.equals("1") ? " card" : " cards"); + String message = numberCards.getMessage(); + if (!message.isEmpty()) { + sb.append(value.equals("X") ? ", where X is " : " for each "); + sb.append(message); } - return "mill X cards, where X is " + numberCards.getMessage(); + staticText = sb.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java index 02c7e62ad6..112e7f5b53 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardControllerEffect.java @@ -55,19 +55,17 @@ public class DiscardControllerEffect extends OneShotEffect { private void setText() { StringBuilder sb = new StringBuilder("discard "); - if (amount.toString().equals("1") || amount.toString().equals("a")) { - sb.append("a card"); - } else { - sb.append(CardUtil.numberToText(amount.toString())).append(" cards"); - } + String value = amount.toString(); + sb.append(CardUtil.numberToText(value, "a")); + sb.append(value.equals("1") ? " card" : " cards"); if (randomDiscard) { sb.append(" at random"); } String message = amount.getMessage(); if (!message.isEmpty()) { - sb.append(" for each "); + sb.append(value.equals("X") ? ", where X is " : " for each "); + sb.append(message); } - sb.append(message); staticText = sb.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardTargetEffect.java index cf849c3aaf..9ba8674935 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/discard/DiscardTargetEffect.java @@ -74,26 +74,19 @@ public class DiscardTargetEffect extends OneShotEffect { if (staticText != null && !staticText.isEmpty()) { return staticText; } - StringBuilder sb = new StringBuilder(); - if (mode.getTargets().isEmpty()) { - sb.append("that player"); - } else { - sb.append("target ").append(mode.getTargets().get(0).getTargetName()); - } + StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), "that player")); sb.append(" discards "); - if (amount.toString().equals("1") || amount.toString().equals("a")) { - sb.append("a card"); - } else { - sb.append(CardUtil.numberToText(amount.toString())).append(" cards"); - } + String value = amount.toString(); + sb.append(CardUtil.numberToText(value, "a")); + sb.append(value.equals("1") ? " card" : " cards"); if (randomDiscard) { sb.append(" at random"); } String message = amount.getMessage(); if (!message.isEmpty()) { - sb.append(" for each "); + sb.append(value.equals("X") ? ", where X is " : " for each "); + sb.append(message); } - sb.append(message); return sb.toString(); } } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index f0cb437add..577bf30f95 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -546,8 +546,7 @@ public final class CardUtil { } public static boolean checkNumeric(String s) { - return s.chars().allMatch(Character::isDigit); - + return !s.isEmpty() && s.chars().allMatch(Character::isDigit); } /**