* Fixed a bug that put back auras always under owners control instead of abilities controller (e.g. triggered ability of It That Betrays).

This commit is contained in:
LevelX2 2016-01-27 00:23:28 +01:00
parent b4e7403d82
commit c4868cfa99
6 changed files with 80 additions and 42 deletions

View file

@ -28,7 +28,6 @@
package mage.sets.riseoftheeldrazi; package mage.sets.riseoftheeldrazi;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.common.OpponentSacrificesNonTokenPermanentTriggeredAbility; import mage.abilities.common.OpponentSacrificesNonTokenPermanentTriggeredAbility;
import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect; import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect;
@ -40,17 +39,16 @@ import mage.filter.FilterPermanent;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.TokenPredicate; import mage.filter.predicate.permanent.TokenPredicate;
/** /**
* *
* @author jeffwadsworth * @author jeffwadsworth
*/ */
public class ItThatBetrays extends CardImpl { public class ItThatBetrays extends CardImpl {
private static final FilterPermanent filter = new FilterPermanent("nontoken permanent"); private static final FilterPermanent FILTER = new FilterPermanent("nontoken permanent");
static { static {
filter.add(Predicates.not(new TokenPredicate())); FILTER.add(Predicates.not(new TokenPredicate()));
} }
public ItThatBetrays(UUID ownerId) { public ItThatBetrays(UUID ownerId) {
@ -61,6 +59,7 @@ public class ItThatBetrays extends CardImpl {
this.power = new MageInt(11); this.power = new MageInt(11);
this.toughness = new MageInt(11); this.toughness = new MageInt(11);
// Annihilator 2 (Whenever this creature attacks, defending player sacrifices two permanents.)
this.addAbility(new AnnihilatorAbility(2)); this.addAbility(new AnnihilatorAbility(2));
// Whenever an opponent sacrifices a nontoken permanent, put that card onto the battlefield under your control. // Whenever an opponent sacrifices a nontoken permanent, put that card onto the battlefield under your control.

View file

@ -87,4 +87,44 @@ public class ItThatBetraysTest extends CardTestPlayerBase {
assertPermanentCount(playerB, "Flooded Strand", 1); assertPermanentCount(playerB, "Flooded Strand", 1);
} }
/**
* I just sacrificed a Spreading Seas to an attacking It That Betrays, and
* it returned the Spreading Seas under my control. It made me choose a land
* to enchant, and I drew a card.
*/
@Test
public void testExileItThatBetraysEffectEnchantment() {
addCard(Zone.BATTLEFIELD, playerA, "Island", 2);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
addCard(Zone.HAND, playerA, "Spreading Seas", 1); // {1}{U}
// Annihilator 2 (Whenever this creature attacks, defending player sacrifices two permanents.)
// Whenever an opponent sacrifices a nontoken permanent, put that card onto the battlefield under your control.
addCard(Zone.BATTLEFIELD, playerB, "It That Betrays"); // 11/11
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);
// Enchant land
// When Spreading Seas enters the battlefield, draw a card.
// Enchanted land is an Island.
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Spreading Seas", "Mountain");
attack(2, playerB, "It That Betrays");
setChoice(playerA, "Spreading Seas");
setChoice(playerA, "Silvercoat Lion");
setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertLife(playerA, 9);
assertLife(playerB, 20);
assertHandCount(playerA, "Spreading Seas", 0);
// Player B now controls a Silvercoat Lion and Spreading Seas
assertPermanentCount(playerB, "Silvercoat Lion", 1);
assertPermanentCount(playerA, "Spreading Seas", 0);
assertGraveyardCount(playerA, "Spreading Seas", 0);
assertPermanentCount(playerB, "Spreading Seas", 1);
}
} }

View file

@ -601,7 +601,7 @@ public class TestPlayer implements Player {
targetName = targetName.substring(0, targetName.length() - 11); targetName = targetName.substring(0, targetName.length() - 11);
} }
} }
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filterPermanent, game)) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filterPermanent, getId(), sourceId, game)) {
if (target.getTargets().contains(permanent.getId())) { if (target.getTargets().contains(permanent.getId())) {
continue; continue;
} }

View file

@ -117,6 +117,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
} }
game.applyEffects(); // So continuousEffects are removed if previous effect of the same ability did move objects that cuase continuous effects game.applyEffects(); // So continuousEffects are removed if previous effect of the same ability did move objects that cuase continuous effects
Player controllingPlayer = null;
if (targetId == null) { if (targetId == null) {
SpellAbility spellAbility = card.getSpellAbility(); SpellAbility spellAbility = card.getSpellAbility();
if (spellAbility.getTargets().isEmpty()) { if (spellAbility.getTargets().isEmpty()) {
@ -145,8 +146,14 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
target.setNotTarget(true); // always not target because this way it's not handled targeted target.setNotTarget(true); // always not target because this way it's not handled targeted
target.clearChosen(); // neccessary if e.g. aura is blinked multiple times target.clearChosen(); // neccessary if e.g. aura is blinked multiple times
} }
Player player = game.getPlayer(card.getOwnerId());
if (target != null && player != null && player.choose(auraOutcome, target, card.getId(), game)) { if (event.getPlayerId() != null) {
controllingPlayer = game.getPlayer(event.getPlayerId());
} else {
controllingPlayer = game.getPlayer(card.getOwnerId());
}
if (target != null && controllingPlayer != null && controllingPlayer.choose(auraOutcome, target, card.getId(), game)) {
targetId = target.getFirstTarget(); targetId = target.getFirstTarget();
} }
} }
@ -162,7 +169,7 @@ public class AuraReplacementEffect extends ReplacementEffectImpl {
if (targetCard != null || targetPermanent != null || targetPlayer != null) { if (targetCard != null || targetPermanent != null || targetPlayer != null) {
card.removeFromZone(game, fromZone, sourceId); card.removeFromZone(game, fromZone, sourceId);
card.updateZoneChangeCounter(game); card.updateZoneChangeCounter(game);
PermanentCard permanent = new PermanentCard(card, card.getOwnerId(), game); PermanentCard permanent = new PermanentCard(card, (controllingPlayer == null ? card.getOwnerId() : controllingPlayer.getId()), game);
game.getBattlefield().addPermanent(permanent); game.getBattlefield().addPermanent(permanent);
card.setZone(Zone.BATTLEFIELD, game); card.setZone(Zone.BATTLEFIELD, game);
if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) { if (permanent.entersBattlefield(event.getSourceId(), game, fromZone, true)) {

View file

@ -82,7 +82,7 @@ import org.apache.log4j.Logger;
*/ */
public class ContinuousEffects implements Serializable { public class ContinuousEffects implements Serializable {
private static final Logger logger = Logger.getLogger(ContinuousEffects.class); private static final Logger LOGGER = Logger.getLogger(ContinuousEffects.class);
private long order = 0; private long order = 0;
@ -226,7 +226,7 @@ public class ContinuousEffects implements Serializable {
} }
} }
} else { } else {
logger.error("No abilities for continuous effect: " + effect.toString()); LOGGER.error("No abilities for continuous effect: " + effect.toString());
} }
break; break;
default: default:
@ -462,17 +462,15 @@ public class ContinuousEffects implements Serializable {
exists = permanent.getCard().getAbilities().contains(ability); exists = permanent.getCard().getAbilities().contains(ability);
} }
} }
} else { } else if (object instanceof PermanentCard) {
if (object instanceof PermanentCard) { PermanentCard permanent = (PermanentCard) object;
PermanentCard permanent = (PermanentCard) object; if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) {
if (permanent.isFaceDown(game) && !ability.getWorksFaceDown()) { return false;
return false; }
} } else if (object instanceof Spell) {
} else if (object instanceof Spell) { Spell spell = (Spell) object;
Spell spell = (Spell) object; if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) {
if (spell.isFaceDown(game) && !ability.getWorksFaceDown()) { return false;
return false;
}
} }
} }
return exists; return exists;
@ -539,10 +537,8 @@ public class ContinuousEffects implements Serializable {
if (effect.applies(objectId, ability, controllerId, game)) { if (effect.applies(objectId, ability, controllerId, game)) {
return true; return true;
} }
} else { } else if (effect.applies(objectId, affectedAbility, ability, game)) {
if (effect.applies(objectId, affectedAbility, ability, game)) { return true;
return true;
}
} }
} }
} }
@ -1082,11 +1078,9 @@ public class ContinuousEffects implements Serializable {
if (abilities == null) { if (abilities == null) {
abilities = new HashSet<>(); abilities = new HashSet<>();
temporaryEffects.put(effect, abilities); temporaryEffects.put(effect, abilities);
} else { } else if (abilities.contains(source)) {
if (abilities.contains(source)) { // this ability (for the continuous effect) is already added
// this ability (for the continuous effect) is already added return;
return;
}
} }
abilities.add(source); abilities.add(source);
@ -1097,10 +1091,10 @@ public class ContinuousEffects implements Serializable {
public void addEffect(ContinuousEffect effect, Ability source) { public void addEffect(ContinuousEffect effect, Ability source) {
if (effect == null) { if (effect == null) {
logger.error("Effect is null: " + source.toString()); LOGGER.error("Effect is null: " + source.toString());
return; return;
} else if (source == null) { } else if (source == null) {
logger.warn("Adding effect without ability : " + effect.toString()); LOGGER.warn("Adding effect without ability : " + effect.toString());
} }
switch (effect.getEffectType()) { switch (effect.getEffectType()) {
case REPLACEMENT: case REPLACEMENT:
@ -1166,10 +1160,8 @@ public class ContinuousEffects implements Serializable {
if (ability.getSourceId().equals(sourceId)) { if (ability.getSourceId().equals(sourceId)) {
ability.setControllerId(controllerId); ability.setControllerId(controllerId);
} }
} else { } else if (!ability.getZone().equals(Zone.COMMAND)) {
if (!ability.getZone().equals(Zone.COMMAND)) { LOGGER.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
logger.fatal("Continuous effect for ability with no sourceId Ability: " + ability);
}
} }
} }
} }
@ -1240,7 +1232,7 @@ public class ContinuousEffects implements Serializable {
} }
} }
} else { } else {
logger.error("Replacement effect without ability: " + entry.getKey().toString()); LOGGER.error("Replacement effect without ability: " + entry.getKey().toString());
} }
} }
return texts; return texts;
@ -1278,7 +1270,7 @@ public class ContinuousEffects implements Serializable {
} }
} }
} else { } else {
logger.warn("Ability without sourceId:" + ability.getRule()); LOGGER.warn("Ability without sourceId:" + ability.getRule());
} }
} }
} }

