mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Correct handling protection abilities for dealing damage. All tests passed.
This commit is contained in:
parent
17c88290af
commit
365bd2a50e
2 changed files with 41 additions and 2 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -617,7 +617,7 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> 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<T extends PermanentImpl<T>> 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<T extends PermanentImpl<T>> 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
|
||||
|
|
Loading…
Reference in a new issue