示例#1
0
        public CodegenExpression MakeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(ContextControllerDetailInitiatedTerminated), GetType(), classScope);

            method.Block
                .DeclareVar<ContextControllerDetailInitiatedTerminated>(
                    "detail",
                    NewInstance(typeof(ContextControllerDetailInitiatedTerminated)))
                .SetProperty(Ref("detail"), "StartCondition", StartCondition.Make(method, symbols, classScope))
                .SetProperty(Ref("detail"), "EndCondition", EndCondition.Make(method, symbols, classScope))
                .SetProperty(Ref("detail"), "IsOverlapping", Constant(IsOverlapping));
            if (DistinctExpressions != null && DistinctExpressions.Length > 0) {
                method.Block
                    .SetProperty(
                        Ref("detail"),
                        "DistinctEval",
                        ExprNodeUtilityCodegen.CodegenEvaluatorMayMultiKeyWCoerce(
                            ExprNodeUtilityQuery.GetForges(DistinctExpressions),
                            null,
                            method,
                            GetType(),
                            classScope))
                    .SetProperty(
                        Ref("detail"),
                        "DistinctTypes",
                        Constant(ExprNodeUtilityQuery.GetExprResultTypes(DistinctExpressions)));
            }

            method.Block.MethodReturn(Ref("detail"));
            return LocalMethod(method);
        }
示例#2
0
        public static Quest GetCopy(Quest q)
        {
            var copy = new Quest
            {
                QuestSize       = q.QuestSize,
                ID              = q.ID,
                Title           = Title.GetCopy(q.Title),
                Description     = Description.GetCopy(q.Description),
                Region          = q.Region,
                QuestType       = q.QuestType,
                IsRepeatAble    = q.IsRepeatAble,
                IsDailyQuest    = q.IsDailyQuest,
                DailyType       = q.DailyType,
                StartCondition  = StartCondition.GetCopy(q.StartCondition),
                EndCondition    = EndCondition.GetCopy(q.EndCondition),
                NumOfActions    = q.NumOfActions,
                Actions         = new Action[10],
                Rewards         = new Reward[12],
                StartScriptSize = q.StartScriptSize,
                DoingScriptSize = q.DoingScriptSize,
                EndScriptSize   = q.EndScriptSize,
                Unk1            = new byte[14],
                StartScript     = string.Copy(q.StartScript),
                DoingScript     = string.Copy(q.DoingScript),
                EndScript       = string.Copy(q.EndScript)
            };

            Array.Copy(q.Actions, 0, copy.Actions, 0, q.Actions.Length);
            Array.Copy(q.Rewards, 0, copy.Rewards, 0, q.Rewards.Length);
            Array.Copy(q.Unk1, 0, copy.Unk1, 0, q.Unk1.Length);

            return(copy);
        }
示例#3
0
        public IEnumerable <Step> GetNextSteps(StartCondition startCondition)
        {
            var validSteps = from s in Steps
                             where (s.StartCondition == StartCondition.Any || s.StartCondition == startCondition) &&
                             s.GetStatus() == Status.None
                             select s;

            var queue = new Queue <Step>(validSteps);

            if (!queue.Any())
            {
                yield break;
            }

            yield return(queue.Dequeue());

            while (queue.Any())
            {
                var next = queue.Dequeue();
                if (next.StartTrigger != StartTrigger.StartParallelPrevious)
                {
                    yield break;
                }
                yield return(next);
            }
        }
