/// <summary>Starts pathfinding for the specified players/</summary>
        /// <param name="actionSet">The actionset of the current rule.</param>
        /// <param name="players">The players that will start pathfinding.</param>
        /// <param name="pathmapReference">A reference to the pathmap the players are pathfinding with.</param>
        /// <param name="parentArray">The parent array path.</param>
        /// <param name="attributeArray">The path attributes.</param>
        /// <param name="destination">The destination the players are navigating to.</param>
        public void Pathfind(ActionSet actionSet, Element players, Element pathmapReference, Element parentArray, Element attributeArray, Element destination)
        {
            // Set target's pathmap reference.
            actionSet.AddAction(PathmapReference.SetVariable(
                                    value: pathmapReference,
                                    targetPlayer: players
                                    ));

            // Set target's parent array.
            actionSet.AddAction(ParentArray.SetVariable(
                                    value: parentArray,
                                    targetPlayer: players
                                    ));

            // Set target's attribute array.
            actionSet.AddAction(AttributeArray.SetVariable(
                                    value: attributeArray,
                                    targetPlayer: players
                                    ));

            // Set target's destination.
            actionSet.AddAction(Destination.SetVariable(
                                    value: destination,
                                    targetPlayer: players
                                    ));

            // For each of the players, get the current.
            SetCurrent(actionSet, players);
        }
示例#2
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            Element effectArray    = (Element)parameterValues[0];
            double  destroyPerLoop = (double)additionalParameterData[1];

            ForeachBuilder foreachBuilder = new ForeachBuilder(actionSet, effectArray);

            for (int i = 0; i < destroyPerLoop; i++)
            {
                if (i == 0)
                {
                    actionSet.AddAction(
                        Element.Part <A_DestroyEffect>(foreachBuilder.IndexValue)
                        );
                }
                else
                {
                    actionSet.AddAction(
                        Element.Part <A_DestroyEffect>(Element.Part <V_ValueInArray>(effectArray, foreachBuilder.Index + i))
                        );
                }
            }

            foreachBuilder.Finish();

            return(null);
        }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            VariableElements elements = ((VariableResolve)additionalParameterData[0]).ParseElements(actionSet);
            WorkshopVariable variable = elements.IndexReference.WorkshopVariable;

            Element       destination  = (Element)parameterValues[1];
            Element       duration     = (Element)parameterValues[2];
            IWorkshopTree reevaluation = parameterValues[3];

            if (variable.IsGlobal)
            {
                actionSet.AddAction(Element.Part <A_ChaseGlobalVariableOverTime>(
                                        variable,
                                        destination,
                                        duration,
                                        reevaluation
                                        ));
            }
            else
            {
                actionSet.AddAction(Element.Part <A_ChasePlayerVariableOverTime>(
                                        elements.Target,
                                        variable,
                                        destination,
                                        duration,
                                        reevaluation
                                        ));
            }

            return(null);
        }
示例#4
0
        protected IWorkshopTree RenderModel(ActionSet actionSet, Model model, Element visibleTo, Element location, Element rotation, Element scale, IWorkshopTree reevaluation, bool getEffectIDs)
        {
            IndexReference effects = null;

            if (getEffectIDs)
            {
                effects = actionSet.VarCollection.Assign("_modelEffects", actionSet.IsGlobal, true);
                actionSet.AddAction(effects.SetVariable(new V_EmptyArray()));
            }

            for (int i = 0; i < model.Lines.Length; i++)
            {
                CreateLine(actionSet, model.Lines[i], visibleTo, location, rotation, scale, reevaluation);

                // Get the last created effect and append it to the store array.
                if (effects != null)
                {
                    actionSet.AddAction(effects.ModifyVariable(Operation.AppendToArray, new V_LastCreatedEntity()));
                }

                // Add a wait every 12 effects to prevent high server load.
                if (i % 10 == 0)
                {
                    actionSet.AddAction(A_Wait.MinimumWait);
                }
            }

            return(effects?.GetVariable());
        }
