diff --git a/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntity.java b/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntity.java index ba7adfe37..139aaff2e 100644 --- a/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntity.java +++ b/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntity.java @@ -109,7 +109,7 @@ public void die() { } this.getHitPoints().modifyBaseValue(new AttributeModifier<>(Modification.SET, 0)); - this.fireDeathEvent(); + this.fireDeathEvent(null); } @Override @@ -190,21 +190,21 @@ public void hit(final int damage, final Ability ability) { } if (this.isDead()) { - this.fireDeathEvent(); + this.fireDeathEvent(event); } this.lastHit = Game.time().now(); } - protected void fireDeathEvent() { + protected void fireDeathEvent(EntityHitEvent entityHitEvent) { this.setCollision(false); for (final CombatEntityListener listener : this.listeners) { - listener.death(this); + listener.death(this, entityHitEvent); } for (final CombatEntityDeathListener listener : this.deathListeners) { - listener.death(this); + listener.death(this, entityHitEvent); } } diff --git a/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntityDeathListener.java b/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntityDeathListener.java index 4b3cafe8b..3e349315f 100644 --- a/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntityDeathListener.java +++ b/litiengine/src/main/java/de/gurkenlabs/litiengine/entities/CombatEntityDeathListener.java @@ -15,6 +15,8 @@ public interface CombatEntityDeathListener extends EventListener { * * @param entity * The combat entity that died. + * @param hitEvent + * The hit event that caused the death or null. */ - void death(ICombatEntity entity); + void death(ICombatEntity entity, EntityHitEvent hitEvent); } diff --git a/litiengine/src/test/java/de/gurkenlabs/litiengine/entities/CombatEntityTests.java b/litiengine/src/test/java/de/gurkenlabs/litiengine/entities/CombatEntityTests.java index 62f02eb00..df0318b01 100644 --- a/litiengine/src/test/java/de/gurkenlabs/litiengine/entities/CombatEntityTests.java +++ b/litiengine/src/test/java/de/gurkenlabs/litiengine/entities/CombatEntityTests.java @@ -200,7 +200,7 @@ void testHitGetsKilledWithThisHit() { combatEntitySpy.hit(hitPoints, ability); // assert - verify(entityListener, times(2)).death(combatEntitySpy); + assertTrue(combatEntitySpy.isDead()); } @Test