Search in sources :

Example 1 with OnScaleEvent

use of org.terasology.engine.logic.characters.events.OnScaleEvent in project Terasology by MovingBlocks.

the class CharacterScalingSystem method onScaleByRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onScaleByRequest(ScaleByRequest request, EntityRef entity, CharacterMovementComponent movementComponent) {
    OnScaleEvent scaleEvent = new OnScaleEvent(movementComponent.height, movementComponent.height * request.getFactor());
    entity.send(scaleEvent);
    request.consume();
}
Also used : OnScaleEvent(org.terasology.engine.logic.characters.events.OnScaleEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 2 with OnScaleEvent

use of org.terasology.engine.logic.characters.events.OnScaleEvent in project Terasology by MovingBlocks.

the class CharacterScalingSystem method onScaleToRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onScaleToRequest(ScaleToRequest request, EntityRef entity, CharacterMovementComponent movementComponent) {
    OnScaleEvent scaleEvent = new OnScaleEvent(movementComponent.height, request.getTargetValue());
    entity.send(scaleEvent);
    request.consume();
}
Also used : OnScaleEvent(org.terasology.engine.logic.characters.events.OnScaleEvent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 3 with OnScaleEvent

use of org.terasology.engine.logic.characters.events.OnScaleEvent in project Terasology by MovingBlocks.

the class CharacterSystem method onScaleCharacter.

@ReceiveEvent
public void onScaleCharacter(OnScaleEvent event, EntityRef entity, CharacterComponent character, CharacterMovementComponent movement) {
    // TODO: We should catch and consume this event somewhere in case there is no space for the character to grow
    Prefab parent = entity.getParentPrefab();
    // adjust movement parameters based on the default values defined by prefab
    CharacterMovementComponent defaultMovement = Optional.ofNullable(parent.getComponent(CharacterMovementComponent.class)).orElse(new CharacterMovementComponent());
    final float factor = event.getFactor();
    movement.height = factor * movement.height;
    movement.jumpSpeed = getJumpSpeed(factor, defaultMovement.jumpSpeed);
    movement.stepHeight = factor * movement.stepHeight;
    movement.distanceBetweenFootsteps = factor * movement.distanceBetweenFootsteps;
    movement.runFactor = getRunFactor(factor, defaultMovement.runFactor);
    entity.saveComponent(movement);
    // adjust character parameters
    CharacterComponent defaultCharacter = Optional.ofNullable(parent.getComponent(CharacterComponent.class)).orElse(new CharacterComponent());
    character.interactionRange = getInteractionRange(factor, defaultCharacter.interactionRange);
    entity.saveComponent(character);
    // refresh the entity collider - by retrieving the character collider after removing it we force recreation
    physicsEngine.removeCharacterCollider(entity);
    physicsEngine.getCharacterCollider(entity);
    // Scaling a character up will grow them into the ground. We would need to adjust the vertical position to be
    // safely above ground.
    Optional.ofNullable(entity.getComponent(LocationComponent.class)).map(k -> k.getWorldPosition(new Vector3f())).map(location -> location.add(0, (event.getNewValue() - event.getOldValue()) / 2f, 0)).ifPresent(location -> entity.send(new CharacterTeleportEvent(location)));
}
Also used : ActivateEvent(org.terasology.engine.logic.common.ActivateEvent) In(org.terasology.engine.registry.In) RegisterMode(org.terasology.engine.entitySystem.systems.RegisterMode) DestroyEvent(org.terasology.engine.logic.health.DestroyEvent) LoggerFactory(org.slf4j.LoggerFactory) BeforeDestroyEvent(org.terasology.engine.logic.health.BeforeDestroyEvent) PhysicsEngine(org.terasology.engine.physics.engine.PhysicsEngine) UpdateSubscriberSystem(org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem) Physics(org.terasology.engine.physics.Physics) ActAsBlockComponent(org.terasology.engine.world.block.regions.ActAsBlockComponent) InteractionUtil(org.terasology.engine.logic.characters.interactions.InteractionUtil) EngineDamageTypes(org.terasology.engine.logic.health.EngineDamageTypes) DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) Time(org.terasology.engine.core.Time) OnScaleEvent(org.terasology.engine.logic.characters.events.OnScaleEvent) Vector3f(org.joml.Vector3f) RangeComponent(org.terasology.engine.logic.common.RangeComponent) AttackEvent(org.terasology.engine.logic.characters.events.AttackEvent) OnItemUseEvent(org.terasology.engine.logic.characters.events.OnItemUseEvent) ActivationRequest(org.terasology.engine.logic.characters.events.ActivationRequest) Logger(org.slf4j.Logger) DeathEvent(org.terasology.engine.logic.characters.events.DeathEvent) HitResult(org.terasology.engine.physics.HitResult) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ClientComponent(org.terasology.engine.network.ClientComponent) AttackRequest(org.terasology.engine.logic.characters.events.AttackRequest) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) StandardCollisionGroup(org.terasology.engine.physics.StandardCollisionGroup) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) Sets(com.google.common.collect.Sets) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) BaseComponentSystem(org.terasology.engine.entitySystem.systems.BaseComponentSystem) PlayerDeathEvent(org.terasology.engine.logic.characters.events.PlayerDeathEvent) ItemComponent(org.terasology.engine.logic.inventory.ItemComponent) ActivationRequestDenied(org.terasology.engine.logic.characters.events.ActivationRequestDenied) RecordAndReplayStatus(org.terasology.engine.recording.RecordAndReplayStatus) AttackButton(org.terasology.engine.input.binds.interaction.AttackButton) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) EventPriority(org.terasology.engine.entitySystem.event.EventPriority) RegisterSystem(org.terasology.engine.entitySystem.systems.RegisterSystem) BlockComponent(org.terasology.engine.world.block.BlockComponent) PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent) Optional(java.util.Optional) DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) CollisionGroup(org.terasology.engine.physics.CollisionGroup) NetworkSystem(org.terasology.engine.network.NetworkSystem) Vector3f(org.joml.Vector3f) PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)3 OnScaleEvent (org.terasology.engine.logic.characters.events.OnScaleEvent)3 Sets (com.google.common.collect.Sets)1 Optional (java.util.Optional)1 Vector3f (org.joml.Vector3f)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 Time (org.terasology.engine.core.Time)1 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 EventPriority (org.terasology.engine.entitySystem.event.EventPriority)1 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)1 BaseComponentSystem (org.terasology.engine.entitySystem.systems.BaseComponentSystem)1 RegisterMode (org.terasology.engine.entitySystem.systems.RegisterMode)1 RegisterSystem (org.terasology.engine.entitySystem.systems.RegisterSystem)1 UpdateSubscriberSystem (org.terasology.engine.entitySystem.systems.UpdateSubscriberSystem)1 AttackButton (org.terasology.engine.input.binds.interaction.AttackButton)1 ActivationRequest (org.terasology.engine.logic.characters.events.ActivationRequest)1 ActivationRequestDenied (org.terasology.engine.logic.characters.events.ActivationRequestDenied)1 AttackEvent (org.terasology.engine.logic.characters.events.AttackEvent)1