Example #1
0
    public static List <Quest> GenerateQuests(Campaign campaign, int seed = 0)
    {
        if (seed != 0)
        {
            Random.InitState(seed);
        }

        QuestDatabase       questData = DarkestDungeonManager.Data.QuestDatabase;
        QuestGenerationData genData   = questData.QuestGeneration;

        QuestGenerationInfo questGenerationInfo = GetQuestInfo(genData, campaign);

        DistributeQuests(questGenerationInfo, genData, campaign);
        DistributeQuestTypes(questGenerationInfo, questData);
        DistributeQuestGoals(questGenerationInfo, questData);
        DistributeQuestRewards(questGenerationInfo, questData);

        List <Quest> generatedQuests = new List <Quest>();

        foreach (var info in questGenerationInfo.dungeonQuests)
        {
            foreach (var quest in info.Quests)
            {
                generatedQuests.Add(quest);
            }
        }

        return(generatedQuests);
    }
Example #2
0
    static QuestGenerationInfo GetQuestInfo(QuestGenerationData genData, Campaign campaign)
    {
        QuestGenerationInfo questInfo = new QuestGenerationInfo();

        foreach (var dungeon in genData.Dungeons.Values)
        {
            if (dungeon.RequiredQuestsCompleted <= campaign.QuestsComleted)
            {
                DungeonQuestInfo dungeonInfo = new DungeonQuestInfo();
                dungeonInfo.Dungeon        = dungeon.Id;
                dungeonInfo.GeneratedTypes = genData.QuestTypes[dungeonInfo.Dungeon].
                                             QuestTypeSets[campaign.Dungeons[dungeon.Id].MasteryLevel];
                questInfo.dungeonQuests.Add(dungeonInfo);
            }
        }
        questInfo.dungeonCount  = questInfo.dungeonQuests.Count;
        questInfo.maxPerDungeon = genData.MaxQuestsPerDungeon;
        questInfo.questCount    = GetQuestNumber(genData, campaign);
        return(questInfo);
    }
Example #3
0
    static int GetQuestNumber(QuestGenerationData genData, Campaign campaign)
    {
        int questNumberState = 0;

        if (campaign.QuestsComleted <= 2)
        {
            questNumberState = 0;
        }
        else if (campaign.QuestsComleted <= 3)
        {
            questNumberState = 1;
        }
        else if (campaign.QuestsComleted <= 4)
        {
            questNumberState = 2;
        }
        else if (campaign.QuestsComleted <= 6)
        {
            questNumberState = 3;
        }
        else if (campaign.QuestsComleted <= 10)
        {
            questNumberState = 4;
        }
        else if (campaign.QuestsComleted <= 16)
        {
            questNumberState = 5;
        }
        else if (campaign.QuestsComleted <= 20)
        {
            questNumberState = 6;
        }
        else
        {
            questNumberState = 7;
        }
        return(genData.QuestsPerVisit[questNumberState]);
    }
