Search in sources :

Example 1 with AttackRequest

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

the class ByteCodeReflectFactoryTest method testCreateConstructorObjectWithProtectedConstructor.

@Test
public void testCreateConstructorObjectWithProtectedConstructor() throws Exception {
    ReflectFactory reflectFactory = new ByteCodeReflectFactory();
    ObjectConstructor<AttackRequest> constructor = reflectFactory.createConstructor(AttackRequest.class);
    AttackRequest result = constructor.construct();
    assertNotNull(result);
}
Also used : ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) ByteCodeReflectFactory(org.terasology.engine.reflection.reflect.ByteCodeReflectFactory) AttackRequest(org.terasology.engine.logic.characters.events.AttackRequest) Test(org.junit.jupiter.api.Test)

Example 2 with AttackRequest

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

the class CharacterSystem method onAttackRequest.

@ReceiveEvent(components = CharacterComponent.class, netFilter = RegisterMode.CLIENT)
public void onAttackRequest(AttackButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
    if (!event.isDown()) {
        return;
    }
    boolean attackRequestIsValid;
    if (networkSystem.getMode().isAuthority()) {
        // Let the AttackRequest handler trigger the OnItemUseEvent if this is a local client
        attackRequestIsValid = true;
    } else {
        OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
        entity.send(onItemUseEvent);
        attackRequestIsValid = !onItemUseEvent.isConsumed();
    }
    if (attackRequestIsValid) {
        EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
        entity.send(new AttackRequest(selectedItemEntity));
        event.consume();
    }
}
Also used : AttackRequest(org.terasology.engine.logic.characters.events.AttackRequest) OnItemUseEvent(org.terasology.engine.logic.characters.events.OnItemUseEvent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

AttackRequest (org.terasology.engine.logic.characters.events.AttackRequest)2 Test (org.junit.jupiter.api.Test)1 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)1 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)1 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)1 ByteCodeReflectFactory (org.terasology.engine.reflection.reflect.ByteCodeReflectFactory)1