示例#5
0
        public void Build(ActionSet actionSet, Element compressedNodeArray, Action <Element> printProgress, ILambdaInvocable onLoop)
        {
            var matcher    = GetMatcher(actionSet);                                                                 // Get the character matcher.
            var nodeArray  = actionSet.VarCollection.Assign("compressedNodes", actionSet.IsGlobal, false);          // The index the node array is stored in.
            var nodeCount  = Element.CountOf(nodeArray.Get());                                                      // The number of nodes.
            var bakeResult = actionSet.VarCollection.Assign("compressBakeResult", true, false);                     // Assign the nodeResult.
            var compressCurrentNodeArray = actionSet.VarCollection.Assign("compressCurrentNodeArray", true, false); // Assign the nodeResult.

            nodeArray.Set(actionSet, compressedNodeArray);
            bakeResult.Set(actionSet, Element.EmptyArray()); // Initialize the nodeResult.

            // Loop through each node.
            var nodeArrayLoop = new ForBuilder(actionSet, "compressBakeNodeLoop", nodeCount);

            printProgress(nodeArrayLoop.Value / nodeCount); // Print the node count.
            nodeArrayLoop.Init();

            compressCurrentNodeArray.Set(actionSet, Element.EmptyArray());

            var currentStringArray = nodeArray.Get()[nodeArrayLoop.Value]; // The current string array.

            // Loop through each string.
            var stringArrayLoop = new ForBuilder(actionSet, "compressBakeStringLoop", Element.CountOf(currentStringArray));

            stringArrayLoop.Init();

            var currentString = currentStringArray[stringArrayLoop.Value]; // The current string.

            // Create an array with the length of the number of characters in the string.
            var mapper = actionSet.VarCollection.Assign("compressMapper", actionSet.IsGlobal, false);

            mapper.Set(actionSet, Element.EmptyArray());
            mapper.Set(actionSet, index: Element.StringLength(currentString) - 1, value: 0);

            actionSet.AddAction(compressCurrentNodeArray.ModifyVariable(
                                    operation: Operation.AppendToArray,
                                    value: Element.Map(
                                        mapper.Get(),
                                        Element.IndexOfArrayValue(
                                            matcher,
                                            Element.StringSlice(currentString, Element.ArrayIndex(), (Element)1)
                                            )
                                        )
                                    ));

            // Invoke onLoop.
            if (onLoop == null)
            {
                actionSet.AddAction(Element.Wait());
            }
            else
            {
                onLoop.Invoke(actionSet);
            }

            stringArrayLoop.End();
            actionSet.AddAction(bakeResult.SetVariable(index: nodeArrayLoop.Value, value: compressCurrentNodeArray.Get()));
            nodeArrayLoop.End();
            Result = bakeResult.Get();
        }
 /// <summary>Updates stuck detector.</summary>
 private void UpdateStuckDetector(ActionSet actionSet)
 {
     if (!TrackTimeSinceLastNode)
     {
         return;                          // Do nothing if TrackTimeSinceLastNode is set to false.
     }
     actionSet.AddAction(TimeSinceLastNode.SetVariable(new V_TotalTimeElapsed()));
     actionSet.AddAction(DistanceToNextNode.SetVariable(Element.Part <V_DistanceBetween>(Element.Part <V_PositionOf>(new V_EventPlayer()), CurrentPositionWithDestination())));
 }
示例#7
0
 /// <summary>Updates stuck detector.</summary>
 private void UpdateStuckDetector(ActionSet actionSet, Element player)
 {
     if (!TrackTimeSinceLastNode)
     {
         return;                          // Do nothing if TrackTimeSinceLastNode is set to false.
     }
     actionSet.AddAction(TimeSinceLastNode.SetVariable(Part("Total Time Elapsed"), targetPlayer: player));
     actionSet.AddAction(DistanceToNextNode.SetVariable(DistanceBetween(PositionOf(player), CurrentPositionWithDestination(player)), targetPlayer: player));
 }
示例#8
0
        public override IWorkshopTree New(ActionSet actionSet, Constructor constructor, IWorkshopTree[] constructorValues, object[] additionalParameterData)
        {
            // Create the class.
            var objectData = actionSet.Translate.DeltinScript.SetupClasses().CreateObject(actionSet, "_new_PathMap");

            // Get the pathmap data.
            PathMap pathMap = (PathMap)additionalParameterData[0];

            actionSet.AddAction(objectData.ClassObject.SetVariable(pathMap.NodesAsWorkshopData(), null, 0));
            actionSet.AddAction(objectData.ClassObject.SetVariable(pathMap.SegmentsAsWorkshopData(), null, 1));

            return(objectData.ClassReference.GetVariable());
        }
 void IPathfinderInfo.OnLoop()
 {
     if (_onLoop == null)
     {
         ActionSet.AddAction(_bakeWait.ModifyVariable(Operation.Add, 1));
         ActionSet.AddAction(SkipIf(_bakeWait.Get() % 6, Num(1)));
         ActionSet.AddAction(Wait());
     }
     else
     {
         _onLoop.Invoke(ActionSet);
     }
 }
        protected override void New(ActionSet actionSet, NewClassInfo newClassInfo)
        {
            Element index = (Element)newClassInfo.ObjectReference.GetVariable();

            if (newClassInfo.AdditionalParameterData.Length > 0)
            {
                // Get the pathmap data.
                PathMap pathMap = (PathMap)newClassInfo.AdditionalParameterData[0];

                IndexReference nodes    = actionSet.VarCollection.Assign("_tempNodes", actionSet.IsGlobal, false);
                IndexReference segments = actionSet.VarCollection.Assign("_tempSegments", actionSet.IsGlobal, false);

                actionSet.AddAction(nodes.SetVariable(new V_EmptyArray()));
                actionSet.AddAction(segments.SetVariable(new V_EmptyArray()));

                foreach (var node in pathMap.Nodes)
                {
                    actionSet.AddAction(nodes.ModifyVariable(operation: Operation.AppendToArray, value: node.ToVector()));
                }
                foreach (var segment in pathMap.Segments)
                {
                    actionSet.AddAction(segments.ModifyVariable(operation: Operation.AppendToArray, value: segment.AsWorkshopData()));
                }

                actionSet.AddAction(Nodes.SetVariable((Element)nodes.GetVariable(), index: index));
                actionSet.AddAction(Segments.SetVariable((Element)segments.GetVariable(), index: index));
            }
            else
            {
                actionSet.AddAction(Nodes.SetVariable(new V_EmptyArray(), index: index));
                actionSet.AddAction(Segments.SetVariable(new V_EmptyArray(), index: index));
            }
        }
        protected override void New(ActionSet actionSet, NewClassInfo newClassInfo)
        {
            // Get the pathmap data.
            PathMap pathMap = (PathMap)newClassInfo.AdditionalParameterData[0];

            actionSet.AddAction(Nodes.SetVariable(
                                    value: pathMap.NodesAsWorkshopData(),
                                    index: (Element)newClassInfo.ObjectReference.GetVariable()
                                    ));
            actionSet.AddAction(Segments.SetVariable(
                                    value: pathMap.SegmentsAsWorkshopData(),
                                    index: (Element)newClassInfo.ObjectReference.GetVariable()
                                    ));
        }
示例#12
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            if (parameterValues[0] is V_Number n)
            {
                V_Number[] indexes = new V_Number[n.Value < 0 ? 0 : (int)n.Value];
                for (int i = 0; i < indexes.Length; i++)
                {
                    indexes[i] = new V_Number(i);
                }
                return(Element.CreateArray(indexes));
            }
            else
            {
                IndexReference array  = actionSet.VarCollection.Assign("_foreachArrayBuilder", actionSet.IsGlobal, false);
                IndexReference length = actionSet.VarCollection.Assign("_foreachArrayBuilderLength", actionSet.IsGlobal, true);
                IndexReference i      = actionSet.VarCollection.Assign("_foreachArrayBuilderIndex", actionSet.IsGlobal, true);

                actionSet.AddAction(ArrayBuilder <Element> .Build(
                                        length.SetVariable((Element)parameterValues[0]),
                                        array.SetVariable(new V_EmptyArray()),
                                        i.SetVariable(0),
                                        Element.Part <A_While>((Element)i.GetVariable() < (Element)length.GetVariable()),
                                        array.SetVariable((Element)i.GetVariable(), null, (Element)i.GetVariable()),
                                        i.ModifyVariable(Operation.Add, 1),
                                        new A_End()
                                        ));

                return(array.GetVariable());
            }
        }
示例#13
0
        public void ParseInner(ActionSet actionSet)
        {
            // Create a new contained action set.
            actionSet = actionSet.New(actionSet.IndexAssigner.CreateContained());

            var infoSaver = actionSet.VarCollection.Assign("funcSaver", true, false);

            actionSet.AddAction(infoSaver.SetVariable((Element)actionSet.CurrentObject));

            actionSet = actionSet.New(infoSaver.Get());

            // Add the contained variables.
            for (int i = 0; i < _lambda.CapturedVariables.Count; i++)
            {
                actionSet.IndexAssigner.Add(_lambda.CapturedVariables[i], infoSaver.CreateChild(i + 2));
            }

            if (_lambda.Expression != null)
            {
                actionSet.ReturnHandler.ReturnValue(_lambda.Expression.Parse(actionSet));
            }
            else
            {
                _lambda.Statement.Translate(actionSet);
            }
        }
示例#14
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            // Setup the continue skip.
            ContinueSkip continueSkip = actionSet.ContinueSkip;

            continueSkip.Setup(actionSet);

            IndexReference result = actionSet.VarCollection.Assign($"_conditionTestResult", actionSet.IsGlobal, true);

            continueSkip.SetSkipCount(actionSet, continueSkip.GetSkipCount(actionSet) + 3);
            actionSet.AddAction(ArrayBuilder <Element> .Build(
                                    // This will continue at (0) if the rule loops.
                                    new A_LoopIfConditionIsFalse(),
                                    // Set the result to true.
                                    result.SetVariable(new V_True()),
                                    Element.Part <A_Skip>(new V_Number(1)),

                                    // The rule will loop back here (0) if false.
                                    result.SetVariable(new V_False())
                                    ));
            continueSkip.ResetSkipCount(actionSet);

            if (TestingIfTrue)
            {
                return(result.GetVariable());
            }
            else
            {
                return(Element.Part <V_Not>(result.GetVariable()));
            }
        }
 public static void Pathfind(ActionSet actionSet, PathfinderInfo info, Element pathResult, Element target, Element destination)
 {
     actionSet.AddAction(info.Path.SetVariable(
                             Element.Part <V_Append>(pathResult, destination),
                             target
                             ));
 }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            VariableElements elements = ((VariableResolve)additionalParameterData[0]).ParseElements(actionSet);
            WorkshopVariable variable = elements.IndexReference.WorkshopVariable;

            if (variable.IsGlobal)
            {
                actionSet.AddAction(Element.Part <A_StopChasingGlobalVariable>(variable));
            }
            else
            {
                actionSet.AddAction(Element.Part <A_StopChasingPlayerVariable>(elements.Target, variable));
            }

            return(null);
        }
        private static Element ContainParameter(ActionSet actionSet, string name, IWorkshopTree value)
        {
            IndexReference containParameter = actionSet.VarCollection.Assign(name, actionSet.IsGlobal, true);

            actionSet.AddAction(containParameter.SetVariable((Element)value));
            return((Element)containParameter.GetVariable());
        }
        public IWorkshopTree Call(ICallInfo call)
        {
            // Get the subroutine.
            _subroutine = Controller.GetSubroutine();
            if (_subroutine)
            {
                ParameterHandler = _subroutine.ParameterHandler;
                SetParameters(call);

                // Store the object the subroutine is executing with.
                if (Controller.Attributes.IsInstance)
                {
                    // Normal
                    if (!Controller.Attributes.IsRecursive)
                    {
                        ActionSet.AddAction(_subroutine.ObjectStack.SetVariable((Element)ActionSet.CurrentObject));
                    }
                    // Recursive: Stack
                    else
                    {
                        ActionSet.AddAction(_subroutine.ObjectStack.ModifyVariable(Operation.AppendToArray, Element.CreateArray(ActionSet.CurrentObject)));
                    }
                }

                call.ExecuteSubroutine(ActionSet, _subroutine.Subroutine);

                // If a return handler was provided, bridge the return value.
                if (call.ProvidedReturnHandler != null && _subroutine.ReturnHandler != null)
                {
                    call.ProvidedReturnHandler.ReturnValue(_subroutine.ReturnHandler.GetReturnedValue());
                }

                return(_subroutine.ReturnHandler?.GetReturnedValue());
            }
            else
            {
                // Inline
                // Recursive stack.
                if (Controller.Attributes.IsRecursive)
                {
                    var lastCall = GetExistingStack();

                    // Function is not yet on the stack.
                    if (lastCall == null)
                    {
                        return(BuildInline(call));
                    }
                    else // Recursive call.
                    {
                        lastCall.RecursiveCall(call, ActionSet);
                        return(ActionSet.ReturnHandler.GetReturnedValue());
                    }
                }
                else
                {
                    return(BuildInline(call));
                }
            }
        }
        public static void Execute(ActionSet actionSet, Subroutine subroutine, CallParallel callParallel = CallParallel.NoParallel)
        {
            switch (callParallel)
            {
            case CallParallel.NoParallel:
                actionSet.AddAction(Element.CallSubroutine(subroutine));
                break;

            case CallParallel.AlreadyRunning_DoNothing:
                actionSet.AddAction(Element.StartRule(subroutine, false));
                break;

            case CallParallel.AlreadyRunning_RestartRule:
                actionSet.AddAction(Element.StartRule(subroutine, true));
                break;
            }
        }
 public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
 {
     actionSet.AddAction(actionSet.Translate.DeltinScript.SetupPathfinder().Path.SetVariable(
                             (Element)parameterValues[1],
                             (Element)parameterValues[0]
                             ));
     return(null);
 }
        public override void Finished()
        {
            SkipEndMarker endLoop = new SkipEndMarker();

            ActionSet.AddAction(endLoop);
            _playerNodeReachedBreak.SetEndMarker(endLoop);

            ResolveInfo.Pathfind(ActionSet, _player, PathmapObject, Builder.ParentArray.Get(), _destination);
        }