Example #4
0
    static void DistributeQuests(QuestGenerationInfo questInfo, QuestGenerationData genData, Campaign campaign)
    {
        if (questInfo.dungeonCount * questInfo.maxPerDungeon < questInfo.questCount)
        {
            questInfo.questCount = questInfo.dungeonCount * questInfo.maxPerDungeon;
        }
        if (questInfo.dungeonCount > questInfo.questCount)
        {
            questInfo.questCount = questInfo.dungeonCount;
        }

        int questsLeft = questInfo.questCount;

        float difOneAvailable = campaign.Heroes.FindAll(hero =>
                                                        genData.Difficulties[0].ResolveLevels.Contains(hero.Resolve.Level)).Count;
        float difTwoAvailable = campaign.Heroes.FindAll(hero =>
                                                        genData.Difficulties[1].ResolveLevels.Contains(hero.Resolve.Level)).Count;
        float difThreeAvailable = campaign.Heroes.FindAll(hero =>
                                                          genData.Difficulties[2].ResolveLevels.Contains(hero.Resolve.Level)).Count;
        float allAvailable = difOneAvailable + difTwoAvailable + difThreeAvailable;

        if (allAvailable == 0)
        {
            difOneAvailable = 4;
            allAvailable    = 4;
        }

        List <int> difficulties = new List <int>();
        int        difOnes      = Mathf.RoundToInt(difOneAvailable / allAvailable * questsLeft);
        int        difTwos      = Mathf.RoundToInt(difTwoAvailable / allAvailable * questsLeft);
        int        difThrees    = Mathf.RoundToInt(difThreeAvailable / allAvailable * questsLeft);

        difOnes += questsLeft - (difOnes + difTwos + difThrees);

        for (int i = 0; i < difOnes; i++)
        {
            difficulties.Add(1);
        }
        for (int i = 0; i < difTwos; i++)
        {
            difficulties.Add(3);
        }
        for (int i = 0; i < difThrees; i++)
        {
            difficulties.Add(5);
        }

        for (int i = 0; i < questInfo.dungeonQuests.Count; i++)
        {
            Quest quest    = new Quest();
            int   difIndex = Random.Range(0, difficulties.Count);
            quest.Dungeon    = questInfo.dungeonQuests[i].Dungeon;
            quest.Difficulty = difficulties[difIndex];
            difficulties.RemoveAt(difIndex);
            questInfo.dungeonQuests[i].Quests.Add(quest);
            questsLeft--;

            if (questsLeft == 0)
            {
                break;
            }
        }

        while (questsLeft > 0)
        {
            foreach (var dungeonInfo in questInfo.dungeonQuests)
            {
                if (questsLeft == 0)
                {
                    break;
                }

                if (dungeonInfo.Quests.Count < questInfo.maxPerDungeon)
                {
                    if (Random.Range(0, 2) == 0)
                    {
                        Quest quest    = new Quest();
                        int   difIndex = Random.Range(0, difficulties.Count);
                        quest.Dungeon    = dungeonInfo.Dungeon;
                        quest.Difficulty = difficulties[difIndex];
                        difficulties.RemoveAt(difIndex);
                        dungeonInfo.Quests.Add(quest);
                        questsLeft--;
                    }
                }
            }
        }

        foreach (var dungeon in campaign.Dungeons)
        {
            var plotMastery = dungeon.Value.CurrentPlotQuest;
            if (plotMastery != null)
            {
                DungeonQuestInfo dungeonQuest = questInfo.dungeonQuests.Find(item => item.Dungeon == dungeon.Value.DungeonName);
                if (dungeonQuest != null)
                {
                    dungeonQuest.Quests.Add(plotMastery.Copy());
                }
                else
                {
                    dungeonQuest = new DungeonQuestInfo()
                    {
                        Dungeon = plotMastery.Dungeon
                    };
                    dungeonQuest.Quests.Add(plotMastery.Copy());
                    questInfo.dungeonQuests.Add(dungeonQuest);
                }
            }
        }

        foreach (var townEventData in campaign.EventModifiers.EventData)
        {
            if (townEventData.Type == TownEventDataType.PlotQuest)
            {
                var plotQuest = DarkestDungeonManager.Data.QuestDatabase.PlotQuests.
                                Find(quest => quest.Id == townEventData.StringData);

                if (plotQuest != null && !campaign.CompletedPlot.Contains(plotQuest.Id))
                {
                    DungeonQuestInfo dungeonQuest = questInfo.dungeonQuests.Find(item => item.Dungeon == plotQuest.Dungeon);
                    if (dungeonQuest != null)
                    {
                        dungeonQuest.Quests.Add(plotQuest.Copy());
                    }
                    else
                    {
                        dungeonQuest = new DungeonQuestInfo()
                        {
                            Dungeon = plotQuest.Dungeon
                        };
                        dungeonQuest.Quests.Add(plotQuest.Copy());
                        questInfo.dungeonQuests.Add(dungeonQuest);
                    }
                }
            }
        }
    }