diff --git a/Mage.Sets/src/mage/cards/v/VaziKeenNegotiator.java b/Mage.Sets/src/mage/cards/v/VaziKeenNegotiator.java index 5fab263e38..a2ccbddfa6 100644 --- a/Mage.Sets/src/mage/cards/v/VaziKeenNegotiator.java +++ b/Mage.Sets/src/mage/cards/v/VaziKeenNegotiator.java @@ -50,6 +50,7 @@ public class VaziKeenNegotiator extends CardImpl { // {T}: Target opponent creates X Treasure tokens, where X is the number of Treasure tokens you created this turn. Ability tapAbility = new SimpleActivatedAbility(new CreateTokenTargetEffect(new TreasureToken(), VaziKeenNegotiatorNumberOfTokensCreated.instance), new TapSourceCost()); tapAbility.addTarget(new TargetOpponent()); + tapAbility.addWatcher(new CreatedTokenWatcher()); this.addAbility(tapAbility); // Whenever an opponent casts a spell or activates an ability, @@ -113,7 +114,7 @@ enum VaziKeenNegotiatorNumberOfTokensCreated implements DynamicValue { @Override public int calculate(Game game, Ability sourceAbility, Effect effect) { - return CreatedTokenWatcher.getTypeCreatedCountByPlayer(sourceAbility.getControllerId(), TreasureToken.class, game); + return CreatedTokenWatcher.getTypeCreatedCountByPlayer(sourceAbility.getControllerId(), SubType.TREASURE, game); } @Override @@ -130,4 +131,4 @@ enum VaziKeenNegotiatorNumberOfTokensCreated implements DynamicValue { public String toString() { return "X"; } -} \ No newline at end of file +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/ncc/VaziKeenNegotiatorTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/ncc/VaziKeenNegotiatorTest.java new file mode 100644 index 0000000000..3bbaa2bb0f --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/ncc/VaziKeenNegotiatorTest.java @@ -0,0 +1,31 @@ +package org.mage.test.cards.single.ncc; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * @author awjackson + */ +public class VaziKeenNegotiatorTest extends CardTestPlayerBase { + @Test + public void testVaziActivatedAbility() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 3); + addCard(Zone.BATTLEFIELD, playerA, "Vazi, Keen Negotiator"); + addCard(Zone.HAND, playerA, "Krenko's Command"); // Create two 1/1 red Goblin creature tokens + addCard(Zone.HAND, playerA, "Strike It Rich"); // Create a Treasure token + + setStrictChooseMode(true); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Krenko's Command", true); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Strike It Rich", true); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target opponent creates", playerB); + + setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); + execute(); + + assertPermanentCount(playerA, "Goblin Token", 2); + assertPermanentCount(playerA, "Treasure Token", 1); + assertPermanentCount(playerB, "Treasure Token", 1); + } +} diff --git a/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java b/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java index e87b867c44..6f8f41acf8 100644 --- a/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java +++ b/Mage/src/main/java/mage/watchers/common/CreatedTokenWatcher.java @@ -4,10 +4,12 @@ import mage.cards.Card; import mage.constants.WatcherScope; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.permanent.token.Token; +import mage.game.permanent.Permanent; +import mage.constants.SubType; import mage.util.CardUtil; import mage.watchers.Watcher; +import java.util.EnumMap; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -19,7 +21,7 @@ public class CreatedTokenWatcher extends Watcher { // Player ID to Number of tokens created private final Map playerMap = new HashMap<>(); - private final Map, Integer>> tokenCreatedMap = new HashMap<>(); + private final Map> tokenCreatedMap = new HashMap<>(); public CreatedTokenWatcher() { super(WatcherScope.GAME); @@ -31,9 +33,12 @@ public class CreatedTokenWatcher extends Watcher { playerMap.compute(event.getPlayerId(), CardUtil::setOrIncrementValue); tokenCreatedMap.putIfAbsent(event.getPlayerId(), new HashMap<>()); - Class tokenClazz = ((Token) game.getPermanent(event.getTargetId())).getClass(); - Map, Integer> playersTokens = tokenCreatedMap.getOrDefault(event.getPlayerId(), new HashMap<>()); - playersTokens.compute(tokenClazz, CardUtil::setOrIncrementValue); + Permanent token = game.getPermanent(event.getTargetId()); + Map playersTokens = tokenCreatedMap.getOrDefault(event.getPlayerId(), new EnumMap<>(SubType.class)); + // TODO: this doesn't handle tokens that are all creature types + for (SubType subType : token.getSubtype(game)) { + playersTokens.compute(subType, CardUtil::setOrIncrementValue); + } tokenCreatedMap.put(event.getPlayerId(), playersTokens); } } @@ -56,12 +61,12 @@ public class CreatedTokenWatcher extends Watcher { .getOrDefault(playerId, 0); } - public static int getTypeCreatedCountByPlayer(UUID playerId, Class tokenCLazz, Game game) { + public static int getTypeCreatedCountByPlayer(UUID playerId, SubType tokenType, Game game) { return game .getState() .getWatcher(CreatedTokenWatcher.class) .tokenCreatedMap - .getOrDefault(playerId, new HashMap<>()) - .getOrDefault(tokenCLazz, 0); + .getOrDefault(playerId, new EnumMap<>(SubType.class)) + .getOrDefault(tokenType, 0); } }