diff --git a/Mage.Sets/src/mage/cards/e/EllynHarbreezeBusybody.java b/Mage.Sets/src/mage/cards/e/EllynHarbreezeBusybody.java new file mode 100644 index 00000000000..405d284179d --- /dev/null +++ b/Mage.Sets/src/mage/cards/e/EllynHarbreezeBusybody.java @@ -0,0 +1,52 @@ +package mage.cards.e; + +import mage.MageInt; +import mage.abilities.common.ChooseABackgroundAbility; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.dynamicvalue.common.TokensCreatedThisTurnCount; +import mage.abilities.effects.common.LookLibraryAndPickControllerEffect; +import mage.abilities.effects.common.LookLibraryControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.watchers.common.CreatedTokenWatcher; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class EllynHarbreezeBusybody extends CardImpl { + + public EllynHarbreezeBusybody(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.PEASANT); + this.power = new MageInt(2); + this.toughness = new MageInt(4); + + // {T}: Look at the top X cards of your library, where X is the number of tokens you created this turn. Put one of those cards into your hand and the rest on the bottom of your library in a random order. + this.addAbility(new SimpleActivatedAbility(new LookLibraryAndPickControllerEffect( + TokensCreatedThisTurnCount.instance, 1, + LookLibraryControllerEffect.PutCards.HAND, + LookLibraryControllerEffect.PutCards.BOTTOM_RANDOM + ), new TapSourceCost()).addHint(TokensCreatedThisTurnCount.getHint()), new CreatedTokenWatcher()); + + // Choose a Background + this.addAbility(ChooseABackgroundAbility.getInstance()); + } + + private EllynHarbreezeBusybody(final EllynHarbreezeBusybody card) { + super(card); + } + + @Override + public EllynHarbreezeBusybody copy() { + return new EllynHarbreezeBusybody(this); + } +} diff --git a/Mage.Sets/src/mage/cards/t/ThalisseReverentMedium.java b/Mage.Sets/src/mage/cards/t/ThalisseReverentMedium.java index b45ef79bbb3..7cd0875121c 100644 --- a/Mage.Sets/src/mage/cards/t/ThalisseReverentMedium.java +++ b/Mage.Sets/src/mage/cards/t/ThalisseReverentMedium.java @@ -1,24 +1,18 @@ package mage.cards.t; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.BeginningOfEndStepTriggeredAbility; -import mage.abilities.dynamicvalue.DynamicValue; -import mage.abilities.effects.Effect; +import mage.abilities.dynamicvalue.common.TokensCreatedThisTurnCount; import mage.abilities.effects.common.CreateTokenEffect; -import mage.abilities.hint.Hint; -import mage.abilities.hint.ValueHint; import mage.cards.CardImpl; import mage.cards.CardSetInfo; -import mage.constants.*; -import mage.game.Game; -import mage.game.events.GameEvent; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.SuperType; +import mage.constants.TargetController; import mage.game.permanent.token.SpiritWhiteToken; -import mage.util.CardUtil; -import mage.watchers.Watcher; +import mage.watchers.common.CreatedTokenWatcher; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; /** @@ -26,11 +20,6 @@ import java.util.UUID; */ public final class ThalisseReverentMedium extends CardImpl { - private static final Hint hint = new ValueHint( - "The number of tokens you created this turn", - ThalisseReverentMediumValue.instance - ); - public ThalisseReverentMedium(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{3}{W}{B}"); @@ -42,8 +31,8 @@ public final class ThalisseReverentMedium extends CardImpl { // At the beginning of each end step, create X 1/1 white Spirit creature tokens with flying, where X is the number of tokens you created this turn. this.addAbility(new BeginningOfEndStepTriggeredAbility(new CreateTokenEffect( - new SpiritWhiteToken(), ThalisseReverentMediumValue.instance - ), TargetController.ANY, false).addHint(hint), new ThalisseReverentMediumWatcher()); + new SpiritWhiteToken(), TokensCreatedThisTurnCount.instance + ), TargetController.ANY, false).addHint(TokensCreatedThisTurnCount.getHint()), new CreatedTokenWatcher()); } private ThalisseReverentMedium(final ThalisseReverentMedium card) { @@ -55,55 +44,3 @@ public final class ThalisseReverentMedium extends CardImpl { return new ThalisseReverentMedium(this); } } - -enum ThalisseReverentMediumValue implements DynamicValue { - instance; - - @Override - public int calculate(Game game, Ability sourceAbility, Effect effect) { - ThalisseReverentMediumWatcher watcher = game.getState().getWatcher(ThalisseReverentMediumWatcher.class); - return watcher == null ? 0 : watcher.getTokenCount(sourceAbility.getControllerId()); - } - - @Override - public ThalisseReverentMediumValue copy() { - return instance; - } - - @Override - public String getMessage() { - return "the number of tokens you created this turn"; - } - - @Override - public String toString() { - return "X"; - } -} - -class ThalisseReverentMediumWatcher extends Watcher { - - private final Map tokenMap = new HashMap<>(); - - ThalisseReverentMediumWatcher() { - super(WatcherScope.GAME); - } - - @Override - public void watch(GameEvent event, Game game) { - if (event.getType() != GameEvent.EventType.CREATED_TOKEN) { - return; - } - tokenMap.compute(event.getPlayerId(), CardUtil::setOrIncrementValue); - } - - @Override - public void reset() { - tokenMap.clear(); - super.reset(); - } - - int getTokenCount(UUID playerId) { - return tokenMap.getOrDefault(playerId, 0); - } -} diff --git a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java index 52d25cb328f..944d721a12c 100644 --- a/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java +++ b/Mage.Sets/src/mage/sets/CommanderLegendsBattleForBaldursGate.java @@ -48,6 +48,7 @@ public final class CommanderLegendsBattleForBaldursGate extends ExpansionSet { cards.add(new SetCardInfo("Dungeon Delver", 67, Rarity.UNCOMMON, mage.cards.d.DungeonDelver.class)); cards.add(new SetCardInfo("Dungeoneer's Pack", 312, Rarity.UNCOMMON, mage.cards.d.DungeoneersPack.class)); cards.add(new SetCardInfo("Elder Brain", 125, Rarity.RARE, mage.cards.e.ElderBrain.class)); + cards.add(new SetCardInfo("Ellyn Harbreeze, Busybody", 16, Rarity.UNCOMMON, mage.cards.e.EllynHarbreezeBusybody.class)); cards.add(new SetCardInfo("Elminster", 274, Rarity.MYTHIC, mage.cards.e.Elminster.class)); cards.add(new SetCardInfo("Elminster's Simulacrum", 561, Rarity.MYTHIC, mage.cards.e.ElminstersSimulacrum.class)); cards.add(new SetCardInfo("Erinis, Gloom Stalker", 230, Rarity.UNCOMMON, mage.cards.e.ErinisGloomStalker.class)); diff --git a/Mage/src/main/java/mage/abilities/dynamicvalue/common/TokensCreatedThisTurnCount.java b/Mage/src/main/java/mage/abilities/dynamicvalue/common/TokensCreatedThisTurnCount.java new file mode 100644 index 00000000000..75abe92ced3 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/dynamicvalue/common/TokensCreatedThisTurnCount.java @@ -0,0 +1,41 @@ +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.effects.Effect; +import mage.abilities.hint.Hint; +import mage.abilities.hint.ValueHint; +import mage.game.Game; +import mage.watchers.common.CreatedTokenWatcher; + +/** + * @author TheElk801 + */ +public enum TokensCreatedThisTurnCount implements DynamicValue { + instance; + private static final Hint hint = new ValueHint("The number of tokens you created this turn", instance); + + public static Hint getHint() { + return hint; + } + + @Override + public int calculate(Game game, Ability sourceAbility, Effect effect) { + return CreatedTokenWatcher.getPlayerCount(sourceAbility.getControllerId(), game); + } + + @Override + public TokensCreatedThisTurnCount copy() { + return instance; + } + + @Override + public String getMessage() { + return "the number of tokens you created this turn"; + } + + @Override + public String toString() { + return "X"; + } +} diff --git a/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java b/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java index 9f90d038614..2e948ad8c3f 100644 --- a/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java @@ -3,10 +3,11 @@ package mage.watchers.common; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; +import mage.util.CardUtil; import mage.watchers.Watcher; -import java.util.HashSet; -import java.util.Set; +import java.util.HashMap; +import java.util.Map; import java.util.UUID; /** @@ -14,7 +15,7 @@ import java.util.UUID; */ public class CreatedTokenWatcher extends Watcher { - private final Set playerIds = new HashSet<>(); + private final Map playerMap = new HashMap<>(); public CreatedTokenWatcher() { super(WatcherScope.GAME); @@ -23,16 +24,24 @@ public class CreatedTokenWatcher extends Watcher { @Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.CREATED_TOKEN) { - playerIds.add(event.getPlayerId()); + playerMap.compute(event.getPlayerId(), CardUtil::setOrIncrementValue); } } @Override public void reset() { - playerIds.clear(); + playerMap.clear(); } public static boolean checkPlayer(UUID playerId, Game game) { - return game.getState().getWatcher(CreatedTokenWatcher.class).playerIds.contains(playerId); + return getPlayerCount(playerId, game) > 0; + } + + public static int getPlayerCount(UUID playerId, Game game) { + return game + .getState() + .getWatcher(CreatedTokenWatcher.class) + .playerMap + .getOrDefault(playerId, 0); } }