Skip to content

Commit f73102f

Browse files
author
luiza.torello
committed
feat: add random quest generation
1 parent ec2f979 commit f73102f

File tree

7 files changed

+48
-15
lines changed

7 files changed

+48
-15
lines changed

Assets/Resources/ScriptableObjectsData/GeneratorSettings.asset

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scenes/Main.unity

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Game/DataCollection/DungeonData.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Linq;
55
using Game.LevelManager.DungeonLoader;
6+
using Game.GameManager;
67
using Overlord.ProfileAnalyst;
78
using UnityEngine;
89
using Util;
@@ -18,6 +19,11 @@ namespace Game.DataCollection
1819
[Serializable]
1920
public class DungeonData : ScriptableObject
2021
{
22+
23+
#if !UNITY_WEBGL || UNITY_EDITOR
24+
[FirestoreProperty]
25+
#endif
26+
[field: SerializeField] public bool PlayerHadFixedProfile { get; set; }
2127
#if !UNITY_WEBGL || UNITY_EDITOR
2228
[FirestoreProperty]
2329
#endif
@@ -287,6 +293,7 @@ public void Init(Map map, string mapName, string jsonPath, int playerId)
287293
TotalReadableItems += map.TotalReadableItems;
288294
HeatMap = CreateHeatMap(map);
289295
TotalAttempts++;
296+
PlayerHadFixedProfile = ExperimentController.UseRandomProfile;
290297
_startTime = Time.realtimeSinceStartup;
291298
_jsonPath = jsonPath;
292299
PlayerId = playerId;

Assets/Scripts/Game/DataCollection/PlayerData.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public void Init(bool useFixedProfile)
2525
{
2626
SerializedData ??= new PlayerSerializedData
2727
{
28+
UseFixedProfile = useFixedProfile,
2829
PreFormAnswers = new List<int>(),
2930
PlayerId = RandomSingleton.GetInstance().Next(0, int.MaxValue) + (int)Time.realtimeSinceStartup,
3031
PlayerProfile = new YeePlayerProfile(),

Assets/Scripts/Game/DataCollection/PlayerDataController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private void Start()
100100
private void OnGameStart(object sender, EventArgs eventArgs)
101101
{
102102
CurrentPlayer = ScriptableObject.CreateInstance<PlayerData>();
103-
CurrentPlayer.Init( ExperimentController.UseFixedProfile );
103+
CurrentPlayer.Init( ExperimentController.UseRandomProfile );
104104
}
105105

106106
private void OnMapStart(object sender, StartMapEventArgs eventArgs)

Assets/Scripts/Game/GameManager/ExperimentController.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616
using Game.GameManager.Player;
1717
using Game.LevelManager.DungeonManager;
1818
using Topdown.Overlord.NarrativeGenerator;
19+
using Game.ExperimentControllers;
1920

2021

2122
namespace Game.GameManager
2223
{
23-
// TODO: Pula tela de level selection e carrega o nível gerado -> ao inves de carregar tela de level select,
24-
25-
// TODO:
26-
// Questão do loop -> Testar
27-
2824
public class ExperimentController : MonoBehaviour
2925
{
3026
public static event EventHandler StartExperimentGeneratorEventHandler;
@@ -36,17 +32,17 @@ public class ExperimentController : MonoBehaviour
3632
private YeePlayerProfile selectedProfile;
3733
private List<QuestLineList> _questLinesListForProfile;
3834

39-
public static bool UseFixedProfile => _useFixedProfile;
40-
private static bool _useFixedProfile;
35+
public static bool UseRandomProfile => _useRandomProfile;
36+
private static bool _useRandomProfile;
4137
private static bool _updatedProfile = false;
4238
private static bool _firstRunCompleted = false;
4339

44-
[SerializeField]
45-
private DungeonSceneLoader[] dungeonEntrances;
40+
[SerializeField] private DungeonSceneLoader[] dungeonEntrances;
41+
[SerializeField] private GeneratorSettings generatorSettings;
4642

4743
private void Awake()
4844
{
49-
SetUseFixedProfile();
45+
SetUseRandomProfile();
5046
_questLinesListForProfile = null;
5147
}
5248

@@ -126,9 +122,10 @@ private void LoadDataForExperiment(object sender, ProfileSelectedEventArgs profi
126122
ProfileSelectedEventHandler?.Invoke(null, new ProfileSelectedEventArgs(selectedProfile));
127123
}
128124

129-
private static void SetUseFixedProfile()
125+
private void SetUseRandomProfile()
130126
{
131-
_useFixedProfile = RandomSingleton.GetInstance().Random.Next(0, 100) < 50;
127+
_useRandomProfile = generatorSettings.EnableRandomProfileToPlayer && RandomSingleton.GetInstance().Random.Next(0, 100) > generatorSettings.ProbabilityToGetTrueProfile;
128+
Debug.Log("Set Use Random Profile to "+_useRandomProfile);
132129
}
133130

134131
private void OnRunComplete(object sender, EventArgs eventArgs)

Assets/Scripts/Game/NarrativeGenerator/Quests/QuestLine.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using UnityEditor;
1111
#endif
1212
using UnityEngine;
13+
using Game.GameManager;
1314
using Util;
1415
using static Util.Enums;
1516
using Overlord.NarrativeGenerator.Quests;
@@ -199,12 +200,22 @@ public List<QuestSo> GetCompletedQuests()
199200
}
200201

201202
public void PopulateQuestLine(in GeneratorSettings generatorSettings, NpcSo npcInCharge )
203+
{
204+
Dictionary<string, Func<int, float>> startSymbolWeights = YeeProfileCalculator.StartSymbolWeights;
205+
if (ExperimentController.UseRandomProfile)
206+
{
207+
startSymbolWeights = GetRandomSymbolWeights();
208+
}
209+
PopulateQuestLineMarkov(generatorSettings, npcInCharge, startSymbolWeights);
210+
}
211+
212+
private void PopulateQuestLineMarkov(in GeneratorSettings generatorSettings, NpcSo npcInCharge, Dictionary<string, Func<int, float>> startSymbolWeights )
202213
{
203214
var questChain = new MarkovChain();
204215
while (questChain.GetLastSymbol().CanDrawNext)
205216
{
206217
var lastSelectedQuest = questChain.GetLastSymbol();
207-
lastSelectedQuest.NextSymbolChances = YeeProfileCalculator.StartSymbolWeights;
218+
lastSelectedQuest.NextSymbolChances = startSymbolWeights;
208219
lastSelectedQuest.SetNextSymbol(questChain);
209220

210221
var nonTerminalSymbol = questChain.GetLastSymbol();
@@ -247,5 +258,16 @@ public void ConvertDataForCurrentDungeon(List<DungeonRoomData> dungeonParts)
247258
quest.CreateQuestString(_language);
248259
}
249260
}
261+
262+
private Dictionary<string, Func<int, float>> GetRandomSymbolWeights()
263+
{
264+
return new Dictionary<string, Func<int, float>>
265+
{
266+
{Constants.ImmersionQuest, _ => 25f},
267+
{Constants.AchievementQuest, _ => 25f},
268+
{Constants.MasteryQuest, _ => 25f},
269+
{Constants.CreativityQuest, _ => 25f}
270+
};
271+
}
250272
}
251273
}

0 commit comments

Comments
 (0)