Search in sources :

Example 6 with PlaySoundEvent

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

the class DoorSystem method closeDoor.

@ReceiveEvent
public void closeDoor(CloseDoorEvent event, EntityRef player) {
    EntityRef entity = event.getDoorEntity();
    DoorComponent door = entity.getComponent(DoorComponent.class);
    Side newSide = door.closedSide;
    BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
    Block bottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.min(), newSide, Side.TOP);
    worldProvider.setBlock(regionComp.region.min(), bottomBlock);
    Block topBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.max(), newSide, Side.TOP);
    worldProvider.setBlock(regionComp.region.max(), topBlock);
    if (door.closeSound != null) {
        entity.send(new PlaySoundEvent(door.closeSound, 1f));
    }
    door.isOpen = false;
    entity.saveComponent(door);
}
Also used : Side(org.terasology.math.Side) BlockRegionComponent(org.terasology.world.block.regions.BlockRegionComponent) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Block(org.terasology.world.block.Block) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 7 with PlaySoundEvent

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

the class ExplosionAuthoritySystem method doExplosion.

void doExplosion(ExplosionActionComponent explosionComp, Vector3f origin, EntityRef instigatingBlockEntity) {
    EntityBuilder builder = entityManager.newBuilder("core:smokeExplosion");
    builder.getComponent(LocationComponent.class).setWorldPosition(origin);
    EntityRef smokeEntity = builder.build();
    smokeEntity.send(new PlaySoundEvent(getRandomExplosionSound(), 1f));
    Vector3i blockPos = new Vector3i();
    for (int i = 0; i < explosionComp.maxRange; i++) {
        Vector3f direction = random.nextVector3f(1.0f);
        for (int j = 0; j < 4; j++) {
            Vector3f target = new Vector3f(origin);
            target.x += direction.x * j;
            target.y += direction.y * j;
            target.z += direction.z * j;
            blockPos.set((int) target.x, (int) target.y, (int) target.z);
            Block currentBlock = worldProvider.getBlock(blockPos);
            /* PHYSICS */
            if (currentBlock.isDestructible()) {
                EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos);
                // allow explosions to chain together,  but do not chain on the instigating block
                if (!blockEntity.equals(instigatingBlockEntity) && blockEntity.hasComponent(ExplosionActionComponent.class)) {
                    doExplosion(blockEntity.getComponent(ExplosionActionComponent.class), blockPos.toVector3f(), blockEntity);
                } else {
                    blockEntity.send(new DoDamageEvent(explosionComp.damageAmount, explosionComp.damageType));
                }
            }
        }
    }
}
Also used : PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Block(org.terasology.world.block.Block) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) DoDamageEvent(org.terasology.logic.health.DoDamageEvent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 8 with PlaySoundEvent

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

the class ExplosionAuthoritySystem method onActivateFuseOnBlock.

@ReceiveEvent(components = ItemComponent.class)
public void onActivateFuseOnBlock(ActivateEvent event, EntityRef entityRef, TimedExplosionComponent timedExplosionComponent) {
    if (event.getTarget().hasComponent(BlockComponent.class) && event.getTarget().hasComponent(ExplosionActionComponent.class) && !event.getTarget().hasComponent(TimedExplosionComponent.class)) {
        Optional<StaticSound> fuseBurningSound = Assets.getSound("core:FuseBurning");
        if (fuseBurningSound.isPresent()) {
            event.getTarget().send(new PlaySoundEvent(fuseBurningSound.get(), 1f));
        }
        // add a timed explosion to the block so that it stays active
        event.getTarget().addComponent(new TimedExplosionComponent());
        delayManager.addDelayedAction(event.getTarget(), DELAYED_EXPLOSION_ACTION_ID, timedExplosionComponent.fuseTimeMs);
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 9 with PlaySoundEvent

use of org.terasology.audio.events.PlaySoundEvent 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 10 with PlaySoundEvent

use of org.terasology.audio.events.PlaySoundEvent 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)

Aggregations

PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)18 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)6 EntityRef (org.terasology.entitySystem.entity.EntityRef)4 Side (org.terasology.math.Side)4 Vector3f (org.terasology.math.geom.Vector3f)4 Vector3i (org.terasology.math.geom.Vector3i)4 LocationComponent (org.terasology.logic.location.LocationComponent)3 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)2 BlockComponent (org.terasology.world.block.BlockComponent)2 PlaceBlocks (org.terasology.world.block.entity.placement.PlaceBlocks)2 BlockSounds (org.terasology.world.block.sounds.BlockSounds)2 HashMap (java.util.HashMap)1 PlaySoundForOwnerEvent (org.terasology.audio.events.PlaySoundForOwnerEvent)1 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)1 BlockDamageModifierComponent (org.terasology.world.block.entity.damage.BlockDamageModifierComponent)1 BlockFamily (org.terasology.world.block.family.BlockFamily)1