mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Fix #9562 and add test for Vazi
This commit is contained in:
parent
3f09836c64
commit
17f6ca6b22
3 changed files with 47 additions and 10 deletions
|
@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<UUID, Integer> playerMap = new HashMap<>();
|
||||
private final Map<UUID, Map<Class<? extends Token>, Integer>> tokenCreatedMap = new HashMap<>();
|
||||
private final Map<UUID, Map<SubType, Integer>> 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<? extends Token> tokenClazz = ((Token) game.getPermanent(event.getTargetId())).getClass();
|
||||
Map<Class<? extends Token>, Integer> playersTokens = tokenCreatedMap.getOrDefault(event.getPlayerId(), new HashMap<>());
|
||||
playersTokens.compute(tokenClazz, CardUtil::setOrIncrementValue);
|
||||
Permanent token = game.getPermanent(event.getTargetId());
|
||||
Map<SubType, Integer> 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<? extends Token> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue