/// <summary> /// Calculates all possibilities to move next to the Entity provided by <paramref name="p_moveToEntityNode"/>. /// </summary> private static IEnumerable <ADecisionNode> createMoveToNavigationNodesLink(DecisionTree p_aiDecisionTree, MoveToEntityNode p_moveToEntityNode) { var l_reachableNavigationNodes = NavigationGraphAlgorithm.getReachableNeighborNavigationNodes( NavigationGraphContainer.UniqueNavigationGraph, p_moveToEntityNode.TargetEntity.CurrentNavigationNode, NavigationGraphFlag.CURRENT).GetEnumerator(); while (l_reachableNavigationNodes.MoveNext()) { MoveToNavigationNodeNode l_moveToNavigationNodeNode = MoveToNavigationNodeNode.alloc(p_moveToEntityNode.SourceEntity.CurrentNavigationNode, l_reachableNavigationNodes.Current); DecisionTree.linkDecisionNodes(p_aiDecisionTree, p_moveToEntityNode, l_moveToNavigationNodeNode); yield return(l_moveToNavigationNodeNode); } /* If the source entity is already a neighbor of the target entity, we still create a node to move to same position to simulate the fact of staying at the same position. */ if (NavigationGraphAlgorithm.areNavigationNodesNeighbors( NavigationGraphContainer.UniqueNavigationGraph, p_moveToEntityNode.SourceEntity.CurrentNavigationNode, p_moveToEntityNode.TargetEntity.CurrentNavigationNode, NavigationGraphFlag.SNAPSHOT)) { MoveToNavigationNodeNode l_moveToNavigationNodeNode = MoveToNavigationNodeNode.alloc(p_moveToEntityNode.SourceEntity.CurrentNavigationNode, p_moveToEntityNode.SourceEntity.CurrentNavigationNode); DecisionTree.linkDecisionNodes(p_aiDecisionTree, p_moveToEntityNode, l_moveToNavigationNodeNode); yield return(l_moveToNavigationNodeNode); } }
// called only once public override void Execute(EventQueue p_eventQueue) { if (SourceEntity.MarkedForDestruction) { Completed = true; return; } float l_costToMove = _ActionPoint.Calculations.actionPointBetweenNavigationNodes(SourceEntity.CurrentNavigationNode, TargetNavigationNode); ActionPoint l_actionPoint = EntityComponent.get_component <ActionPoint>(SourceEntity); MovementAllowed = (l_actionPoint.ActionPointData.CurrentActionPoints >= l_costToMove && NavigationGraphAlgorithm.areNavigationNodesNeighbors(NavigationGraphContainer.UniqueNavigationGraph, SourceEntity.CurrentNavigationNode, TargetNavigationNode, NavigationGraphFlag.CURRENT)); if (MovementAllowed) { LocomotionSystemV2.HeadTowardsNode(EntityComponent.get_component <Locomotion>(SourceEntity).LocomotionSystemV2, TargetNavigationNode, (p_startNavigationNode, p_endNavigationNode) => { ActionPoint.add(l_actionPoint, -1 * l_costToMove); Completed = true; }); } else { Completed = true; } }
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 override void TreeTraversal(ADecisionNode p_sourceNode) { using (NavigationGraphAlgorithm.CalculatePathRequest l_calculationRequest = NavigationGraphAlgorithm.CalculatePathRequest.CalculatePathRequestPool.popOrCreate()) { NavigationGraphAlgorithm.CalculatePathRequest.prepareForCalculation( l_calculationRequest, NavigationGraphContainer.UniqueNavigationGraph, SourceNavigationNode, TargetNavigationNode, PathCalculationParameters.build(2.0f)); NavigationGraphAlgorithm.CalculatePath(l_calculationRequest); ref NavigationPath l_calculatedNavigationPath = ref l_calculationRequest.ResultPath; NavigationPath = new List <NavigationNode>(l_calculatedNavigationPath.NavigationNodes); PathCost = l_calculatedNavigationPath.PathCost; }
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); }
private void onEntityCreated(Entity p_entity) { AssociatedEntity = p_entity; AssociatedEntity.EntityGameWorldInstanceID = new EntityGameWorldInstanceID() { ID = GetInstanceID() }; AssociatedEntity.EntityGameWorld = EntityGameWorld.build(TransformComponent.alloc()); TransformComponentSynchronizer.alloc(AssociatedEntity.EntityGameWorld.RootGround); EntityModelTransformSynchronizer = TransformSynchronizer.alloc(transform, AssociatedEntity.EntityGameWorld.RootGround.TransformComponentSynchronizer); TransformSynchronizerContainer.TransformSynchronizers.Add(EntityModelTransformSynchronizer); MyEvent <Entity> .IEventCallback l_onEntityDestroyed = OnEntityDestroyed.build(this); MyEvent <Entity> .register( ref this.AssociatedEntity.OnEntityDestroyed, ref l_onEntityDestroyed); // Initializing Entity components EntityDefinition.Initialize( ref this.EntityDefinition, ref this.AssociatedEntity, this.RuntimeObject.RuntimeObjectRootComponent); NavigationNode l_randomNavigationNode = NavigationGraphAlgorithm.pickRandomNode(NavigationGraphComponentContainer.UniqueNavigationGraphComponent.NavigationGraph); EventQueue.enqueueEvent(EventQueueContainer.TurnTimelineQueue, NavigationNodeWarpEntityEvent.alloc(AssociatedEntity, l_randomNavigationNode)); AnimationVisualFeedback l_animationVisualFeedbackComponent = EntityComponent.get_component <AnimationVisualFeedback>(AssociatedEntity); if (l_animationVisualFeedbackComponent != null) { EventQueue.enqueueEvent(EventQueueContainer.TurnTimelineQueue, AnimationVisualFeedbackPlayAsyncEvent.alloc(l_animationVisualFeedbackComponent, AnimationLayers.BASE, l_animationVisualFeedbackComponent.AnimationVisualFeedbackData.GetAnimation(AnimationLookupTag.IDLE).GetAnimationInput())); } }
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); }