1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-02 03:18:09 -09:00

* Fixed that permanents that became creatures are not removed from combat if the creature making effect is removed during combat (fixes 366).

This commit is contained in:
LevelX2 2015-07-08 23:40:15 +02:00
parent d847fb7109
commit 77b3706c9f
5 changed files with 32 additions and 9 deletions
Mage.Tests/src/test/java/org/mage/test/combat
Mage/src/mage/game

View file

@ -29,6 +29,8 @@ package org.mage.test.combat;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.game.permanent.Permanent;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
@ -60,7 +62,7 @@ public class RemoveFromCombatTest extends CardTestPlayerBase {
attack(2, playerB, "Stomping Ground");
activateAbility(2, PhaseStep.DECLARE_ATTACKERS, playerB, "{1}{G},Sacrifice an Elf: Target creature gets +3/+3", "Stomping Ground");
castSpell(2, PhaseStep.DECLARE_BLOCKERS, playerA, "Lightning Blast", "Ambush Commander");
setStopAt(2, PhaseStep.POSTCOMBAT_MAIN);
setStopAt(2, PhaseStep.COMBAT_DAMAGE);
execute();
assertGraveyardCount(playerB, "Elvish Mystic", 1);
@ -69,6 +71,9 @@ public class RemoveFromCombatTest extends CardTestPlayerBase {
assertPowerToughness(playerB, "Stomping Ground", 0, 0);
Permanent stompingGround = getPermanent("Stomping Ground", playerB);
Assert.assertEquals("Stomping Ground has to be removed from combat", false, stompingGround.isAttacking());
assertLife(playerA, 20);
assertLife(playerB, 20);

View file

@ -2124,7 +2124,7 @@ public abstract class GameImpl implements Game, Serializable {
}
// check if it's a creature and must be removed from combat
if (perm.getCardType().contains(CardType.CREATURE) && this.getCombat() != null) {
this.getCombat().removeFromCombat(perm.getId(), this);
perm.removeFromCombat(this, true);
}
it.remove();
}

View file

@ -534,9 +534,10 @@ public class GameState implements Serializable, Copyable<GameState> {
player.reset();
}
battlefield.reset(game);
combat.reset();
combat.reset(game);
this.reset();
effects.apply(game);
combat.checkForRemoveFromCombat(game);
}
// Remove End of Combat effects

View file

@ -42,6 +42,7 @@ import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.CanAttackOnlyAloneAbility;
import mage.abilities.keyword.CantAttackAloneAbility;
import mage.abilities.keyword.VigilanceAbility;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterControlledCreaturePermanent;
@ -157,11 +158,26 @@ public class Combat implements Serializable, Copyable<Combat> {
this.useToughnessForDamageFilters.add(filter);
}
public void reset() {
public void reset(Game game) {
this.useToughnessForDamage = false;
this.useToughnessForDamageFilters.clear();
}
public void checkForRemoveFromCombat(Game game) {
for (UUID creatureId : getAttackers()) {
Permanent creature = game.getPermanent(creatureId);
if (!creature.getCardType().contains(CardType.CREATURE)) {
removeFromCombat(creatureId, game, true);
}
}
for (UUID creatureId : getBlockers()) {
Permanent creature = game.getPermanent(creatureId);
if (!creature.getCardType().contains(CardType.CREATURE)) {
removeFromCombat(creatureId, game, true);
}
}
}
public void clear() {
groups.clear();
blockingGroups.clear();
@ -993,7 +1009,7 @@ public class Combat implements Serializable, Copyable<Combat> {
}
}
public boolean removeFromCombat(UUID creatureId, Game game) {
public boolean removeFromCombat(UUID creatureId, Game game, boolean withInfo) {
boolean result = false;
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
@ -1003,6 +1019,9 @@ public class Combat implements Serializable, Copyable<Combat> {
for (CombatGroup group : groups) {
result |= group.remove(creatureId);
}
if (result && withInfo) {
game.informPlayers(creature.getLogName() + " removed from combat");
}
}
return result;
}

View file

@ -1200,11 +1200,9 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
@Override
public boolean removeFromCombat(Game game, boolean withInfo) {
if (this.isAttacking() || this.blocking > 0) {
if (game.getCombat().removeFromCombat(objectId, game) && withInfo && !game.isSimulation()) {
game.informPlayers(new StringBuilder(this.getLogName()).append(" removed from combat").toString());
}
return game.getCombat().removeFromCombat(objectId, game, withInfo);
}
return true;
return false;
}
@Override