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