Search in sources :

Example 11 with ReceiveEvent

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

the class CharacterSystem method onAttackRequest.

@ReceiveEvent(components = LocationComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onAttackRequest(AttackRequest event, EntityRef character, CharacterComponent characterComponent) {
    // if an item is used,  make sure this entity is allowed to attack with it
    if (event.getItem().exists()) {
        if (!character.equals(event.getItem().getOwner())) {
            return;
        }
    }
    OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
    character.send(onItemUseEvent);
    if (!onItemUseEvent.isConsumed()) {
        EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(character);
        LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
        Vector3f direction = gazeLocation.getWorldDirection(new Vector3f());
        Vector3f originPos = gazeLocation.getWorldPosition(new Vector3f());
        if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.RECORDING) {
            directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().add(direction, originPos);
        } else if (recordAndReplayCurrentStatus.getStatus() == RecordAndReplayStatus.REPLAYING) {
            Vector3f[] data = directionAndOriginPosRecorderList.getAttackEventDirectionAndOriginPosRecorder().poll();
            direction = data[0];
            originPos = data[1];
        }
        HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
        if (result.isHit()) {
            result.getEntity().send(new AttackEvent(character, event.getItem()));
        }
    }
}
Also used : HitResult(org.terasology.engine.physics.HitResult) OnItemUseEvent(org.terasology.engine.logic.characters.events.OnItemUseEvent) Vector3f(org.joml.Vector3f) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 12 with ReceiveEvent

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

the class CharacterSystem method onActivationRequest.

@ReceiveEvent(components = { CharacterComponent.class, LocationComponent.class }, netFilter = RegisterMode.AUTHORITY)
public void onActivationRequest(ActivationRequest event, EntityRef character) {
    if (isPredictionOfEventCorrect(character, event)) {
        OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
        event.getInstigator().send(onItemUseEvent);
        if (!onItemUseEvent.isConsumed()) {
            if (event.getUsedOwnedEntity().exists()) {
                event.getUsedOwnedEntity().send(new ActivateEvent(event));
            } else {
                event.getTarget().send(new ActivateEvent(event));
            }
        }
    } else {
        character.send(new ActivationRequestDenied(event.getActivationId()));
    }
}
Also used : ActivateEvent(org.terasology.engine.logic.common.ActivateEvent) OnItemUseEvent(org.terasology.engine.logic.characters.events.OnItemUseEvent) ActivationRequestDenied(org.terasology.engine.logic.characters.events.ActivationRequestDenied) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 13 with ReceiveEvent

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

the class CharacterSystem method beforeDestroy.

@ReceiveEvent
public void beforeDestroy(BeforeDestroyEvent event, EntityRef character, CharacterComponent characterComponent, AliveCharacterComponent aliveCharacterComponent) {
    if (character.hasComponent(PlayerCharacterComponent.class)) {
        // Consume the BeforeDestroyEvent so that the DoDestroy event is never sent for player entities
        event.consume();
        // PlayerDeathEvent only sent to the client for the player entity.
        PlayerDeathEvent playerDeathEvent = new PlayerDeathEvent();
        // Store the details of the death in the event for display on the death screen
        playerDeathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
        playerDeathEvent.instigatorName = getInstigatorName(event.getInstigator());
        character.send(playerDeathEvent);
    }
    // DeathEvent sent to client for any character entity.
    DeathEvent deathEvent = new DeathEvent();
    deathEvent.damageTypeName = getDamageTypeName(event.getDamageType());
    deathEvent.instigatorName = getInstigatorName(event.getInstigator());
    characterComponent.controller.send(deathEvent);
    character.removeComponent(AliveCharacterComponent.class);
// TODO: Don't just destroy, ragdoll or create particle effect or something (possible allow another system to handle)
// entity.removeComponent(CharacterComponent.class);
// entity.removeComponent(CharacterMovementComponent.class);
}
Also used : DeathEvent(org.terasology.engine.logic.characters.events.DeathEvent) PlayerDeathEvent(org.terasology.engine.logic.characters.events.PlayerDeathEvent) PlayerDeathEvent(org.terasology.engine.logic.characters.events.PlayerDeathEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 14 with ReceiveEvent

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

the class GazeAuthoritySystem method onScaleCharacter.

@ReceiveEvent(priority = EventPriority.PRIORITY_LOW)
public void onScaleCharacter(OnScaleEvent event, EntityRef entity, GazeMountPointComponent gazeMountPoint) {
    // adjust character eye level
    // set eye level based on "average" body decomposition for human-like figures into 7.5 "heads".
    // TODO: this glitches for some values (look through ceiling)
    gazeMountPoint.translate.y = (event.getNewValue() / 7.5f) * 7f - event.getNewValue() * 0.5f;
    Location.removeChild(entity, gazeMountPoint.gazeEntity);
    Location.attachChild(entity, gazeMountPoint.gazeEntity, gazeMountPoint.translate, new Quaternionf());
    entity.saveComponent(gazeMountPoint);
}
Also used : Quaternionf(org.joml.Quaternionf) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 15 with ReceiveEvent

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

the class GazeAuthoritySystem method ensureGazeContainerEntitiesCreated.

@ReceiveEvent
public void ensureGazeContainerEntitiesCreated(OnActivatedComponent event, EntityRef entityRef, GazeMountPointComponent gazeMountPointComponent, LocationComponent locationComponent) {
    if (!gazeMountPointComponent.gazeEntity.exists()) {
        gazeMountPointComponent.gazeEntity = createGazeEntity();
        entityRef.saveComponent(gazeMountPointComponent);
    }
    gazeMountPointComponent.translate.y = playerConfig.eyeHeight.get();
    Location.attachChild(entityRef, gazeMountPointComponent.gazeEntity, gazeMountPointComponent.translate, new Quaternionf());
}
Also used : Quaternionf(org.joml.Quaternionf) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2