* Fixed a bug that prevented most continuous effects from recognizing if a permanent made zone changes and so the permanent was considered as a valid target even if the permanent changed zones (e.g. was Cloudshifted).

This commit is contained in:
LevelX2 2014-04-05 02:51:11 +02:00
parent 042552aa1e
commit d031b93fd4
15 changed files with 39 additions and 41 deletions

View file

@ -137,8 +137,6 @@ class LilianaOfTheDarkRealmsEffect extends ContinuousEffectImpl<LilianaOfTheDark
if (player != null && player.chooseUse(Outcome.Neutral, message, game)) { if (player != null && player.chooseUse(Outcome.Neutral, message, game)) {
this.amount *= -1; this.amount *= -1;
} }
targetPointer.init(game, source);
} }
@Override @Override

View file

@ -113,7 +113,7 @@ class SharedAnimosityEffect extends ContinuousEffectImpl<SharedAnimosityEffect>
} }
} }
if(!isChangeling){ if(!isChangeling){
ArrayList<Predicate<MageObject>> predicateList = new ArrayList<Predicate<MageObject>>(); ArrayList<Predicate<MageObject>> predicateList = new ArrayList<>();
for(String subtype : permanent.getSubtype()){ for(String subtype : permanent.getSubtype()){
predicateList.add(new SubtypePredicate(subtype)); predicateList.add(new SubtypePredicate(subtype));
} }
@ -122,7 +122,6 @@ class SharedAnimosityEffect extends ContinuousEffectImpl<SharedAnimosityEffect>
power = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game).size(); power = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game).size();
} }
targetPointer.init(game, source);
} }
@Override @Override

View file

@ -154,7 +154,7 @@ class RescueFromTheUnderworldCreateDelayedTriggeredAbilityEffect extends OneShot
for(Effect effect : delayedAbility.getEffects()) { for(Effect effect : delayedAbility.getEffects()) {
effect.getTargetPointer().init(game, source); effect.getTargetPointer().init(game, source);
} }
// add the scraificed creature as target // add the sacrificed creature as target
for (Cost cost :source.getCosts()) { for (Cost cost :source.getCosts()) {
if (cost instanceof SacrificeTargetCost) { if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost; SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
@ -193,10 +193,7 @@ class RescueFromTheUnderworldDelayedTriggeredAbility extends DelayedTriggeredAbi
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE && event.getPlayerId().equals(this.controllerId)) { return event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE && event.getPlayerId().equals(this.controllerId);
return true;
}
return false;
} }
@Override @Override

View file

