Search in sources :

Example 1 with PlayerDeathEvent

use of org.terasology.engine.logic.characters.events.PlayerDeathEvent 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);
}
Also used : DeathEvent(org.terasology.engine.logic.characters.events.DeathEvent) PlayerDeathEvent(org.terasology.engine.logic.characters.events.PlayerDeathEvent) PlayerDeathEvent(org.terasology.engine.logic.characters.events.PlayerDeathEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 DeathEvent (org.terasology.engine.logic.characters.events.DeathEvent)1 PlayerDeathEvent (org.terasology.engine.logic.characters.events.PlayerDeathEvent)1