示例#22
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            if (parameterValues[0] is V_Array ar)
            {
                if (ar.ParameterValues.All(element => element is V_Number))
                {
                    return(new V_Number(ar.ParameterValues.Average(element => ((V_Number)element).Value)));
                }
                else if (ar.ParameterValues.All(element => ((Element)element).ConstantSupported <Vertex>()))
                {
                    Vertex sum_ = new Vertex();
                    foreach (IWorkshopTree vert in ar.ParameterValues)
                    {
                        sum_ += (Vertex)((Element)vert).GetConstant();
                    }
                    return((sum_ / ar.ParameterValues.Length).ToVector());
                }
                else
                {
                    Element sum_ = (Element)ar.ParameterValues[0];
                    for (int i = 1; i < ar.ParameterValues.Length; i++)
                    {
                        sum_ += (Element)ar.ParameterValues[i];
                    }
                    return(sum_ / ar.ParameterValues.Length);
                }
            }
            else if (parameterValues[0] is V_EmptyArray)
            {
                return(new V_Number(0));
            }
            else
            {
                IndexReference array = actionSet.VarCollection.Assign("_arrayToAverage", actionSet.IsGlobal, true);
                IndexReference sum   = actionSet.VarCollection.Assign("_sumOfAverageArray", actionSet.IsGlobal, true);

                actionSet.AddAction(array.SetVariable((Element)parameterValues[0]));
                actionSet.AddAction(sum.SetVariable(0));
                ForeachBuilder builder = new ForeachBuilder(actionSet, array.GetVariable());
                actionSet.AddAction(sum.ModifyVariable(Operation.Add, builder.IndexValue));
                builder.Finish();
                return((Element)sum.GetVariable() / Element.Part <V_CountOf>(array.GetVariable()));
            }
        }
 public override void OnLoopEnd()
 {
     // Break out of the while loop when the current node is the closest node to the player.
     _playerNodeReachedBreak = new SkipStartMarker(ActionSet, Compare(
                                                       NodeFromPosition(PositionOf(_player)),
                                                       Operator.NotEqual,
                                                       Builder.Current.GetVariable()
                                                       ));
     ActionSet.AddAction(_playerNodeReachedBreak);
 }
 public void OnLoop()
 {
     if (_onLoop == null)
     {
         ActionSet.AddAction(Wait());
     }
     else
     {
         _onLoop.Invoke(ActionSet);
     }
 }
