diff --git a/Mage.Sets/src/mage/cards/a/AcademyManufactor.java b/Mage.Sets/src/mage/cards/a/AcademyManufactor.java index e5ccd23d64..94d885eb6f 100644 --- a/Mage.Sets/src/mage/cards/a/AcademyManufactor.java +++ b/Mage.Sets/src/mage/cards/a/AcademyManufactor.java @@ -1,17 +1,15 @@ package mage.cards.a; -import java.util.Map; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.ReplacementEffectImpl; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.SubType; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.SubType; import mage.game.Game; import mage.game.events.CreateTokenEvent; import mage.game.events.GameEvent; @@ -20,8 +18,11 @@ import mage.game.permanent.token.FoodToken; import mage.game.permanent.token.Token; import mage.game.permanent.token.TreasureToken; +import java.util.Iterator; +import java.util.Map; +import java.util.UUID; + /** - * * @author weirddan455 */ public final class AcademyManufactor extends CardImpl { @@ -70,12 +71,14 @@ class AcademyManufactorEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (event instanceof CreateTokenEvent && event.getPlayerId().equals(source.getControllerId())) { - CreateTokenEvent tokenEvent = (CreateTokenEvent) event; - for (Token token : tokenEvent.getTokens().keySet()) { - if (token instanceof ClueArtifactToken || token instanceof FoodToken || token instanceof TreasureToken) { - return true; - } + if (!(event instanceof CreateTokenEvent) || !event.getPlayerId().equals(source.getControllerId())) { + return false; + } + for (Token token : ((CreateTokenEvent) event).getTokens().keySet()) { + if (token.hasSubtype(SubType.CLUE, game) + || token.hasSubtype(SubType.FOOD, game) + || token.hasSubtype(SubType.TREASURE, game)) { + return true; } } return false; @@ -83,51 +86,22 @@ class AcademyManufactorEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (event instanceof CreateTokenEvent) { - CreateTokenEvent tokenEvent = (CreateTokenEvent) event; - int clues = 0; - int food = 0; - int treasures = 0; - ClueArtifactToken clueToken = null; - FoodToken foodToken = null; - TreasureToken treasureToken = null; - Map tokens = tokenEvent.getTokens(); - - for (Map.Entry entry : tokens.entrySet()) { - Token token = entry.getKey(); - int amount = entry.getValue(); - if (token instanceof ClueArtifactToken) { - clueToken = (ClueArtifactToken) token; - clues += amount; - } - else if (token instanceof FoodToken) { - foodToken = (FoodToken) token; - food += amount; - } - else if (token instanceof TreasureToken) { - treasureToken = (TreasureToken) token; - treasures += amount; - } + int amount = 0; + Map tokens = ((CreateTokenEvent) event).getTokens(); + for (Iterator> iter = tokens.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry entry = iter.next(); + Token token = entry.getKey(); + if (token.hasSubtype(SubType.CLUE, game) + || token.hasSubtype(SubType.FOOD, game) + || token.hasSubtype(SubType.TREASURE, game)) { + amount += entry.getValue(); + iter.remove(); } - - if (clueToken == null) { - clueToken = new ClueArtifactToken(); - } - if (foodToken == null) { - foodToken = new FoodToken(); - } - if (treasureToken == null) { - treasureToken = new TreasureToken(); - } - - int cluesToAdd = food + treasures; - int foodToAdd = clues + treasures; - int treasuresToAdd = clues + food; - - tokens.put(clueToken, tokens.getOrDefault(clueToken, 0) + cluesToAdd); - tokens.put(foodToken, tokens.getOrDefault(foodToken, 0) + foodToAdd); - tokens.put(treasureToken, tokens.getOrDefault(treasureToken, 0) + treasuresToAdd); } + + tokens.put(new ClueArtifactToken(), amount); + tokens.put(new FoodToken(), amount); + tokens.put(new TreasureToken(), amount); return false; } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/AcademyManufactorTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/AcademyManufactorTest.java index 068f70edab..25af4cffba 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/AcademyManufactorTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/AcademyManufactorTest.java @@ -68,4 +68,28 @@ public class AcademyManufactorTest extends CardTestPlayerBase { // 8 permanents above + 500 token limit assertPermanentCount(playerA, 508); } + + @Test + public void testGingerbruteToken() { + addCard(Zone.BATTLEFIELD, playerA, "Academy Manufactor", 2); + addCard(Zone.BATTLEFIELD, playerA, "Tundra", 5); + addCard(Zone.HAND, playerA, "Fractured Identity"); + + addCard(Zone.BATTLEFIELD, playerB, "Gingerbrute"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Fractured Identity", "Gingerbrute"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertAllCommandsUsed(); + assertPermanentCount(playerA, "Tundra", 5); + assertPermanentCount(playerA, "Academy Manufactor", 2); + // Gingerbrute token copy becomes a regular Food + assertPermanentCount(playerA, "Gingerbrute", 0); + assertPermanentCount(playerB, "Gingerbrute", 0); + assertPermanentCount(playerA, "Clue", 3); + assertPermanentCount(playerA, "Food", 3); + assertPermanentCount(playerA, "Treasure", 3); + } }