diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/prevent/MalignusNoPreventDamageTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/prevent/MalignusNoPreventDamageTest.java index bcf37a52d5..bec7fb6791 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/replacement/prevent/MalignusNoPreventDamageTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/replacement/prevent/MalignusNoPreventDamageTest.java @@ -41,4 +41,26 @@ public class MalignusNoPreventDamageTest extends CardTestPlayerBase { assertPermanentCount(playerA, "Vedalken Outlander", 0); } + /** + * Tests that blocking red creature by creature by pro red will prevent damage + */ + @Test + public void testBlockAnotherWithProRed() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Vedalken Outlander"); + + addCard(Constants.Zone.BATTLEFIELD, playerB, "Ogre Resister"); + + attack(2, playerB, "Ogre Resister"); + block(2, playerA, "Vedalken Outlander", "Ogre Resister"); + + setStopAt(2, Constants.PhaseStep.END_TURN); + execute(); + + assertLife(playerA, 20); + assertLife(playerB, 20); + + assertPermanentCount(playerB, "Ogre Resister", 1); + assertPermanentCount(playerA, "Vedalken Outlander", 1); + } + } diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index ffe39f7969..246f5c2b56 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -617,7 +617,7 @@ public abstract class PermanentImpl> extends CardImpl protected int damageCreature(int damage, UUID sourceId, Game game, boolean preventable, boolean combat, boolean markDamage) { GameEvent event = new DamageCreatureEvent(objectId, sourceId, controllerId, damage, preventable, combat); if (!game.replaceEvent(event)) { - int actualDamage = event.getAmount(); + int actualDamage = checkProtectionAbilities(event, sourceId, game); if (actualDamage > 0) { //Permanent source = game.getPermanent(sourceId); MageObject source = game.getObject(sourceId); @@ -639,6 +639,20 @@ public abstract class PermanentImpl> extends CardImpl } return 0; } + + private int checkProtectionAbilities(GameEvent event, UUID sourceId, Game game) { + MageObject source = game.getObject(sourceId); + if (source != null && hasProtectionFrom(source, game)) { + GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, this.objectId, sourceId, this.controllerId, event.getAmount(), false); + if (!game.replaceEvent(preventEvent)) { + int damage = event.getAmount(); + event.setAmount(0); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, this.objectId, sourceId, this.controllerId, damage)); + return 0; + } + } + return event.getAmount(); + } private void markDamage(Counter counter) { if (markedDamage == null) { @@ -678,7 +692,10 @@ public abstract class PermanentImpl> extends CardImpl } protected boolean canDamage(MageObject source, Game game) { - return (!hasProtectionFrom(source, game)); + //noxx: having protection doesn't prevents from dealing damage + // instead it adds damage prevention + //return (!hasProtectionFrom(source, game)); + return true; } @Override