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