public override void Execute(EventQueue p_eventQueue) { if ( !SourceEntity.MarkedForDestruction && !TargetEntity.MarkedForDestruction && NavigationGraphAlgorithm.areNavigationNodesNeighbors(NavigationGraphContainer.UniqueNavigationGraph, SourceEntity.CurrentNavigationNode, TargetEntity.CurrentNavigationNode, NavigationGraphFlag.SNAPSHOT)) { ActionPoint l_actionPoint = EntityComponent.get_component <ActionPoint>(SourceEntity); if (l_actionPoint.ActionPointData.CurrentActionPoints >= Attack.AttackData.APCost) { ActionPoint.add(EntityComponent.get_component <ActionPoint>(SourceEntity), -1 * Attack.AttackData.APCost); EntityGameWorld.orientTowards(ref SourceEntity.EntityGameWorld, TargetEntity, math.up()); float l_appliedDamage = Attack.resolve(Attack, TargetEntity); EventQueue.insertEventAt(p_eventQueue, 0, EntityApplyDamageEvent.alloc(TargetEntity, l_appliedDamage)); if (Attack.AttackBeforeDamageEventHook != null) { Attack.AttackBeforeDamageEventHook.SourceEntity = SourceEntity; Attack.AttackBeforeDamageEventHook.FeedEventQueue(p_eventQueue, 0); } } } }
public void TriggerComponentTest_executionOrder() { // Initializing trigger Entity Entity l_testTriggerEntity = Entity.alloc(); l_testTriggerEntity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); NavigationEngineTestTriggerComponent_Order1st l_firstTrigger = NavigationEngineTestTriggerComponent_Order1st.alloc(); NavigationEngineTestTriggerComponent_Order2nd l_secondTrigger = NavigationEngineTestTriggerComponent_Order2nd.alloc(l_firstTrigger); EntityComponent.add_component(l_testTriggerEntity, l_secondTrigger); EntityComponent.add_component(l_testTriggerEntity, l_firstTrigger); EntityComponent.add_component(l_testTriggerEntity, Locomotion.alloc(new LocomotionData())); // We warp the l_testTriggeredEntity to a random NavigationNode EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_testTriggerEntity, NavigationGraphAlgorithm.pickRandomNode(NavigationGraphContainer.UniqueNavigationGraph) ) ); EventQueue.iterate(TestEventQueue); // We create the Entity that will be involved in the trigger Entity l_entity = Entity.alloc(); l_entity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); EntityComponent.add_component(l_entity, Locomotion.alloc(new LocomotionData())); EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_entity, l_testTriggerEntity.CurrentNavigationNode ) ); EventQueue.iterate(TestEventQueue); NavigationEngineTestTriggerComponent l_triggerComponent = EntityComponent.get_component <NavigationEngineTestTriggerComponent>(l_testTriggerEntity); Assert.IsTrue(l_secondTrigger.ExecutedAfterTriggerSupposedToBeBefore); }
public void Tick(float d) { if (HeadingTowardsTargetNode) { float3 l_initialDirection = math.normalize(CurrentDestination - LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition); float3 l_targetPosition = LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition + (l_initialDirection * LocomotionComponent.LocomotionData.Speed * d); float3 l_finalDirection = math.normalize(CurrentDestination - l_targetPosition); // If the initial direction is not the same as the final direction, this means that the destination point has been crossed // thus, the destination is reached bool l_isDestinationReached = math.dot(l_initialDirection, l_finalDirection) <= 0.0f; if (l_isDestinationReached) { /* * When the NavigationNode is reached, we set the position to the exact final location. */ l_targetPosition = CurrentDestination; } LocomotionComponent.AssociatedEntity.EntityGameWorld.RootGround.WorldPosition = l_targetPosition; if (l_isDestinationReached) { HeadingTowardsTargetNode = false; NavigationNode l_oldNavigationNode = LocomotionComponent.AssociatedEntity.CurrentNavigationNode; if (OnNavigationNodeReachedEvent != null) { OnNavigationNodeReachedEvent.Invoke(l_oldNavigationNode, CurrentTargetNode); } } else { float3 l_orientationDirection = l_initialDirection.ProjectOnPlane(math.up()); EntityGameWorld.orientTowards(ref LocomotionComponent.AssociatedEntity.EntityGameWorld, ref l_orientationDirection); } } }
public void TriggerComponentTest_navigationNodeMove() { // Initializing trigger Entity Entity l_testTriggerEntity = Entity.alloc(); l_testTriggerEntity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); EntityComponent.add_component(l_testTriggerEntity, NavigationEngineTestTriggerComponent.alloc()); EntityComponent.add_component(l_testTriggerEntity, Locomotion.alloc(new LocomotionData() { Speed = float.MaxValue * 0.1f })); // We warp the l_testTriggeredEntity to a random NavigationNode EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_testTriggerEntity, NavigationGraphAlgorithm.pickRandomNode(NavigationGraphContainer.UniqueNavigationGraph) ) ); EventQueue.iterate(TestEventQueue); // We create the Entity that will be involved in the trigger Entity l_entity = Entity.alloc(); l_entity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); EntityComponent.add_component(l_entity, Locomotion.alloc(new LocomotionData() { Speed = float.MaxValue * 0.1f })); ActionPointData l_actionPointdata = new ActionPointData() { InitialActionPoints = 999f, CurrentActionPoints = 999f }; EntityComponent.add_component(l_entity, ActionPoint.alloc(ref l_actionPointdata)); var l_entityNavigationNodeEnumerator = NavigationGraphAlgorithm.getReachableNeighborNavigationNodes(NavigationGraphContainer.UniqueNavigationGraph, l_testTriggerEntity.CurrentNavigationNode, NavigationGraphFlag.CURRENT).GetEnumerator(); l_entityNavigationNodeEnumerator.MoveNext(); EventQueue.enqueueEvent( TestEventQueue, NavigationNodeWarpEntityEvent.alloc( l_entity, l_entityNavigationNodeEnumerator.Current ) ); NavigationNodeMoveEvent l_navigationNodeMoveEvent = NavigationNodeMoveEvent.alloc(l_entity, l_testTriggerEntity.CurrentNavigationNode); EventQueue.enqueueEvent( TestEventQueue, l_navigationNodeMoveEvent ); while (!l_navigationNodeMoveEvent.IsCompleted()) { LocomotionSystemV2Container.Tick(1.0f); EventQueue.iterate(TestEventQueue); } NavigationEngineTestTriggerComponent l_triggerComponent = EntityComponent.get_component <NavigationEngineTestTriggerComponent>(l_testTriggerEntity); Assert.IsTrue(l_triggerComponent.IsTriggered); Assert.IsTrue(l_triggerComponent.TriggeredEntity == l_entity); }