@ -41,6 +41,7 @@ import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @param <T>
*/ */
public interface ContinuousEffect<T extends ContinuousEffect<T>> extends Effect<T> { public interface ContinuousEffect<T extends ContinuousEffect<T>> extends Effect<T> {

View file

@ -144,6 +144,7 @@ public abstract class ContinuousEffectImpl<T extends ContinuousEffectImpl<T>> ex
@Override @Override
public void init(Ability source, Game game) { public void init(Ability source, Game game) {
targetPointer.init(game, source);
//20100716 - 611.2c //20100716 - 611.2c
if (source instanceof ActivatedAbility || source instanceof TriggeredAbility) { if (source instanceof ActivatedAbility || source instanceof TriggeredAbility) {
if (layer != null) { if (layer != null) {

View file

@ -42,6 +42,7 @@ import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @param <T>
*/ */
public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> { public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
@ -65,7 +66,7 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
this.staticText = effect.staticText; this.staticText = effect.staticText;
this.targetPointer = effect.targetPointer.copy(); this.targetPointer = effect.targetPointer.copy();
if (effect.values != null) { if (effect.values != null) {
values = new HashMap<String, Object>(); values = new HashMap<>();
Map<String, Object> map = effect.values; Map<String, Object> map = effect.values;
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
values.put(entry.getKey(), entry.getValue()); values.put(entry.getKey(), entry.getValue());
@ -120,7 +121,7 @@ public abstract class EffectImpl<T extends Effect<T>> implements Effect<T> {
public void setValue(String key, Object value) { public void setValue(String key, Object value) {
synchronized (this) { synchronized (this) {
if (values == null) { if (values == null) {
values = new HashMap<String, Object>(); values = new HashMap<>();
} }
} }
values.put(key, value); values.put(key, value);

View file

@ -71,7 +71,7 @@ public class DetainAllEffect extends OneShotEffect<DetainAllEffect> {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
List<FixedTarget> detainedObjects = new ArrayList<FixedTarget>(); List<FixedTarget> detainedObjects = new ArrayList<>();
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
game.informPlayers("Detained permanent: " + permanent.getName()); game.informPlayers("Detained permanent: " + permanent.getName());
FixedTarget fixedTarget = new FixedTarget(permanent.getId()); FixedTarget fixedTarget = new FixedTarget(permanent.getId());
@ -86,7 +86,7 @@ public class DetainAllEffect extends OneShotEffect<DetainAllEffect> {
class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionEffect> { class DetainAllRestrictionEffect extends RestrictionEffect<DetainAllRestrictionEffect> {
private List<FixedTarget> detainedObjects; private final List<FixedTarget> detainedObjects;
public DetainAllRestrictionEffect(List<FixedTarget> detainedObjects) { public DetainAllRestrictionEffect(List<FixedTarget> detainedObjects) {
super(Duration.Custom); super(Duration.Custom);

View file

@ -86,7 +86,6 @@ public class DetainTargetEffect extends OneShotEffect<DetainTargetEffect> {
} }
} }
DetainRestrictionEffect effect = new DetainRestrictionEffect(); DetainRestrictionEffect effect = new DetainRestrictionEffect();
effect.getTargetPointer().init(game, source); // needed to init zoneChangeCounter
game.addEffect(effect, source); game.addEffect(effect, source);
return true; return true;
} }

View file

@ -29,13 +29,15 @@
package mage.abilities.effects.common; package mage.abilities.effects.common;
import java.util.UUID; import java.util.UUID;
import mage.constants.Outcome;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.Mode; import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player;
/** /**
* *
@ -66,14 +68,17 @@ public class ExileTargetForSourceEffect extends OneShotEffect<ExileTargetForSour
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source)); Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
UUID exileId = source.getSourceId(); UUID exileId = source.getSourceId();
if (permanent != null) { if (permanent != null) {
return permanent.moveToExile(exileId, exileZone, source.getId(), game); return controller.moveCardToExileWithInfo(permanent, exileId, exileZone, source.getSourceId(), game, Zone.BATTLEFIELD);
} else { } else {
Card card = game.getCard(targetPointer.getFirst(game, source)); Card card = game.getCard(targetPointer.getFirst(game, source));
if (card != null) { if (card != null) {
return card.moveToExile(exileId, exileZone, source.getId(), game); return controller.moveCardToExileWithInfo(card, exileId, exileZone, source.getSourceId(), game, game.getState().getZone(card.getId()));
}
} }
} }
return false; return false;

View file

@ -34,6 +34,7 @@ import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.game.Game; import mage.game.Game;
import mage.players.Player;
/** /**
* *
@ -57,13 +58,17 @@ public class ReturnToBattlefieldUnderYourControlTargetEffect extends OneShotEffe
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card card = game.getCard(targetPointer.getFirst(game, source)); Card card = game.getCard(targetPointer.getFirst(game, source));
if (card != null) { if (card != null) {
Zone currentZone = game.getState().getZone(card.getId()); Zone currentZone = game.getState().getZone(card.getId());
if (card.putOntoBattlefield(game, currentZone, source.getId(), source.getControllerId())) { if (controller.putOntoBattlefieldWithInfo(card, game, currentZone, source.getSourceId())) {
return true; return true;
} }
} }
}
return false; return false;
} }

View file

@ -92,7 +92,6 @@ public class BoostTargetEffect extends ContinuousEffectImpl<BoostTargetEffect> {
power = new StaticValue(power.calculate(game, source)); power = new StaticValue(power.calculate(game, source));
toughness = new StaticValue(toughness.calculate(game, source)); toughness = new StaticValue(toughness.calculate(game, source));
} }
targetPointer.init(game, source);
} }
@Override @Override

View file

@ -79,12 +79,6 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl<GainAbilityTar
return new GainAbilityTargetEffect(this); return new GainAbilityTargetEffect(this);
} }
@Override
public void init(Ability source, Game game) {
super.init(source, game);
targetPointer.init(game, source);
}
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
int affectedTargets = 0; int affectedTargets = 0;

View file

@ -55,7 +55,7 @@ public enum CardRepository {
private static final String JDBC_URL = "jdbc:sqlite:db/cards.db"; private static final String JDBC_URL = "jdbc:sqlite:db/cards.db";
private static final String VERSION_ENTITY_NAME = "card"; private static final String VERSION_ENTITY_NAME = "card";
private static final long CARD_DB_VERSION = 21; private static final long CARD_DB_VERSION = 22;
private final Random random = new Random(); private final Random random = new Random();
private Dao<CardInfo, Object> cardDao; private Dao<CardInfo, Object> cardDao;

View file

@ -1227,8 +1227,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} }
} }
List<Permanent> planeswalkers = new ArrayList<Permanent>(); List<Permanent> planeswalkers = new ArrayList<>();
List<Permanent> legendary = new ArrayList<Permanent>(); List<Permanent> legendary = new ArrayList<>();
for (Permanent perm: getBattlefield().getAllActivePermanents()) { for (Permanent perm: getBattlefield().getAllActivePermanents()) {
if (perm.getCardType().contains(CardType.CREATURE)) { if (perm.getCardType().contains(CardType.CREATURE)) {
//20091005 - 704.5f //20091005 - 704.5f

View file

@ -1,11 +1,10 @@
package mage.target.targetpointer; package mage.target.targetpointer;
import mage.abilities.Ability;
import mage.game.Game;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability;
import mage.game.Game;
public interface TargetPointer extends Serializable { public interface TargetPointer extends Serializable {
void init(Game game, Ability source); void init(Game game, Ability source);