From 43e82b7a1ac2cde78a97df854be4be1120aaca94 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 18 Aug 2014 19:45:37 +0400 Subject: [PATCH] Added zoneChangeCounter into LKI. Reimplemented Trostani. PersistTest and LastKnownInformationTest do work now. --- .../TrostaniSelesnyasVoice.java | 16 +++++----- .../cards/abilities/keywords/PersistTest.java | 5 +++- Mage/src/mage/game/Game.java | 1 + Mage/src/mage/game/GameImpl.java | 30 +++++++++++++++++++ 4 files changed, 44 insertions(+), 8 deletions(-) diff --git a/Mage.Sets/src/mage/sets/returntoravnica/TrostaniSelesnyasVoice.java b/Mage.Sets/src/mage/sets/returntoravnica/TrostaniSelesnyasVoice.java index 94d9ab47b4..5e63e627a0 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/TrostaniSelesnyasVoice.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/TrostaniSelesnyasVoice.java @@ -28,11 +28,6 @@ package mage.sets.returntoravnica; -import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; @@ -43,12 +38,17 @@ import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.PopulateEffect; import mage.cards.CardImpl; +import mage.constants.CardType; import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; +import java.util.UUID; + /** * * @author LevelX2 @@ -103,6 +103,7 @@ class TrostaniSelesnyasVoiceTriggeredAbility extends TriggeredAbilityImpl { && event.getTargetId() != this.getSourceId()) { Effect effect = this.getEffects().get(0); effect.setValue("lifeSource", event.getTargetId()); + effect.setValue("zoneChangeCounter", permanent.getZoneChangeCounter()); return true; } } @@ -139,9 +140,10 @@ class TrostaniSelesnyasVoiceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { UUID creatureId = (UUID) getValue("lifeSource"); + Integer zoneChangeCounter = (Integer) getValue("zoneChangeCounter"); Permanent creature = game.getPermanent(creatureId); - if (creature == null) { - creature = (Permanent) game.getLastKnownInformation(creatureId, Zone.BATTLEFIELD); + if (creature == null || creature.getZoneChangeCounter() != zoneChangeCounter) { + creature = (Permanent) game.getLastKnownInformation(creatureId, Zone.BATTLEFIELD, zoneChangeCounter); } if (creature != null) { int amount = creature.getToughness().getValue(); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java index 94a6b17730..731aadf685 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/PersistTest.java @@ -148,6 +148,9 @@ public class PersistTest extends CardTestPlayerBase { block(2, playerA, "Kitchen Finks", "Wurmcoil Engine"); block(2, playerA, "Kitchen Finks", "Wurmcoil Engine"); + setChoice(playerB, "Creatures entering the battlefield don't cause abilities to trigger"); + setChoice(playerB, "Creatures entering the battlefield don't cause abilities to trigger"); + setStopAt(2, PhaseStep.END_TURN); execute(); @@ -157,7 +160,7 @@ public class PersistTest extends CardTestPlayerBase { assertPermanentCount(playerB, "Wurmcoil Engine", 0); assertPermanentCount(playerB, "Wurm", 2); assertPermanentCount(playerA, "Kitchen Finks", 2); - assertPowerToughness(playerA, "Kitchen Finks", 2,1, Filter.ComparisonScope.All); + assertPowerToughness(playerA, "Kitchen Finks", 2, 1, Filter.ComparisonScope.All); } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index f1650bbf7c..1031f911fe 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -137,6 +137,7 @@ public interface Game extends MageItem, Serializable { boolean isSimulation(); void setSimulation(boolean simulation); MageObject getLastKnownInformation(UUID objectId, Zone zone); + MageObject getLastKnownInformation(UUID objectId, Zone zone, int zoneChangeCounter); MageObject getShortLivingLKI(UUID objectId, Zone zone); void rememberLKI(UUID objectId, Zone zone, MageObject object); void resetLKI(); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 3ad93f7b0e..e2b490be4b 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -129,6 +129,7 @@ public abstract class GameImpl implements Game, Serializable { protected Map gameCards = new HashMap<>(); protected Map> lki = new EnumMap<>(Zone.class); + protected Map> lkiExtended = new HashMap<>(); protected Map> shortLivingLKI = new EnumMap<>(Zone.class); protected GameState state; @@ -190,6 +191,7 @@ public abstract class GameImpl implements Game, Serializable { this.simulation = game.simulation; this.gameOptions = game.gameOptions; this.lki.putAll(game.lki); + this.lkiExtended.putAll(game.lkiExtended); this.shortLivingLKI.putAll(game.shortLivingLKI); if (logger.isDebugEnabled()) { copyCount++; @@ -2060,6 +2062,22 @@ public abstract class GameImpl implements Game, Serializable { return null; } + @Override + public MageObject getLastKnownInformation(UUID objectId, Zone zone, int zoneChangeCounter) { + if (zone.equals(Zone.BATTLEFIELD)) { + Map lkiMapExtended = lkiExtended.get(objectId); + + if (lkiMapExtended != null) { + MageObject object = lkiMapExtended.get(zoneChangeCounter); + if (object != null) { + return object.copy(); + } + } + } + + return getLastKnownInformation(objectId, zone); + } + @Override public MageObject getShortLivingLKI(UUID objectId, Zone zone) { Map shortLivingLkiMap = shortLivingLKI.get(zone); @@ -2101,6 +2119,17 @@ public abstract class GameImpl implements Game, Serializable { newMap.put(objectId, copy); shortLivingLKI.put(zone, newMap); } + + if (object instanceof Permanent) { + Map lkiExtendedMap = lkiExtended.get(objectId); + if (lkiExtendedMap != null) { + lkiExtendedMap.put(((Permanent) object).getZoneChangeCounter(), copy); + } else { + lkiExtendedMap = new HashMap<>(); + lkiExtendedMap.put(((Permanent) object).getZoneChangeCounter(), copy); + lkiExtended.put(objectId, lkiExtendedMap); + } + } } } @@ -2110,6 +2139,7 @@ public abstract class GameImpl implements Game, Serializable { @Override public void resetLKI() { lki.clear(); + lkiExtended.clear(); } @Override