示例#4
0
        public Quest(BinaryReader reader)
        {
            QuestSize = reader.ReadUInt32() - 4;
            ID        = reader.ReadUInt32();
            if (ID > HighestID)
            {
                HighestID = ID;
            }
            var titleID = reader.ReadUInt32();

            Title = new Title(titleID, "");
            var descriptionID = reader.ReadUInt32();

            Description = new Description(descriptionID, "");

            //TODO: Figure out what this is
            Region = reader.ReadByte();

            QuestType    = (QuestType)reader.ReadByte();
            IsRepeatAble = reader.ReadBoolean();
            IsDailyQuest = reader.ReadBoolean();
            DailyType    = (DailyType)reader.ReadByte();

            StartCondition = new StartCondition(reader);
            EndCondition   = new EndCondition(reader);

            NumOfActions = (byte)reader.ReadInt32();

            Actions = new Action[10];
            for (var i = 0; i < 10; i++)
            {
                Actions[i] = new Action(reader);
            }

            Rewards = new Reward[12];
            for (var i = 0; i < 12; i++)
            {
                Rewards[i] = new Reward(reader);
            }

            StartScriptSize = reader.ReadUInt16();
            EndScriptSize   = reader.ReadUInt16();
            DoingScriptSize = reader.ReadUInt16();

            Unk1 = new byte[14];
            Unk1 = reader.ReadBytes(14);

            StartScript = Encoding.ASCII.GetString(reader.ReadBytes(StartScriptSize));
            DoingScript = Encoding.ASCII.GetString(reader.ReadBytes(DoingScriptSize));
            EndScript   = Encoding.ASCII.GetString(reader.ReadBytes(EndScriptSize));
        }
        private void LoadSettings()
        {
            var options = new JsonSerializerOptions
            {
                Converters =
                {
                    new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, true)
                },
                AllowTrailingCommas = true
            };

            //TODO: Make this real Settings
            var jsonConfig              = File.ReadAllText("Components\\GW2SAB\\gw2sab_config.json");
            var rawConfig               = JsonSerializer.Deserialize <Dictionary <string, string> >(jsonConfig, options);
            var rawLoadingScreen        = rawConfig.GetValueOrDefault("LoadingScreens", "Include");
            var rawStartCondition       = rawConfig.GetValueOrDefault("StartCondition", "Moving");
            var rawPauseOnExit          = rawConfig.GetValueOrDefault("PauseOnExit", "true");
            var rawMaxSkippedTicks      = rawConfig.GetValueOrDefault("MaxSkippedTicks", "3");
            var rawBlackBarSize         = rawConfig.GetValueOrDefault("BlackBarSize", "0.1");
            var rawBlackPixelPercentage = rawConfig.GetValueOrDefault("BlackPixelPercentage", "0.8");

            if (!Enum.TryParse(rawLoadingScreen, true, out _loadingScreen))
            {
                _loadingScreen = LoadingScreen.Include;
            }

            if (!Enum.TryParse(rawStartCondition, true, out _startCondition))
            {
                _startCondition = StartCondition.Moving;
            }

            if (!bool.TryParse(rawPauseOnExit, out _pauseOnExit))
            {
                _pauseOnExit = true;
            }

            if (!int.TryParse(rawMaxSkippedTicks, out _maxSkippedTicks))
            {
                _maxSkippedTicks = 3;
            }

            if (!double.TryParse(rawBlackBarSize, out _blackBarSize))
            {
                _blackBarSize = 0.1f;
            }

            if (!double.TryParse(rawBlackPixelPercentage, out _blackPixelPercentage))
            {
                _blackPixelPercentage = 0.8f;
            }
        }
示例#6
0
        public virtual async Task Run(T device)
        {
            while (!StartCondition.Invoke(device))
            {
                await Task.Delay(100);
            }

            Routine(device);

            while (!StopCondition.Invoke(device))
            {
                await Task.Delay(100);
            }
        }
 public void ToEPL(TextWriter writer, EPStatementFormatter formatter)
 {
     writer.Write(IsOverlapping ? "initiated by " : "start ");
     if (_optionalDistinctExpressions != null && _optionalDistinctExpressions.Count > 0)
     {
         writer.Write("distinct(");
         String delimiter = "";
         foreach (Expression expression in _optionalDistinctExpressions)
         {
             writer.Write(delimiter);
             expression.ToEPL(writer, ExpressionPrecedenceEnum.MINIMUM);
             delimiter = ", ";
         }
         writer.Write(") ");
     }
     StartCondition.ToEPL(writer, formatter);
     writer.Write(" ");
     writer.Write(IsOverlapping ? "terminated " : "end ");
     EndCondition.ToEPL(writer, formatter);
 }
        /// <summary>
        /// Play all actions and check if the event can end up or not
        /// </summary>
        public void PlayEvent(GameTime gameTime)
        {
            //Check for start condition
            if (StartCondition != null)
            {
                StartCondition.Run(gameTime, ScrollValue);
                //Condition not satisfied : do not launch event's actions
                if (!StartCondition.IsEnded)
                {
                    return;
                }
            }

            //Launch actions
            List <Command> commandsToDelete = new List <Command>();

            foreach (Command c in Commands)
            {
                c.Run(gameTime, ScrollValue);

                if (c.IsEnded)
                {
                    commandsToDelete.Add(c);
                }
                else
                {
                    break;  //Do not execute more commands if you didn't finish this one. This is useful for a if or wait
                }
            }

            foreach (Command cd in commandsToDelete)
            {
                Commands.Remove(cd);
            }

            //No more actions
            if (Commands.Count == 0)
            {
                IsEnded = true;
            }
        }
示例#9
0
        public void Save(BinaryWriter writer)
        {
            writer.Write(QuestSize + 4);
            writer.Write(ID);
            writer.Write(Title.ID);
            writer.Write(Description.ID);
            writer.Write(Region);
            writer.Write((byte)QuestType);
            writer.Write(IsRepeatAble);
            writer.Write(IsDailyQuest);
            writer.Write((byte)DailyType);

            StartCondition.Save(writer);
            EndCondition.Save(writer);

            writer.Write((int)NumOfActions);

            for (int i = 0; i < 10; i++)
            {
                Actions[i].Save(writer);
            }

            for (int i = 0; i < 12; i++)
            {
                Rewards[i].Save(writer);
            }

            writer.Write(StartScriptSize);
            writer.Write(EndScriptSize);
            writer.Write(DoingScriptSize);

            writer.Write(Unk1);

            writer.Write(GetBytes(StartScript, StartScriptSize));
            writer.Write(GetBytes(DoingScript, DoingScriptSize));
            writer.Write(GetBytes(EndScript, EndScriptSize));
        }
