Skip to content

Commit

Permalink
Provide the hit event with the death event when available.
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Oct 5, 2024
1 parent 950d93b commit bfc0d9b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void die() {
}

this.getHitPoints().modifyBaseValue(new AttributeModifier<>(Modification.SET, 0));
this.fireDeathEvent();
this.fireDeathEvent(null);
}

@Override
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void testHitGetsKilledWithThisHit() {
combatEntitySpy.hit(hitPoints, ability);

// assert
verify(entityListener, times(2)).death(combatEntitySpy);
assertTrue(combatEntitySpy.isDead());
}

@Test
Expand Down

0 comments on commit bfc0d9b

Please sign in to comment.