Search in sources :

Example 66 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onLanded.

@ReceiveEvent
public void onLanded(VerticalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    Vector3f velocity = event.getVelocity();
    float soundVolumeModifier = (velocity.y * -1 - LANDING_VELOCITY_THRESHOLD) * LANDING_VOLUME_MODIFIER;
    if (soundVolumeModifier <= 0f) {
        return;
    }
    if (soundVolumeModifier > LANDING_VOLUME_MAX) {
        soundVolumeModifier = LANDING_VOLUME_MAX;
    }
    if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        StaticSound sound = null;
        if (characterSounds.landingSounds.size() > 0) {
            sound = random.nextItem(characterSounds.landingSounds);
        } else if (characterSounds.footstepSounds.size() > 0) {
            sound = random.nextItem(characterSounds.footstepSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.landingVolume * soundVolumeModifier));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) Vector3f(org.terasology.math.geom.Vector3f) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 67 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterSoundSystem method onEnterBlock.

@ReceiveEvent
public void onEnterBlock(OnEnterBlockEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
    // only play this sound if the feet hit the water
    if (event.getCharacterRelativePosition().y == 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
        boolean oldBlockIsLiquid = event.getOldBlock().isLiquid();
        boolean newBlockIsLiquid = event.getNewBlock().isLiquid();
        StaticSound sound = null;
        if (!oldBlockIsLiquid && newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.enterWaterSounds);
        } else if (oldBlockIsLiquid && !newBlockIsLiquid) {
            sound = random.nextItem(characterSounds.leaveWaterSounds);
        }
        if (sound != null) {
            entity.send(new PlaySoundEvent(entity, sound, characterSounds.diveVolume));
            characterSounds.lastSoundTime = time.getGameTimeInMs();
            entity.saveComponent(characterSounds);
        }
    }
}
Also used : StaticSound(org.terasology.audio.StaticSound) PlaySoundEvent(org.terasology.audio.events.PlaySoundEvent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 68 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterSystem method onAttackRequest.

@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onAttackRequest(AttackButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
    if (!event.isDown()) {
        return;
    }
    boolean attackRequestIsValid;
    if (networkSystem.getMode().isAuthority()) {
        // Let the AttackRequest handler trigger the OnItemUseEvent if this is a local client
        attackRequestIsValid = true;
    } else {
        OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
        entity.send(onItemUseEvent);
        attackRequestIsValid = !onItemUseEvent.isConsumed();
    }
    if (attackRequestIsValid) {
        EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
        entity.send(new AttackRequest(selectedItemEntity));
        event.consume();
    }
}
Also used : AttackRequest(org.terasology.logic.characters.events.AttackRequest) OnItemUseEvent(org.terasology.logic.characters.events.OnItemUseEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 69 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class CharacterSystem method onItemUse.

@ReceiveEvent(components = { CharacterComponent.class })
public void onItemUse(OnItemUseEvent event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
    long currentTime = time.getGameTimeInMs();
    if (characterHeldItemComponent.nextItemUseTime > currentTime) {
        // this character is not yet ready to use another item,  they are still cooling down from last use
        event.consume();
        return;
    }
    EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
    characterHeldItemComponent.lastItemUsedTime = currentTime;
    characterHeldItemComponent.nextItemUseTime = currentTime;
    ItemComponent itemComponent = selectedItemEntity.getComponent(ItemComponent.class);
    // Add the cooldown time for the next use of this item.
    if (itemComponent != null) {
        // Send out this event so other systems can alter the cooldown time.
        AffectItemUseCooldownTimeEvent affectItemUseCooldownTimeEvent = new AffectItemUseCooldownTimeEvent(itemComponent.cooldownTime);
        entity.send(affectItemUseCooldownTimeEvent);
        characterHeldItemComponent.nextItemUseTime += affectItemUseCooldownTimeEvent.getResultValue();
    } else {
        characterHeldItemComponent.nextItemUseTime += 200;
    }
    entity.saveComponent(characterHeldItemComponent);
}
Also used : ItemComponent(org.terasology.logic.inventory.ItemComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 70 with ReceiveEvent

use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class ClientCharacterPredictionSystem method onDestroy.

@ReceiveEvent(components = { CharacterComponent.class, CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onDestroy(final BeforeDeactivateComponent event, final EntityRef entity) {
    CharacterComponent character = entity.getComponent(CharacterComponent.class);
    ClientComponent controller = character.controller.getComponent(ClientComponent.class);
    if (controller != null && controller.local) {
        predictedState = null;
        authoritiveState = null;
        inputs.clear();
    }
    physics.removeCharacterCollider(entity);
    playerStates.remove(entity);
}
Also used : ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2