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);
}
}
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));
}
}
}
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);
}
}
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);
}
}
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));
}
}
Aggregations