Search in sources :

Example 1 with PlaySoundForOwnerEvent

use of org.terasology.audio.events.PlaySoundForOwnerEvent in project Terasology by MovingBlocks.

the class HealthAuthoritySystem method onDamaged.

@ReceiveEvent
public void onDamaged(OnDamagedEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
        // play the sound of damage hitting the character for everyone
        DamageSoundComponent damageSounds = event.getType().getComponent(DamageSoundComponent.class);
        if (damageSounds != null && !damageSounds.sounds.isEmpty()) {
            StaticSound sound = random.nextItem(damageSounds.sounds);
            if (sound != null) {
                entity.send(new PlaySoundEvent(sound, 1f));
            }
        }
        // play the sound of a client's character being damaged to the client
        if (!characterSounds.damageSounds.isEmpty()) {
            StaticSound sound = random.nextItem(characterSounds.damageSounds);
            if (sound != null) {
                entity.send(new PlaySoundForOwnerEvent(sound, characterSounds.damageVolume));
            }
        }
        characterSounds.lastSoundTime = time.getGameTimeInMs();
        entity.saveComponent(characterSounds);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) PlaySoundForOwnerEvent(org.terasology.audio.events.PlaySoundForOwnerEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 2 with PlaySoundForOwnerEvent

use of org.terasology.audio.events.PlaySoundForOwnerEvent in project Terasology by MovingBlocks.

the class CharacterInventorySystem method onGiveItemToEntity.

@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void onGiveItemToEntity(GiveItemEvent event, EntityRef entity) {
    if (event.getTargetEntity().hasComponent(InventoryComponent.class)) {
        if (inventoryManager.giveItem(event.getTargetEntity(), entity, entity)) {
            event.getTargetEntity().send(new PlaySoundForOwnerEvent(Assets.getSound("engine:Loot").get(), 1.0f));
            event.setHandled(true);
        }
    }
}
Also used : PlaySoundForOwnerEvent(org.terasology.audio.events.PlaySoundForOwnerEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)2 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)2 StaticSound (org.terasology.audio.StaticSound)1 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)1