// IComponent
        public void Init()
        {
            _waitAsyncQueue = DeltinScript.VarCollection.Assign("waitAsync_queue", true, false);
            DeltinScript.InitialGlobal.ActionSet.AddAction(_waitAsyncQueue.SetVariable(new V_EmptyArray()));

            // Rule creator.
            var rule = new TranslateRule(DeltinScript, "waitAsync", RuleEvent.OngoingGlobal);

            rule.Conditions.Add(new Condition(
                                    Element.Part <V_IsTrueForAny>(_waitAsyncQueue.Get(), ArrayElementTimeSurpassed(new V_ArrayElement()))
                                    ));

            // Get the affected item.
            var item = DeltinScript.VarCollection.Assign("waitAsync_item", true, false);

            rule.ActionSet.AddAction(item.SetVariable(Element.Part <V_FirstOf>(Element.Part <V_FilteredArray>(
                                                                                   Element.Part <V_MappedArray>(_waitAsyncQueue.Get(), new V_CurrentArrayIndex()),
                                                                                   ArrayElementTimeSurpassed(_waitAsyncQueue.Get()[new V_ArrayElement()])
                                                                                   ))));

            // Activate item lambda.
            DeltinScript.GetComponent <LambdaGroup>().Call(rule.ActionSet.New(Element.Part <V_LastOf>(_waitAsyncQueue.Get()[item.Get()])), new CallHandler());

            // Remove from queue.
            rule.ActionSet.AddAction(_waitAsyncQueue.ModifyVariable(Operation.RemoveFromArrayByIndex, item.Get()));

            // Loop if another item needs to execute on the same tick.
            rule.ActionSet.AddAction(Element.Part <A_LoopIfConditionIsTrue>());

            // Get the rule.
            DeltinScript.WorkshopRules.Add(rule.GetRule());
        }
Ejemplo n.º 2
0
        void GetResolveCurrentRule()
        {
            // Create the rule that will get the closest node.
            TranslateRule getResolveRule = new TranslateRule(DeltinScript, "Pathfinder: Resolve Current", RuleEvent.OngoingPlayer);

            // The rule will activate when DoGetCurrent is set to true.
            getResolveRule.Conditions.Add(new Condition((Element)DoGetCurrent.GetVariable(), Operator.Equal, Element.True()));
            // Set the Current variable to the closest node.
            getResolveRule.ActionSet.AddAction(Current.SetVariable(ClosestNode(getResolveRule.ActionSet, PlayerPosition())));

            // If the OnPathStart hook is null, do the default which is throttling the player to the next node.
            if (OnPathStart == null)
            {
                // Start throttle to the current node.
                ThrottleEventPlayerToNextNode(getResolveRule.ActionSet);
            }
            // Otherwise, use the hook.
            else
            {
                OnPathStart.Invoke(getResolveRule.ActionSet);
            }

            // Update IsPathfindStuck data.
            UpdateStuckDetector(getResolveRule.ActionSet, EventPlayer());

            // Reset DoGetCurrent to false.
            getResolveRule.ActionSet.AddAction(DoGetCurrent.SetVariable(Element.False()));

            // Add the rule.
            DeltinScript.WorkshopRules.Add(getResolveRule.GetRule());
        }
        // IComponent
        public void Init(DeltinScript deltinScript)
        {
            DeltinScript = deltinScript;

            _waitAsyncQueue = DeltinScript.VarCollection.Assign("waitAsync_queue", true, false);
            DeltinScript.InitialGlobal.ActionSet.AddAction(_waitAsyncQueue.SetVariable(Element.EmptyArray()));

            // Rule creator.
            var rule = new TranslateRule(DeltinScript, "waitAsync", RuleEvent.OngoingGlobal);

            rule.Conditions.Add(new Condition(
                                    Element.Any(_waitAsyncQueue.Get(), ArrayElementTimeSurpassed(Element.ArrayElement()))
                                    ));

            // Get the affected item.
            var item = DeltinScript.VarCollection.Assign("waitAsync_item", true, false);

            rule.ActionSet.AddAction(item.SetVariable(Element.FirstOf(Element.Filter(
                                                                          Element.Map(_waitAsyncQueue.Get(), Element.ArrayIndex()),
                                                                          ArrayElementTimeSurpassed(_waitAsyncQueue.Get()[Element.ArrayElement()])
                                                                          ))));

            // Activate item lambda.
            DeltinScript.WorkshopConverter.LambdaBuilder.Call(rule.ActionSet.New(Element.LastOf(_waitAsyncQueue.Get()[item.Get()])), new Functions.Builder.CallInfo(), null);

            // Remove from queue.
            rule.ActionSet.AddAction(_waitAsyncQueue.ModifyVariable(Operation.RemoveFromArrayByIndex, item.Get()));

            // Loop if another item needs to execute on the same tick.
            rule.ActionSet.AddAction(Element.LoopIfConditionIsTrue());

            // Get the rule.
            DeltinScript.WorkshopRules.Add(rule.GetRule());
        }
