Search in sources :

Example 6 with StaticSound

use of org.terasology.audio.StaticSound 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 7 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class BlockEntitySystem method commonDestroyed.

private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
    entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
    BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
    // TODO: Configurable via block definition
    if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
        // dust particle effect
        if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
            EntityBuilder dustBuilder = entityManager.newBuilder("core:dustEffect");
            // TODO: particle system stuff should be split out better - this is effectively a stealth dependency on Core from the engine
            if (dustBuilder.hasComponent(LocationComponent.class)) {
                dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition());
                dustBuilder.build();
            }
        }
        // sound to play for destroyed block
        BlockSounds sounds = block.getSounds();
        if (!sounds.getDestroySounds().isEmpty()) {
            StaticSound sound = random.nextItem(sounds.getDestroySounds());
            entity.send(new PlaySoundEvent(sound, 0.6f));
        }
    }
}
Also used : BlockSounds(org.terasology.world.block.sounds.BlockSounds) StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) BlockDamageModifierComponent(org.terasology.world.block.entity.damage.BlockDamageModifierComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) LocationComponent(org.terasology.logic.location.LocationComponent)

Example 8 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class PlaySoundAction method onActivate.

/**
 * This method plays sound if it wasn't played by prediction system
 * @param event contains the details for the active event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = { PlaySoundActionComponent.class })
public void onActivate(ActivateEvent event, EntityRef entity) {
    if (event.getInstigator().equals(localPlayer.getCharacterEntity())) {
        // owner has heard sound from prediction
        return;
    }
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos = null;
        switch(playSound.relativeTo) {
            case Target:
                pos = event.getTargetLocation();
                break;
            default:
                pos = event.getInstigatorLocation();
                break;
        }
        if (pos == null) {
            pos = event.getOrigin();
        }
        audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 9 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class PlaySoundAction method onActivationPredicted.

/**
 * This method plays sound in prediction for preventing not playing song because of server lags
 * @param event contains the details for the predicted event, used here for location purposes
 * @param entity is source of the playsound
 */
@ReceiveEvent(components = { PlaySoundActionComponent.class })
public void onActivationPredicted(ActivationPredicted event, EntityRef entity) {
    PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
    StaticSound sound = random.nextItem(playSound.sounds);
    if (sound != null) {
        Vector3f pos = null;
        switch(playSound.relativeTo) {
            case Target:
                pos = event.getTargetLocation();
                break;
            default:
                pos = event.getInstigatorLocation();
                break;
        }
        if (pos == null) {
            pos = event.getOrigin();
        }
        audioManager.playSound(sound, pos, playSound.volume, AudioManager.PRIORITY_NORMAL);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 10 with StaticSound

use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onPlayerDeath.

@ReceiveEvent
public void onPlayerDeath(PlayerDeathEvent event, EntityRef character) {
    CharacterSoundComponent characterSounds = character.getComponent(CharacterSoundComponent.class);
    if (characterSounds.deathSounds.size() > 0) {
        StaticSound sound = random.nextItem(characterSounds.deathSounds);
        character.send(new PlaySoundEvent(character, sound, characterSounds.deathVolume));
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

StaticSound (org.terasology.audio.StaticSound)15 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)13 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)13 Vector3f (org.terasology.math.geom.Vector3f)4 BlockSounds (org.terasology.world.block.sounds.BlockSounds)2 PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)1 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Block (org.terasology.world.block.Block)1 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1