Added zoneChangeCounter into LKI. Reimplemented Trostani. PersistTest and LastKnownInformationTest do work now.

This commit is contained in:
magenoxx 2014-08-18 19:45:37 +04:00
parent cae473b6ca
commit 43e82b7a1a
4 changed files with 44 additions and 8 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -129,6 +129,7 @@ public abstract class GameImpl implements Game, Serializable {
protected Map<UUID, Card> gameCards = new HashMap<>();
protected Map<Zone,HashMap<UUID, MageObject>> lki = new EnumMap<>(Zone.class);
protected Map<UUID, Map<Integer, MageObject>> lkiExtended = new HashMap<>();
protected Map<Zone,HashMap<UUID, MageObject>> 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<Integer, MageObject> 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<UUID, MageObject> 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<Integer, MageObject> 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