Пример #1
0
        // 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;
            }
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
        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);
                    }
                }
            }
        }