Ejemplo n.º 4
0
        private Rule GetStartRule(DeltinScript deltinScript)
        {
            var condition = new Condition(
                Element.Part <V_CountOf>(Path.GetVariable()),
                Operators.GreaterThan,
                0
                );

            Element eventPlayer    = new V_EventPlayer();
            Element eventPlayerPos = Element.Part <V_PositionOf>(eventPlayer);

            TranslateRule rule = new TranslateRule(deltinScript, Constants.INTERNAL_ELEMENT + "Pathfinder: Move", RuleEvent.OngoingPlayer);

            IfBuilder isBetween = new IfBuilder(rule.ActionSet,
                                                Element.Part <V_And>(
                                                    Element.Part <V_CountOf>(Path.GetVariable()) >= 2,
                                                    IsBetween(eventPlayerPos, NextPosition(eventPlayer), PositionAt(eventPlayer, 1))
                                                    )
                                                );

            isBetween.Setup();
            rule.ActionSet.AddAction(Next());
            isBetween.Finish();

            rule.ActionSet.AddAction(ArrayBuilder <Element> .Build
                                     (
                                         LastUpdate.SetVariable(new V_TotalTimeElapsed()),
                                         DistanceToNext.SetVariable(Element.Part <V_DistanceBetween>(Element.Part <V_PositionOf>(new V_EventPlayer()), NextPosition(new V_EventPlayer()))),
                                         // Element.Part<A_StartFacing>(
                                         //     new V_EventPlayer(),
                                         //     Element.Part<V_DirectionTowards>(
                                         //         new V_EyePosition(),
                                         //         NextPosition()
                                         //     ),
                                         //     new V_Number(700),
                                         //     EnumData.GetEnumValue(Relative.ToWorld),
                                         //     EnumData.GetEnumValue(FacingRev.DirectionAndTurnRate)
                                         // ),

                                         // Move to the next node.
                                         Element.Part <A_StartThrottleInDirection>(
                                             new V_EventPlayer(),
                                             Element.Part <V_DirectionTowards>(
                                                 new V_EyePosition(),
                                                 NextPosition(new V_EventPlayer()) // Because of ThrottleRev this will be reevaluated so 'Start Throttle In Direction' only needs to run once.
                                                 ),
                                             new V_Number(1),
                                             EnumData.GetEnumValue(Relative.ToWorld),
                                             EnumData.GetEnumValue(ThrottleBehavior.ReplaceExistingThrottle),
                                             EnumData.GetEnumValue(ThrottleRev.DirectionAndMagnitude)
                                             )
                                     ));

            var result = rule.GetRule();

            result.Conditions = new Condition[] { condition };
            return(result);
        }