示例#25
0
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues, object[] additionalParameterData)
        {
            CallVariableAction callVariable   = (CallVariableAction)additionalParameterData[0];
            IndexReference     indexReference = (IndexReference)actionSet.IndexAssigner[callVariable.Calling];

            Operation operation = (Operation)((EnumMember)parameterValues[1]).Value;
            Element   value     = (Element)parameterValues[2];

            actionSet.AddAction(indexReference.ModifyVariable(operation, value, null, callVariable.ParseIndex(actionSet)));
            return(null);
        }
示例#26
0
 public void Push(ActionSet actionSet, IWorkshopTree value)
 {
     if (Gettable is RecursiveIndexReference recursive)
     {
         actionSet.AddAction(recursive.Push((Element)value));
     }
     else
     {
         throw new Exception("Cannot push non-recursive parameter");
     }
 }
示例#27
0
 public void Pop(ActionSet actionSet)
 {
     if (Gettable is RecursiveIndexReference recursive)
     {
         actionSet.AddAction(recursive.Pop());
     }
     else
     {
         throw new Exception("Cannot pop non-recursive parameter");
     }
 }
        public override IWorkshopTree Get(ActionSet actionSet, IWorkshopTree[] parameterValues)
        {
            Element player = (Element)parameterValues[0];

            actionSet.AddAction(Element.Part <A_Teleport>(
                                    player,
                                    actionSet.Translate.DeltinScript.SetupPathfinder().NextPosition(player)
                                    ));

            return(null);
        }
        private static void SetInitialUnvisited(ActionSet actionSet, Element nodeArray, IndexReference unvisitedVar)
        {
            // Create an array counting up to the number of values in the nodeArray array.
            // For example, if nodeArray has 6 variables unvisitedVar will be set to [0, 1, 2, 3, 4, 5].

            // Empty the unvisited array.
            actionSet.AddAction(unvisitedVar.SetVariable(new V_EmptyArray()));

            IndexReference current = actionSet.VarCollection.Assign("unvisitedBuilder", actionSet.IsGlobal, true);

            actionSet.AddAction(current.SetVariable(0));

            WhileBuilder unvisitedBuilder = new WhileBuilder(actionSet, (Element)current.GetVariable() < Element.Part <V_CountOf>(nodeArray));

            unvisitedBuilder.Setup();

            actionSet.AddAction(unvisitedVar.ModifyVariable(Operation.AppendToArray, (Element)current.GetVariable()));

            actionSet.AddAction(current.ModifyVariable(Operation.Add, 1));
            unvisitedBuilder.Finish();
        }
        protected override void Init()
        {
            // Assign an array that will be used to store the closest node to each player.
            _closestNodesToPlayers = ActionSet.VarCollection.Assign("Dijkstra: Closest nodes", ActionSet.IsGlobal, false);
            ActionSet.AddAction(_closestNodesToPlayers.SetVariable(EmptyArray()));

            // Loop through each player and get the closest node.
            ForeachBuilder getClosestNodes = new ForeachBuilder(ActionSet, _players);

            ActionSet.AddAction(_closestNodesToPlayers.ModifyVariable(Operation.AppendToArray, NodeFromPosition(getClosestNodes.IndexValue)));
            getClosestNodes.Finish();
        }