use of org.terasology.engine.logic.characters.events.DeathEvent in project Terasology by MovingBlocks.
the class CharacterSystem method beforeDestroy.
@ReceiveEvent
public void beforeDestroy(BeforeDestroyEvent event, EntityRef character, CharacterComponent characterComponent, AliveCharacterComponent aliveCharacterComponent) {
if (character.hasComponent(PlayerCharacterComponent.class)) {
// Consume the BeforeDestroyEvent so that the DoDestroy event is never sent for player entities
event.consume();
// PlayerDeathEvent only sent to the client for the player entity.
PlayerDeathEvent playerDeathEvent = new PlayerDeathEvent();
// Store the details of the death in the event for display on the death screen
playerDeathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
playerDeathEvent.instigatorName = getInstigatorName(event.getInstigator());
character.send(playerDeathEvent);
}
// DeathEvent sent to client for any character entity.
DeathEvent deathEvent = new DeathEvent();
deathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
deathEvent.instigatorName = getInstigatorName(event.getInstigator());
characterComponent.controller.send(deathEvent);
character.removeComponent(AliveCharacterComponent.class);
// TODO: Don't just destroy, ragdoll or create particle effect or something (possible allow another system to handle)
// entity.removeComponent(CharacterComponent.class);
// entity.removeComponent(CharacterMovementComponent.class);
}
Aggregations