示例#10
0
        public CodegenExpression MakeCodegen(
            CodegenMethodScope parent,
            SAIFFInitializeSymbol symbols,
            CodegenClassScope classScope)
        {
            var method = parent.MakeChild(typeof(ContextControllerDetailInitiatedTerminated), GetType(), classScope);

            var distinctEval = MultiKeyCodegen.CodegenExprEvaluatorMayMultikey(
                DistinctExpressions, null, DistinctMultiKey, method, classScope);

            method.Block
                .DeclareVar<ContextControllerDetailInitiatedTerminated>(
                    "detail",
                    NewInstance(typeof(ContextControllerDetailInitiatedTerminated)))
                .SetProperty(Ref("detail"), "StartCondition", StartCondition.Make(method, symbols, classScope))
                .SetProperty(Ref("detail"), "EndCondition", EndCondition.Make(method, symbols, classScope))
                .SetProperty(Ref("detail"), "IsOverlapping", Constant(IsOverlapping))
                .SetProperty(Ref("detail"), "DistinctEval", distinctEval)
                .SetProperty(Ref("detail"), "DistinctTypes", DistinctExpressions == null ? ConstantNull() : Constant(ExprNodeUtilityQuery.GetExprResultTypes(DistinctExpressions)))
                .SetProperty(Ref("detail"), "DistinctSerde", DistinctMultiKey == null ? ConstantNull() : DistinctMultiKey.GetExprMKSerde(method, classScope));

            method.Block.MethodReturn(Ref("detail"));
            return LocalMethod(method);
        }
示例#11
0
        public PropertyGraphModel Calculate(PropertyGraphModel graph)
        {
            if (graph?.Vertices == null || graph.Vertices.Count == 0 ||
                graph?.Edges == null || graph.Edges.Count == 0)
            {
                return(graph);
            }

            var nodes = graph.Vertices.Count;

            var stack = new Stack <int>();
            var paths = new List <int> [nodes];

            for (var v = 0; v < nodes; v++)
            {
                paths[v] = new List <int>();
            }

            var distances = new Dictionary <int, double>();
            var seen      = new Dictionary <int, double>();
            var queue     = new SimplePriorityQueue <Path, double>();

            // start nodes
            for (var start = 0; start < nodes; start++)
            {
                if (StartCondition.Evaluate(graph.Vertices[start], null))
                {
                    queue.Enqueue(new Path()
                    {
                        Dist = 0, Start = start, End = start
                    }, 0);
                    seen.Add(start, 0);
                }
            }

            while (queue.Count > 0)
            {
                var path   = queue.Dequeue();
                var dist   = path.Dist;
                var vertex = path.End;

                if (distances.ContainsKey(vertex))
                {
                    continue;                                // already searched this node
                }
                stack.Push(vertex);
                distances[vertex] = dist;

                foreach (var edge in graph.Vertices[vertex].Edges)
                {
                    var target = edge.Target;
                    if (edge.Target == vertex)
                    {
                        if (DirectedGraph)
                        {
                            continue;
                        }
                        else
                        {
                            target = edge.Source;
                        }
                    }

                    if (EdgeCondition != null && !EdgeCondition.Evaluate(null, edge))
                    {
                        continue;
                    }

                    double weight = 1.0;
                    if (LengthPropIdentifier != null)
                    {
                        weight = Convert.ToDouble(LengthPropIdentifier.Evaluate(null, edge) ?? 1.0);
                    }


                    var edgeDist = distances[vertex] + weight;
                    if (!(distances.ContainsKey(target)) && (!(seen.ContainsKey(target)) || edgeDist < seen[target]))
                    {
                        seen[target] = edgeDist;
                        queue.Enqueue(new Path()
                        {
                            Dist = edgeDist, Start = vertex, End = target
                        }, edgeDist);
                        paths[target] = new List <int>()
                        {
                            vertex
                        };
                    }
                    else if (Math.Abs(edgeDist - seen[target]) < 0.001)
                    {
                        // handle equal paths
                        paths[target].Add(vertex);
                    }
                }
            }

            for (int i = 0; i < nodes; i++)
            {
                double dist;
                if (distances.TryGetValue(i, out dist))
                {
                    if (graph.Vertices[i].Props == null)
                    {
                        graph.Vertices[i].Props = new Dictionary <string, object>();
                    }
                    graph.Vertices[i].Props["pathLength"] = dist;
                    if (paths[i].Count > 0)
                    {
                        graph.Vertices[i].Props["pathNext"] = paths[i];
                    }
                }
            }
            return(graph);
        }