use of org.terasology.engine.logic.characters.events.AttackEvent 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.logic.characters.events.AttackEvent in project Terasology by MovingBlocks.
the class EventCopier method copyEvent.
public Event copyEvent(Event toBeCopied) {
if (toBeCopied instanceof PlaySoundEvent) {
return toBeCopied;
} else if (toBeCopied instanceof BindButtonEvent) {
BindButtonEvent originalEvent = (BindButtonEvent) toBeCopied;
BindButtonEvent newEvent = (BindButtonEvent) createNewBindEvent(originalEvent);
newEvent.prepare(originalEvent.getId(), originalEvent.getState(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof KeyEvent) {
KeyEvent originalEvent = (KeyEvent) toBeCopied;
KeyEvent newEvent = createNewKeyEvent(originalEvent);
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof BindAxisEvent) {
BindAxisEvent originalEvent = (BindAxisEvent) toBeCopied;
BindAxisEvent newEvent = (BindAxisEvent) createNewBindEvent(originalEvent);
newEvent.prepare(originalEvent.getId(), (float) originalEvent.getValue(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof MouseAxisEvent) {
MouseAxisEvent originalEvent = (MouseAxisEvent) toBeCopied;
MouseAxisEvent newEvent = createNewMouseAxisEvent(originalEvent);
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof CameraTargetChangedEvent) {
CameraTargetChangedEvent originalEvent = (CameraTargetChangedEvent) toBeCopied;
return new CameraTargetChangedEvent(originalEvent.getOldTarget(), originalEvent.getNewTarget());
} else if (toBeCopied instanceof CharacterMoveInputEvent) {
CharacterMoveInputEvent originalEvent = (CharacterMoveInputEvent) toBeCopied;
return new CharacterMoveInputEvent(originalEvent.getSequenceNumber(), originalEvent.getPitch(), originalEvent.getYaw(), originalEvent.getMovementDirection(), originalEvent.isRunning(), originalEvent.isCrouching(), originalEvent.isJumping(), originalEvent.getDeltaMs());
} else if (toBeCopied instanceof MouseButtonEvent) {
MouseButtonEvent originalEvent = (MouseButtonEvent) toBeCopied;
MouseButtonEvent newEvent = new MouseButtonEvent(originalEvent.getButton(), originalEvent.getState(), originalEvent.getDelta());
newEvent.setMousePosition(originalEvent.getMousePosition());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof MouseWheelEvent) {
MouseWheelEvent originalEvent = (MouseWheelEvent) toBeCopied;
MouseWheelEvent newEvent = new MouseWheelEvent(originalEvent.getMousePosition(), originalEvent.getWheelTurns(), originalEvent.getDelta());
inputEventSetup(newEvent, originalEvent);
return newEvent;
} else if (toBeCopied instanceof GetMaxSpeedEvent) {
GetMaxSpeedEvent originalEvent = (GetMaxSpeedEvent) toBeCopied;
GetMaxSpeedEvent newEvent = new GetMaxSpeedEvent(originalEvent.getBaseValue(), originalEvent.getMovementMode());
newEvent.setModifiers(originalEvent.getModifiers());
newEvent.setMultipliers(originalEvent.getMultipliers());
newEvent.setPostModifiers(originalEvent.getPostModifiers());
return newEvent;
} else if (toBeCopied instanceof AttackEvent) {
AttackEvent originalEvent = (AttackEvent) toBeCopied;
AttackEvent newEvent = new AttackEvent(originalEvent.getInstigator(), originalEvent.getDirectCause());
return newEvent;
} else {
return null;
}
}
Aggregations