* Breath of Fury - Fixed that the enchnatment was no longer properly moved (fixes #3722).

This commit is contained in:
LevelX2 2017-07-24 00:41:03 +02:00
parent fbd90bb3e0
commit acf28d8aff
7 changed files with 129 additions and 42 deletions

View file

@ -120,6 +120,7 @@ class BoundEffect extends OneShotEffect {
Permanent toSacrifice = game.getPermanent(target.getFirstTarget()); Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
if (toSacrifice != null) { if (toSacrifice != null) {
toSacrifice.sacrifice(source.getSourceId(), game); toSacrifice.sacrifice(source.getSourceId(), game);
game.applyEffects();
int colors = toSacrifice.getColor(game).getColorCount(); int colors = toSacrifice.getColor(game).getColorCount();
if (colors > 0) { if (colors > 0) {
TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(0, colors, TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(0, colors,

View file

@ -52,12 +52,14 @@ import mage.players.Player;
import mage.target.Target; import mage.target.Target;
import mage.target.TargetPermanent; import mage.target.TargetPermanent;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
/** /**
* @author duncant * @author duncant
*/ */
public class BreathOfFury extends CardImpl { public class BreathOfFury extends CardImpl {
public BreathOfFury(UUID ownerId, CardSetInfo setInfo) { public BreathOfFury(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{2}{R}{R}"); super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{R}{R}");
this.subtype.add("Aura"); this.subtype.add("Aura");
// Enchant creature you control // Enchant creature you control
@ -103,11 +105,11 @@ class BreathOfFuryAbility extends TriggeredAbilityImpl {
@Override @Override
public boolean checkTrigger(GameEvent event, Game game) { public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event; DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Permanent enchantment = game.getPermanent(getSourceId()); Permanent enchantment = game.getPermanent(getSourceId());
if (damageEvent.isCombatDamage() && if (damageEvent.isCombatDamage()
enchantment != null && && enchantment != null
enchantment.getAttachedTo().equals(event.getSourceId())) { && enchantment.getAttachedTo().equals(event.getSourceId())) {
Permanent creature = game.getPermanent(enchantment.getAttachedTo()); Permanent creature = game.getPermanent(enchantment.getAttachedTo());
if (creature != null) { if (creature != null) {
for (Effect effect : getEffects()) { for (Effect effect : getEffects()) {
@ -129,7 +131,7 @@ class BreathOfFuryEffect extends OneShotEffect {
public BreathOfFuryEffect() { public BreathOfFuryEffect() {
super(Outcome.Benefit); super(Outcome.Benefit);
staticText = "sacrifice enchanted creature and attach {this} to a creature you control. If you do, untap all creatures you control and after this phase, there is an additional combat phase."; staticText = "sacrifice enchanted creature and attach {this} to a creature you control. If you do, untap all creatures you control and after this phase, there is an additional combat phase";
} }
public BreathOfFuryEffect(final BreathOfFuryEffect effect) { public BreathOfFuryEffect(final BreathOfFuryEffect effect) {
@ -142,7 +144,7 @@ class BreathOfFuryEffect extends OneShotEffect {
} }
@Override @Override
public boolean apply(Game game, Ability source){ public boolean apply(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId()); Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment == null) { if (enchantment == null) {
return false; return false;
@ -156,8 +158,8 @@ class BreathOfFuryEffect extends OneShotEffect {
// It's important to check that the creature was successfully sacrificed here. Effects that prevent sacrifice will also prevent Breath of Fury's effect from working. // It's important to check that the creature was successfully sacrificed here. Effects that prevent sacrifice will also prevent Breath of Fury's effect from working.
// Commanders going to the command zone and Rest in Peace style replacement effects don't make Permanent.sacrifice return false. // Commanders going to the command zone and Rest in Peace style replacement effects don't make Permanent.sacrifice return false.
if (enchantedCreature != null && controller != null if (enchantedCreature != null && controller != null
&& enchantedCreature.sacrifice(source.getSourceId(), game) && enchantedCreature.sacrifice(source.getSourceId(), game)
&& target.canChoose(source.getSourceId(), controller.getId(), game)) { && target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(outcome, target, source.getSourceId(), game); controller.choose(outcome, target, source.getSourceId(), game);
Permanent newCreature = game.getPermanent(target.getFirstTarget()); Permanent newCreature = game.getPermanent(target.getFirstTarget());
boolean success = false; boolean success = false;
@ -168,7 +170,7 @@ class BreathOfFuryEffect extends OneShotEffect {
success = true; success = true;
} else { } else {
if (oldCreature.removeAttachment(enchantment.getId(), game) if (oldCreature.removeAttachment(enchantment.getId(), game)
&& newCreature.addAttachment(enchantment.getId(), game)) { && newCreature.addAttachment(enchantment.getId(), game)) {
game.informPlayers(enchantment.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + newCreature.getLogName()); game.informPlayers(enchantment.getLogName() + " was unattached from " + oldCreature.getLogName() + " and attached to " + newCreature.getLogName());
success = true; success = true;
} }

View file

@ -0,0 +1,72 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package org.mage.test.cards.enchantments;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class BreathOfFuryTest extends CardTestPlayerBase {
@Test
public void testMoveEnchantment() {
// Enchant creature you control
// When enchanted creature deals combat damage to a player, sacrifice it and attach Breath of Fury to a creature you control.
// If you do, untap all creatures you control and after this phase, there is an additional combat phase.
addCard(Zone.HAND, playerA, "Breath of Fury", 1); // Enchantment - Aura {2}{R}{R}
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 4);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
addCard(Zone.BATTLEFIELD, playerA, "Pillarfield Ox");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Breath of Fury", "Silvercoat Lion");
attack(3, playerA, "Pillarfield Ox");
attack(3, playerA, "Silvercoat Lion");
addTarget(playerA, "Pillarfield Ox");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 16);
assertGraveyardCount(playerA, "Silvercoat Lion", 1);
assertTappedCount("Pillarfield Ox", false, 1);
assertPermanentCount(playerA, "Breath of Fury", 1);
}
}

View file

@ -10,6 +10,7 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
* @author BetaSteward * @author BetaSteward
*/ */
public class FuryOfTheHordeTest extends CardTestPlayerBase { public class FuryOfTheHordeTest extends CardTestPlayerBase {
/* /*
* Fury of the Horde * Fury of the Horde
* Sorcery, 5RR (7) * Sorcery, 5RR (7)
@ -18,8 +19,7 @@ public class FuryOfTheHordeTest extends CardTestPlayerBase {
* Untap all creatures that attacked this turn. After this main phase, there * Untap all creatures that attacked this turn. After this main phase, there
* is an additional combat phase followed by an additional main phase. * is an additional combat phase followed by an additional main phase.
* *
*/ */
// test that creatures attack twice // test that creatures attack twice
@Test @Test
public void testCreaturesAttackTwice() { public void testCreaturesAttackTwice() {
@ -31,6 +31,8 @@ public class FuryOfTheHordeTest extends CardTestPlayerBase {
attack(3, playerA, "Craw Wurm"); attack(3, playerA, "Craw Wurm");
attack(3, playerA, "Goblin Roughrider"); attack(3, playerA, "Goblin Roughrider");
castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Fury of the Horde"); castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Fury of the Horde");
attack(3, playerA, "Craw Wurm");
attack(3, playerA, "Goblin Roughrider");
setStopAt(3, PhaseStep.END_TURN); setStopAt(3, PhaseStep.END_TURN);
execute(); execute();
@ -67,6 +69,7 @@ public class FuryOfTheHordeTest extends CardTestPlayerBase {
attack(3, playerA, "Craw Wurm"); attack(3, playerA, "Craw Wurm");
castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Fury of the Horde"); castSpell(3, PhaseStep.POSTCOMBAT_MAIN, playerA, "Fury of the Horde");
attack(3, playerA, "Craw Wurm");
setStopAt(3, PhaseStep.END_TURN); setStopAt(3, PhaseStep.END_TURN);
execute(); execute();

View file

@ -27,6 +27,10 @@
*/ */
package org.mage.test.player; package org.mage.test.player;
import java.io.Serializable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.abilities.*; import mage.abilities.*;
@ -50,7 +54,6 @@ import mage.filter.FilterPermanent;
import mage.filter.common.*; import mage.filter.common.*;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate; import mage.filter.predicate.mageobject.NamePredicate;
import mage.filter.predicate.permanent.AttackingPredicate;
import mage.filter.predicate.permanent.SummoningSicknessPredicate; import mage.filter.predicate.permanent.SummoningSicknessPredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.Graveyard; import mage.game.Graveyard;
@ -71,11 +74,6 @@ import mage.target.*;
import mage.target.common.*; import mage.target.common.*;
import org.junit.Ignore; import org.junit.Ignore;
import java.io.Serializable;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @author Simown * @author Simown
@ -585,7 +583,9 @@ public class TestPlayer implements Player {
public void selectAttackers(Game game, UUID attackingPlayerId) { public void selectAttackers(Game game, UUID attackingPlayerId) {
// Loop through players and validate can attack/block this turn // Loop through players and validate can attack/block this turn
UUID defenderId = null; UUID defenderId = null;
for (PlayerAction action : actions) { //List<PlayerAction>
for (Iterator<org.mage.test.player.PlayerAction> it = actions.iterator(); it.hasNext();) {
PlayerAction action = it.next();
if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) { if (action.getTurnNum() == game.getTurnNum() && action.getAction().startsWith("attack:")) {
String command = action.getAction(); String command = action.getAction();
command = command.substring(command.indexOf("attack:") + 7); command = command.substring(command.indexOf("attack:") + 7);
@ -623,14 +623,16 @@ public class TestPlayer implements Player {
findPermanent(firstFilter, groups[0], computerPlayer.getId(), game); findPermanent(firstFilter, groups[0], computerPlayer.getId(), game);
// Second check to filter creature for combat - less strict to workaround issue in #3038 // Second check to filter creature for combat - less strict to workaround issue in #3038
FilterCreatureForCombat secondFilter = new FilterCreatureForCombat(); FilterCreatureForCombat secondFilter = new FilterCreatureForCombat();
secondFilter.add(Predicates.not(new AttackingPredicate())); // secondFilter.add(Predicates.not(new AttackingPredicate()));
secondFilter.add(Predicates.not(new SummoningSicknessPredicate())); secondFilter.add(Predicates.not(new SummoningSicknessPredicate()));
// TODO: Cannot enforce legal attackers multiple times per combat. See issue #3038 // TODO: Cannot enforce legal attackers multiple times per combat. See issue #3038
Permanent attacker = findPermanent(secondFilter, groups[0], computerPlayer.getId(), game, false); Permanent attacker = findPermanent(secondFilter, groups[0], computerPlayer.getId(), game, false);
if (attacker != null && attacker.canAttack(defenderId, game)) { if (attacker != null && attacker.canAttack(defenderId, game)) {
computerPlayer.declareAttacker(attacker.getId(), defenderId, game, false); computerPlayer.declareAttacker(attacker.getId(), defenderId, game, false);
it.remove();
} }
} }
} }
} }

View file

@ -57,12 +57,20 @@ public class DiesTriggeredAbility extends ZoneChangeTriggeredAbility {
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) { public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
// check it was previously on battlefield // check it was previously on battlefield
Permanent before = ((ZoneChangeEvent) event).getTarget(); Permanent before = ((ZoneChangeEvent) event).getTarget();
if (before == null) {
return false;
}
if (!(before instanceof PermanentToken) && !this.hasSourceObjectAbility(game, before, event)) { if (!(before instanceof PermanentToken) && !this.hasSourceObjectAbility(game, before, event)) {
return false; return false;
} }
// check now it is in graveyard // check now it is in graveyard
Zone after = game.getState().getZone(sourceId); if (before.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(source.getId())) {
return before != null && after != null && Zone.GRAVEYARD.match(after); Zone after = game.getState().getZone(sourceId);
return after != null && Zone.GRAVEYARD.match(after);
} else {
// Already moved to another zone, so guess it's ok
return true;
}
} }
@Override @Override

View file

@ -27,6 +27,7 @@
*/ */
package mage.game.permanent; package mage.game.permanent;
import java.util.*;
import mage.MageObject; import mage.MageObject;
import mage.MageObjectReference; import mage.MageObjectReference;
import mage.ObjectColor; import mage.ObjectColor;
@ -55,8 +56,6 @@ import mage.players.Player;
import mage.util.GameLog; import mage.util.GameLog;
import mage.util.ThreadLocalStringBuilder; import mage.util.ThreadLocalStringBuilder;
import java.util.*;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
@ -990,8 +989,8 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName()); game.informPlayers(player.getLogName() + " sacrificed " + this.getLogName());
} }
game.fireEvent(GameEvent.getEvent(EventType.SACRIFICED_PERMANENT, objectId, sourceId, controllerId)); game.fireEvent(GameEvent.getEvent(EventType.SACRIFICED_PERMANENT, objectId, sourceId, controllerId));
game.checkStateAndTriggered(); // game.checkStateAndTriggered();
game.applyEffects(); // game.applyEffects();
return true; return true;
} }
return false; return false;