Ejemplo n.º 5
0
        void GetNextNodeRule()
        {
            // The 'next' rule will set current to the next node index when the current node is reached.
            TranslateRule next = new TranslateRule(DeltinScript, "Pathfinder: Resolve Next", RuleEvent.OngoingPlayer);

            next.Conditions.Add(NodeReachedCondition(next.ActionSet));
            next.Conditions.Add(new Condition(ParentArray.Get(), Operator.NotEqual, Element.Null()));

            GetNextNode(next.ActionSet, EventPlayer());

            // Loop the next rule if the condition is true.
            next.ActionSet.AddAction(LoopIfConditionIsTrue());

            // Add rule
            DeltinScript.WorkshopRules.Add(next.GetRule());
        }
        public void Complete()
        {
            _functionBuilder.Controller.Build(_functionBuilder.ActionSet);
            _functionBuilder.ReturnHandler?.ApplyReturnSkips();

            if (_context.Controller.Attributes.IsRecursive)
            {
                _parameterHandler.Pop(_actionSet);

                // Pop object array.
                if (_context.Controller.Attributes.IsInstance)
                {
                    _actionSet.AddAction(_objectStore.ModifyVariable(Operation.RemoveFromArrayByIndex, Element.CountOf(_objectStore.GetVariable()) - 1));
                }
            }

            // Add the subroutine.
            Rule translatedRule = _subroutineRule.GetRule();

            _deltinScript.WorkshopRules.Add(translatedRule);
        }
        private void GetResolveRoutine()
        {
            // Create the rule that will get the closest node.
            TranslateRule getResolveRule = new TranslateRule(DeltinScript, "Pathfinder: Resolve Current", RuleEvent.OngoingPlayer);

            // The rule will activate when DoGetCurrent is set to true.
            getResolveRule.Conditions.Add(new Condition((Element)DoGetCurrent.GetVariable(), Operators.Equal, new V_True()));
            // Set the Current variable to the closest node.
            getResolveRule.ActionSet.AddAction(Current.SetVariable(ClosestNode(getResolveRule.ActionSet, PlayerPosition())));

            // If the OnPathStart hook is null, do the default which is throttling the player to the next node.
            if (OnPathStart == null)
            {
                // Start throttle to the current node.
                ThrottleEventPlayerToNextNode(getResolveRule.ActionSet);
            }
            // Otherwise, use the hook.
            else
            {
                OnPathStart.Invoke(getResolveRule.ActionSet);
            }

            // Update IsPathfindStuck data.
            UpdateStuckDetector(getResolveRule.ActionSet);

            // Reset DoGetCurrent to false.
            getResolveRule.ActionSet.AddAction(DoGetCurrent.SetVariable(new V_False()));

            // Add the rule.
            DeltinScript.WorkshopRules.Add(getResolveRule.GetRule());

            // Resolve the rule that increments the current node.

            // The 'next' rule will set current to the next node index when the current node is reached.
            TranslateRule next = new TranslateRule(DeltinScript, "Pathfinder: Resolve Next", RuleEvent.OngoingPlayer);

            next.Conditions.Add(NodeReachedCondition(next.ActionSet));
            next.Conditions.Add(new Condition(ParentArray.Get(), Operators.NotEqual, new V_Null()));

            if (OnPathCompleted == null || !OnPathCompleted.EmptyBlock)
            {
                next.ActionSet.AddAction(Element.Part <A_If>(new V_Compare(Current.Get(), Operators.NotEqual, new V_Number(-1))));
            }

            // Get last attribute.
            next.ActionSet.AddAction(CurrentAttribute.SetVariable(NextSegmentAttribute(new V_EventPlayer())));

            // Set current as the current's parent.
            next.ActionSet.AddAction(Current.SetVariable(ParentArray.Get()[Current.Get()] - 1));

            // Update stuck
            UpdateStuckDetector(next.ActionSet);

            // Invoke OnNodeReached
            OnNodeReached?.Invoke(next.ActionSet);

            if (OnPathCompleted == null || !OnPathCompleted.EmptyBlock)
            {
                next.ActionSet.AddAction(Element.Part <A_Else>());
            }

            if (OnPathCompleted == null)
            {
                next.ActionSet.AddAction(Element.Part <A_StopThrottleInDirection>(new V_EventPlayer()));
                StopPathfinding(next.ActionSet, new V_EventPlayer());
            }
            else if (!OnPathCompleted.EmptyBlock)
            {
                OnPathCompleted.Invoke(next.ActionSet);
            }

            if (OnPathCompleted == null || !OnPathCompleted.EmptyBlock)
            {
                next.ActionSet.AddAction(Element.Part <A_End>());
            }

            // Add rule
            DeltinScript.WorkshopRules.Add(next.GetRule());
        }