From 01b797f4948a978f782bb030c1f1675c03996c8e Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Fri, 23 Apr 2021 09:42:06 -0400 Subject: [PATCH] reworked alara heralds --- Mage.Sets/src/mage/cards/a/AngelsHerald.java | 28 ++----- .../src/mage/cards/b/BehemothsHerald.java | 30 ++------ Mage.Sets/src/mage/cards/c/Conflux.java | 2 +- Mage.Sets/src/mage/cards/d/DemonsHerald.java | 30 ++------ Mage.Sets/src/mage/cards/d/DragonsHerald.java | 30 ++------ Mage.Sets/src/mage/cards/s/SphinxsHerald.java | 32 +++----- .../costs/common/SacrificeTargetCost.java | 4 +- .../dynamicvalue/common/ColorAssignment.java | 15 ++-- .../TargetControlledCreatureEachColor.java | 76 +++++++++++++++++++ Mage/src/main/java/mage/util/CardUtil.java | 23 ++++++ 10 files changed, 152 insertions(+), 118 deletions(-) create mode 100644 Mage/src/main/java/mage/target/common/TargetControlledCreatureEachColor.java diff --git a/Mage.Sets/src/mage/cards/a/AngelsHerald.java b/Mage.Sets/src/mage/cards/a/AngelsHerald.java index 17afd86366..9947d5e8b4 100644 --- a/Mage.Sets/src/mage/cards/a/AngelsHerald.java +++ b/Mage.Sets/src/mage/cards/a/AngelsHerald.java @@ -1,9 +1,6 @@ - package mage.cards.a; -import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeTargetCost; @@ -14,13 +11,12 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterControlledCreaturePermanent; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.NamePredicate; import mage.target.common.TargetCardInLibrary; -import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetControlledCreatureEachColor; + +import java.util.UUID; /** * @author nantuko @@ -28,19 +24,13 @@ import mage.target.common.TargetControlledCreaturePermanent; public final class AngelsHerald extends CardImpl { private static final FilterCard filter = new FilterCard("card named Empyrial Archangel"); - private static final FilterControlledCreaturePermanent filterGreen = new FilterControlledCreaturePermanent("a green creature"); - private static final FilterControlledCreaturePermanent filterWhite = new FilterControlledCreaturePermanent("a white creature"); - private static final FilterControlledCreaturePermanent filterBlue = new FilterControlledCreaturePermanent("a blue creature"); static { filter.add(new NamePredicate("Empyrial Archangel")); - filterGreen.add(new ColorPredicate(ObjectColor.GREEN)); - filterWhite.add(new ColorPredicate(ObjectColor.WHITE)); - filterBlue.add(new ColorPredicate(ObjectColor.BLUE)); } public AngelsHerald(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{W}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{W}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.CLERIC); @@ -49,13 +39,11 @@ public final class AngelsHerald extends CardImpl { // {2}{W}, {tap}, Sacrifice a green creature, a white creature, and a blue creature: // Search your library for a card named Empyrial Archangel and put it onto the battlefield. Then shuffle your library. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new SearchLibraryPutInPlayEffect(new TargetCardInLibrary(1, 1, new FilterCard(filter))), - new ManaCostsImpl("{2}{W}")); + Ability ability = new SimpleActivatedAbility(new SearchLibraryPutInPlayEffect( + new TargetCardInLibrary(filter)), new ManaCostsImpl<>("{2}{W}") + ); ability.addCost(new TapSourceCost()); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterGreen, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterWhite, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlue, false))); + ability.addCost(new SacrificeTargetCost(new TargetControlledCreatureEachColor("GWU"))); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/b/BehemothsHerald.java b/Mage.Sets/src/mage/cards/b/BehemothsHerald.java index f29f57711d..bfcae12781 100644 --- a/Mage.Sets/src/mage/cards/b/BehemothsHerald.java +++ b/Mage.Sets/src/mage/cards/b/BehemothsHerald.java @@ -1,9 +1,6 @@ - package mage.cards.b; -import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeTargetCost; @@ -14,34 +11,26 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterControlledCreaturePermanent; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.NamePredicate; import mage.target.common.TargetCardInLibrary; -import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetControlledCreatureEachColor; + +import java.util.UUID; /** - * * @author North */ public final class BehemothsHerald extends CardImpl { private static final FilterCard filter = new FilterCard("card named Godsire"); - private static final FilterControlledCreaturePermanent filterRed = new FilterControlledCreaturePermanent("a red creature"); - private static final FilterControlledCreaturePermanent filterGreen = new FilterControlledCreaturePermanent("a green creature"); - private static final FilterControlledCreaturePermanent filterWhite = new FilterControlledCreaturePermanent("a white creature"); static { filter.add(new NamePredicate("Godsire")); - filterRed.add(new ColorPredicate(ObjectColor.RED)); - filterGreen.add(new ColorPredicate(ObjectColor.GREEN)); - filterWhite.add(new ColorPredicate(ObjectColor.WHITE)); } public BehemothsHerald(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{G}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{G}"); this.subtype.add(SubType.ELF, SubType.SHAMAN); this.power = new MageInt(1); @@ -49,14 +38,11 @@ public final class BehemothsHerald extends CardImpl { // {2}{G}, {tap}, Sacrifice a red creature, a green creature, and a white creature: // Search your library for a card named Godsire and put it onto the battlefield. Then shuffle your library. - TargetCardInLibrary target = new TargetCardInLibrary(1, 1, new FilterCard(filter)); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new SearchLibraryPutInPlayEffect(target), - new ManaCostsImpl("{2}{G}")); + Ability ability = new SimpleActivatedAbility(new SearchLibraryPutInPlayEffect( + new TargetCardInLibrary(filter)), new ManaCostsImpl<>("{2}{G}") + ); ability.addCost(new TapSourceCost()); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterRed, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterGreen, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterWhite, false))); + ability.addCost(new SacrificeTargetCost(new TargetControlledCreatureEachColor("RGW"))); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/c/Conflux.java b/Mage.Sets/src/mage/cards/c/Conflux.java index f1d970c94c..524fe867c8 100644 --- a/Mage.Sets/src/mage/cards/c/Conflux.java +++ b/Mage.Sets/src/mage/cards/c/Conflux.java @@ -47,7 +47,7 @@ class ConfluxTarget extends TargetCardInLibrary { filter.add(Predicates.not(ColorlessPredicate.instance)); } - private static final ColorAssignment colorAssigner = new ColorAssignment(); + private static final ColorAssignment colorAssigner = new ColorAssignment("W", "U", "B", "R", "G"); ConfluxTarget() { super(0, 5, filter); diff --git a/Mage.Sets/src/mage/cards/d/DemonsHerald.java b/Mage.Sets/src/mage/cards/d/DemonsHerald.java index 29df9abb10..bb91661560 100644 --- a/Mage.Sets/src/mage/cards/d/DemonsHerald.java +++ b/Mage.Sets/src/mage/cards/d/DemonsHerald.java @@ -1,9 +1,6 @@ - package mage.cards.d; -import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeTargetCost; @@ -14,34 +11,26 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterControlledCreaturePermanent; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.NamePredicate; import mage.target.common.TargetCardInLibrary; -import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetControlledCreatureEachColor; + +import java.util.UUID; /** - * * @author North */ public final class DemonsHerald extends CardImpl { private static final FilterCard filter = new FilterCard("card named Prince of Thralls"); - private static final FilterControlledCreaturePermanent filterBlue = new FilterControlledCreaturePermanent("a blue creature"); - private static final FilterControlledCreaturePermanent filterBlack = new FilterControlledCreaturePermanent("a black creature"); - private static final FilterControlledCreaturePermanent filterRed = new FilterControlledCreaturePermanent("a red creature"); static { filter.add(new NamePredicate("Prince of Thralls")); - filterBlue.add(new ColorPredicate(ObjectColor.BLUE)); - filterBlack.add(new ColorPredicate(ObjectColor.BLACK)); - filterRed.add(new ColorPredicate(ObjectColor.RED)); } public DemonsHerald(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{B}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{B}"); this.subtype.add(SubType.HUMAN); this.subtype.add(SubType.WIZARD); @@ -50,14 +39,11 @@ public final class DemonsHerald extends CardImpl { // {2}{B}, {tap}, Sacrifice a blue creature, a black creature, and a red creature: // Search your library for a card named Prince of Thralls and put it onto the battlefield. Then shuffle your library. - TargetCardInLibrary target = new TargetCardInLibrary(1, 1, new FilterCard(filter)); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new SearchLibraryPutInPlayEffect(target), - new ManaCostsImpl("{2}{B}")); + Ability ability = new SimpleActivatedAbility(new SearchLibraryPutInPlayEffect( + new TargetCardInLibrary(filter)), new ManaCostsImpl<>("{2}{B}") + ); ability.addCost(new TapSourceCost()); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlue, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlack, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterRed, false))); + ability.addCost(new SacrificeTargetCost(new TargetControlledCreatureEachColor("UBR"))); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/d/DragonsHerald.java b/Mage.Sets/src/mage/cards/d/DragonsHerald.java index c1e8e799af..d93f811c5c 100644 --- a/Mage.Sets/src/mage/cards/d/DragonsHerald.java +++ b/Mage.Sets/src/mage/cards/d/DragonsHerald.java @@ -1,9 +1,6 @@ - package mage.cards.d; -import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeTargetCost; @@ -14,34 +11,26 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterControlledCreaturePermanent; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.NamePredicate; import mage.target.common.TargetCardInLibrary; -import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetControlledCreatureEachColor; + +import java.util.UUID; /** - * * @author North */ public final class DragonsHerald extends CardImpl { private static final FilterCard filter = new FilterCard("card named Hellkite Overlord"); - private static final FilterControlledCreaturePermanent filterBlack = new FilterControlledCreaturePermanent("a black creature"); - private static final FilterControlledCreaturePermanent filterRed = new FilterControlledCreaturePermanent("a red creature"); - private static final FilterControlledCreaturePermanent filterGreen = new FilterControlledCreaturePermanent("a green creature"); static { filter.add(new NamePredicate("Hellkite Overlord")); - filterBlack.add(new ColorPredicate(ObjectColor.BLACK)); - filterRed.add(new ColorPredicate(ObjectColor.RED)); - filterGreen.add(new ColorPredicate(ObjectColor.GREEN)); } public DragonsHerald(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{R}"); this.subtype.add(SubType.GOBLIN); this.subtype.add(SubType.SHAMAN); @@ -50,14 +39,11 @@ public final class DragonsHerald extends CardImpl { // {2}{R}, {tap}, Sacrifice a black creature, a red creature, and a green creature: // Search your library for a card named Hellkite Overlord and put it onto the battlefield. Then shuffle your library. - TargetCardInLibrary target = new TargetCardInLibrary(1, 1, new FilterCard(filter)); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new SearchLibraryPutInPlayEffect(target), - new ManaCostsImpl("{2}{R}")); + Ability ability = new SimpleActivatedAbility(new SearchLibraryPutInPlayEffect( + new TargetCardInLibrary(filter)), new ManaCostsImpl<>("{2}{R}") + ); ability.addCost(new TapSourceCost()); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlack, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterRed, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterGreen, false))); + ability.addCost(new SacrificeTargetCost(new TargetControlledCreatureEachColor("BRG"))); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/cards/s/SphinxsHerald.java b/Mage.Sets/src/mage/cards/s/SphinxsHerald.java index 687a735120..1518737ec1 100644 --- a/Mage.Sets/src/mage/cards/s/SphinxsHerald.java +++ b/Mage.Sets/src/mage/cards/s/SphinxsHerald.java @@ -1,9 +1,6 @@ - package mage.cards.s; -import java.util.UUID; import mage.MageInt; -import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.common.SacrificeTargetCost; @@ -14,32 +11,26 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; -import mage.constants.Zone; import mage.filter.FilterCard; -import mage.filter.common.FilterControlledCreaturePermanent; -import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.mageobject.NamePredicate; import mage.target.common.TargetCardInLibrary; -import mage.target.common.TargetControlledCreaturePermanent; +import mage.target.common.TargetControlledCreatureEachColor; + +import java.util.UUID; /** - * * @author North */ public final class SphinxsHerald extends CardImpl { + private static final FilterCard filter = new FilterCard("card named Sphinx Sovereign"); - private static final FilterControlledCreaturePermanent filterWhite = new FilterControlledCreaturePermanent("a white creature"); - private static final FilterControlledCreaturePermanent filterBlue = new FilterControlledCreaturePermanent("a blue creature"); - private static final FilterControlledCreaturePermanent filterBlack = new FilterControlledCreaturePermanent("a black creature"); static { filter.add(new NamePredicate("Sphinx Sovereign")); - filterWhite.add(new ColorPredicate(ObjectColor.WHITE)); - filterBlue.add(new ColorPredicate(ObjectColor.BLUE)); - filterBlack.add(new ColorPredicate(ObjectColor.BLACK)); } + public SphinxsHerald(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{U}"); this.subtype.add(SubType.VEDALKEN); this.subtype.add(SubType.WIZARD); @@ -48,14 +39,11 @@ public final class SphinxsHerald extends CardImpl { // {2}{U}, {tap}, Sacrifice a white creature, a blue creature, and a black creature: // Search your library for a card named Sphinx Sovereign and put it onto the battlefield. Then shuffle your library. - TargetCardInLibrary target = new TargetCardInLibrary(1, 1, new FilterCard(filter)); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new SearchLibraryPutInPlayEffect(target), - new ManaCostsImpl("{2}{U}")); + Ability ability = new SimpleActivatedAbility(new SearchLibraryPutInPlayEffect( + new TargetCardInLibrary(filter)), new ManaCostsImpl<>("{2}{U}") + ); ability.addCost(new TapSourceCost()); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterWhite, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlue, false))); - ability.addCost(new SacrificeTargetCost(new TargetControlledCreaturePermanent(1, 1, filterBlack, false))); + ability.addCost(new SacrificeTargetCost(new TargetControlledCreatureEachColor("WUB"))); this.addAbility(ability); } diff --git a/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java b/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java index 27c96f3dae..fdd4b8cbe9 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/SacrificeTargetCost.java @@ -103,7 +103,9 @@ public class SacrificeTargetCost extends CostImpl { if (target.getMinNumberOfTargets() != target.getMaxNumberOfTargets()) { return target.getTargetName(); } - if (target.getNumberOfTargets() == 1) { + if (target.getNumberOfTargets() == 1 + || target.getTargetName().startsWith("a ") + || target.getTargetName().startsWith("an ")) { return CardUtil.addArticle(target.getTargetName()); } return CardUtil.numberToText(target.getNumberOfTargets()) + ' ' + target.getTargetName(); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/ColorAssignment.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/ColorAssignment.java index 40e012f390..b915b236d6 100644 --- a/Mage/src/main/java/mage/abilities/dynamicvalue/common/ColorAssignment.java +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/ColorAssignment.java @@ -4,21 +4,20 @@ import mage.abilities.dynamicvalue.RoleAssignment; import mage.cards.Card; import mage.game.Game; -import java.util.HashSet; +import java.util.Arrays; import java.util.Set; +import java.util.stream.Collectors; public class ColorAssignment extends RoleAssignment { - public ColorAssignment() { - super("W", "U", "B", "R", "G"); + public ColorAssignment(String... colors) { + super(colors); } @Override protected Set makeSet(Card card, Game game) { - Set strings = new HashSet<>(); - for (char c : card.getColor(game).toString().toCharArray()) { - strings.add("" + c); - } - return strings; + return Arrays.stream(card.getColor(game).toString().split("")) + .filter(attributes::contains) + .collect(Collectors.toSet()); } } diff --git a/Mage/src/main/java/mage/target/common/TargetControlledCreatureEachColor.java b/Mage/src/main/java/mage/target/common/TargetControlledCreatureEachColor.java new file mode 100644 index 0000000000..e47df1e4de --- /dev/null +++ b/Mage/src/main/java/mage/target/common/TargetControlledCreatureEachColor.java @@ -0,0 +1,76 @@ +package mage.target.common; + +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.ColorAssignment; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.filter.common.FilterControlledCreaturePermanent; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.util.CardUtil; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +/** + * @author TheElk801 + */ +public class TargetControlledCreatureEachColor extends TargetControlledPermanent { + + private final ColorAssignment colorAssigner; + + private static final FilterControlledPermanent makeFilter(String colors) { + List objectColors + = Arrays.stream(colors.split("")) + .map(ObjectColor::new) + .collect(Collectors.toList()); + FilterControlledPermanent filter + = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd( + objectColors + .stream() + .map(ObjectColor::getDescription) + .map(s -> CardUtil.addArticle(s) + " creature") + .collect(Collectors.toList()) + )); + filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList()))); + return filter; + } + + public TargetControlledCreatureEachColor(String colors) { + super(colors.length(), makeFilter(colors)); + colorAssigner = new ColorAssignment(colors.split("")); + } + + private TargetControlledCreatureEachColor(final TargetControlledCreatureEachColor target) { + super(target); + this.colorAssigner = target.colorAssigner; + } + + @Override + public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) { + if (!super.canTarget(playerId, id, source, game)) { + return false; + } + Permanent permanent = game.getPermanent(id); + if (permanent == null) { + return false; + } + if (this.getTargets().isEmpty()) { + return true; + } + Cards cards = new CardsImpl(this.getTargets()); + cards.add(permanent); + return colorAssigner.getRoleCount(cards, game) >= cards.size(); + } + + @Override + public TargetControlledCreatureEachColor copy() { + return new TargetControlledCreatureEachColor(this); + } +} diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 7b72bc97e4..9d138428d0 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -1338,4 +1338,27 @@ public final class CardUtil { // normal game return "T" + gameState.getTurnNum() + "." + gameState.getTurn().getStep().getType().getStepShortText(); } + + public static String concatWithAnd(List strings) { + switch (strings.size()) { + case 0: + return ""; + case 1: + return strings.get(0); + case 2: + return strings.get(0) + " and " + strings.get(1); + } + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < strings.size(); i++) { + sb.append(strings.get(i)); + if (i == strings.size() - 1) { + break; + } + sb.append(", "); + if (i == strings.size() - 2) { + sb.append("and "); + } + } + return sb.toString(); + } }