View file

@ -104,7 +104,7 @@ public class AnnihilatorAbility extends TriggeredAbilityImpl {
class AnnihilatorEffect extends OneShotEffect { class AnnihilatorEffect extends OneShotEffect {
private final int count; private final int count;
private static final FilterControlledPermanent filter = new FilterControlledPermanent(); private static final FilterControlledPermanent FILTER = new FilterControlledPermanent();
AnnihilatorEffect(int count) { AnnihilatorEffect(int count) {
super(Outcome.Sacrifice); super(Outcome.Sacrifice);
@ -124,8 +124,8 @@ class AnnihilatorEffect extends OneShotEffect {
player = game.getPlayer(defendingPlayerId); player = game.getPlayer(defendingPlayerId);
} }
if (player != null) { if (player != null) {
int amount = Math.min(count, game.getBattlefield().countAll(filter, player.getId(), game)); int amount = Math.min(count, game.getBattlefield().countAll(FILTER, player.getId(), game));
Target target = new TargetControlledPermanent(amount, amount, filter, true); Target target = new TargetControlledPermanent(amount, amount, FILTER, true);
if (target.canChoose(player.getId(), game)) { if (target.canChoose(player.getId(), game)) {
while (!target.isChosen() && target.canChoose(player.getId(), game) && player.canRespond()) { while (!target.isChosen() && target.canChoose(player.getId(), game) && player.canRespond()) {
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);