Beispiel #1
0
        public static Quest Generate(QuestScriptDef root, Slate initialVars)
        {
            if (DeepProfiler.enabled)
            {
                DeepProfiler.Start("Generate quest");
            }
            Quest result = null;

            try
            {
                if (working)
                {
                    throw new Exception("Called Generate() while already working.");
                }
                working       = true;
                QuestGen.root = root;
                slate.Reset();
                slate.SetAll(initialVars);
                quest = Quest.MakeRaw();
                quest.ticksUntilAcceptanceExpiry = (int)(root.expireDaysRange.RandomInRange * 60000f);
                if (root.defaultChallengeRating > 0)
                {
                    quest.challengeRating = root.defaultChallengeRating;
                }
                quest.root   = root;
                quest.hidden = root.defaultHidden;
                slate.SetIfNone("inSignal", quest.InitiateSignal);
                root.Run();
                try
                {
                    QuestNode_ResolveQuestName.Resolve();
                }
                catch (Exception arg)
                {
                    Log.Error("Error while generating quest name: " + arg);
                }
                try
                {
                    QuestNode_ResolveQuestDescription.Resolve();
                }
                catch (Exception arg2)
                {
                    Log.Error("Error while generating quest description: " + arg2);
                }
                try
                {
                    QuestNode_ResolveTextRequests.Resolve();
                }
                catch (Exception arg3)
                {
                    Log.Error("Error while resolving text requests: " + arg3);
                }
                AddSlateQuestTags();
                bool flag = root.autoAccept;
                if (flag)
                {
                    List <QuestPart> partsListForReading = quest.PartsListForReading;
                    for (int i = 0; i < partsListForReading.Count; i++)
                    {
                        if (partsListForReading[i].PreventsAutoAccept)
                        {
                            flag = false;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    quest.SetInitiallyAccepted();
                }
                result = quest;
                return(result);
            }
            catch (Exception arg4)
            {
                Log.Error("Error in QuestGen: " + arg4);
                return(result);
            }
            finally
            {
                if (DeepProfiler.enabled)
                {
                    DeepProfiler.End();
                }
                quest         = null;
                QuestGen.root = null;
                working       = false;
                generatedPawns.Clear();
                textRequests.Clear();
                slate.Reset();
                questDescriptionRules.Clear();
                questDescriptionConstants.Clear();
                questNameRules.Clear();
                questNameConstants.Clear();
                questContentRules.Clear();
                slateQuestTagsToAddWhenFinished.Clear();
                ResetIdCounters();
            }
        }