* Fix that commander replacement effects work again, some cleanup after the changes of continuous effects and triggered abilities.

This commit is contained in:
LevelX2 2014-12-25 03:08:31 +01:00
parent 071a611f91
commit eb0544957b
8 changed files with 6 additions and 19 deletions

View file

@ -54,7 +54,6 @@ import mage.game.permanent.Permanent;
import mage.game.permanent.token.EmptyToken;
import mage.util.CardUtil;
import mage.util.functions.ApplyToPermanent;
import org.apache.log4j.Logger;
/**
*

View file

@ -46,7 +46,6 @@ import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import org.apache.log4j.Logger;
/**
*

View file

@ -130,7 +130,6 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
* @param attachedTo - the object that gained the ability
*/
public void add(TriggeredAbility ability, UUID sourceId, MageObject attachedTo) {
Logger.getLogger(TriggeredAbilities.class).debug("TRIGGER ADDED - sourceId " + sourceId);
this.add(ability, attachedTo);
List<UUID> uuidList = new LinkedList<>();
uuidList.add(sourceId);
@ -140,7 +139,6 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
public void add(TriggeredAbility ability, MageObject attachedTo) {
Logger.getLogger(TriggeredAbilities.class).debug("TRIGGER ADDED - id: " + ability.getId() + " source: " +attachedTo.getId() + " - " + attachedTo.getLogName() + " - " + ability.getRule());
this.put(getKey(ability, attachedTo), ability);
}
@ -165,8 +163,6 @@ public class TriggeredAbilities extends ConcurrentHashMap<String, TriggeredAbili
}
public void removeAllGainedAbilities() {
Logger.getLogger(TriggeredAbilities.class).debug("REMOVE all gained Triggered Abilities");
for(String key: sources.keySet()) {
this.remove(key);
}

View file

@ -344,7 +344,7 @@ public class ContinuousEffects implements Serializable {
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
if (!game.getScopeRelevant() || effect.hasSelfScope() || !event.getTargetId().equals(ability.getSourceId())) {
if (checkAbilityStillExists(ability, effect, event, game)) {
if (effect.applies(event, ability, game)) {
if (effect.applies(event, ability, game)) {
applicableAbilities.add(ability);
}
}
@ -381,7 +381,7 @@ public class ContinuousEffects implements Serializable {
}
private boolean checkAbilityStillExists(Ability ability, ContinuousEffect effect, GameEvent event, Game game) {
if (effect.getDuration().equals(Duration.OneUse)) { // needed for some special replacment effects (e.g. Undying)
if (effect.getDuration().equals(Duration.OneUse) || ability.getSourceId() == null) { // needed for some special replacment effects (e.g. Undying) or commander replacement effect
return true;
}
MageObject object;
@ -762,7 +762,7 @@ public class ContinuousEffects implements Serializable {
consumed.put(rEffect.getId(), set);
}
}
// Must be called here so some
// Must be called here for some effects to be able to work correctly
game.applyEffects();
} while (true);
return caught;

View file

@ -117,21 +117,18 @@ public class ContinuousEffectsList<T extends ContinuousEffect> extends ArrayList
return false;
} else if (effect.isDiscarded()) {
it.remove();
} else if (game.getObject(ability.getSourceId()) == null) {
logger.debug("Ability without source object removed: " + ability.getSourceId() + " " + ability.getRule());
} else if (ability.getSourceId() != null && game.getObject(ability.getSourceId()) == null) { // Commander effects have no sourceId
it.remove(); // if the related source object does no longer exist the effect has to be removed
} else {
switch(effect.getDuration()) {
case OneUse:
if (effect.isUsed()) {
logger.debug("Ability one use removed: " + ability.getSourceId() + " " + ability.getRule());
it.remove();
}
break;
case Custom:
case UntilYourNextTurn:
if (effect.isInactive(ability , game)) {
logger.debug("Ability custom removed: " + ability.getSourceId() + " " + ability.getRule());
it.remove();
}
}

View file

@ -553,8 +553,6 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
}
updateZoneChangeCounter();
PermanentCard permanent = new PermanentCard(this, event.getPlayerId());
// reset is done to end continuous effects from previous instances of that permanent (e.g undying)
// game.resetForSourceId(permanent.getId());
// make sure the controller of all continuous effects of this card are switched to the current controller
game.getContinuousEffects().setController(objectId, event.getPlayerId());
game.addPermanent(permanent);

View file

@ -106,7 +106,7 @@ public abstract class GameCommanderImpl extends GameImpl {
}
}
this.getState().addAbility(ability, this.getId(), null);
this.getState().addAbility(ability, null);
if (startingPlayerSkipsDraw) {
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}

View file

@ -398,7 +398,6 @@ public class GameState implements Serializable, Copyable<GameState> {
}
public void applyEffects(Game game) {
Logger.getLogger(GameState.class).debug("Apply Effects turn: " + game.getTurnNum() + " - Step: " + (game.getStep() == null ? "null":game.getStep().getType().toString()));
for (Player player: players.values()) {
player.reset();
}
@ -510,7 +509,6 @@ public class GameState implements Serializable, Copyable<GameState> {
eventsToHandle.addAll(simultaneousEvents);
simultaneousEvents.clear();
for (GameEvent event:eventsToHandle) {
Logger.getLogger(GameState.class).debug("Handle Simultanous events - type: " + event.getType().toString() + " sourceId " + event.getSourceId() + " targetId " + event.getTargetId());
this.handleEvent(event, game);
}
}
@ -760,7 +758,7 @@ public class GameState implements Serializable, Copyable<GameState> {
}
/**
* Used for diagbostic purposes
* Onl used for diagnostic purposes of tests
* @return
*/
public TriggeredAbilities getTriggers() {