fr.jeanf.questsystem 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,9 @@ using jeanf.EventSystem;
|
|
|
4
4
|
using UnityEngine;
|
|
5
5
|
using jeanf.propertyDrawer;
|
|
6
6
|
using jeanf.validationTools;
|
|
7
|
+
using Unity.VisualScripting.YamlDotNet.Core.Tokens;
|
|
8
|
+
using UnityEngine.SceneManagement;
|
|
9
|
+
using UnityEditor;
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
namespace jeanf.questsystem
|
|
@@ -24,6 +27,7 @@ namespace jeanf.questsystem
|
|
|
24
27
|
private QuestSO questSO;
|
|
25
28
|
private Dictionary<string, QuestStep> stepMap = new Dictionary<string, QuestStep>();
|
|
26
29
|
private Dictionary<string, QuestStep> activeSteps = new Dictionary<string, QuestStep>();
|
|
30
|
+
private Dictionary<string, QuestStep> completedSteps = new Dictionary<string, QuestStep>();
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
[ReadOnly] [Range(0, 1)] [SerializeField]
|
|
@@ -39,11 +43,12 @@ namespace jeanf.questsystem
|
|
|
39
43
|
// if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
|
|
40
44
|
[Header("Listening on:")]
|
|
41
45
|
[SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
|
|
42
|
-
[SerializeField] [Validation("A reference to the StartQuestEventChannel SO is required")] private StringEventChannelSO StartQuestEventChannel;
|
|
43
46
|
[SerializeField] [Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
|
|
44
47
|
|
|
45
48
|
[Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
|
|
46
49
|
private StringEventChannelSO requirementCheck;
|
|
50
|
+
[SerializeField] StringEventChannelSO loadRequiredScenesEventChannel;
|
|
51
|
+
[SerializeField] IntEventChannelSO unlockDoorsEventChannel;
|
|
47
52
|
|
|
48
53
|
#region Awake/Enable/Disable
|
|
49
54
|
private void Awake()
|
|
@@ -65,6 +70,9 @@ namespace jeanf.questsystem
|
|
|
65
70
|
InstantiateQuestStep(step.StepId);
|
|
66
71
|
}
|
|
67
72
|
}
|
|
73
|
+
|
|
74
|
+
LoadDependencies();
|
|
75
|
+
|
|
68
76
|
}
|
|
69
77
|
|
|
70
78
|
private void OnEnable()
|
|
@@ -78,35 +86,35 @@ namespace jeanf.questsystem
|
|
|
78
86
|
|
|
79
87
|
private void Subscribe()
|
|
80
88
|
{
|
|
81
|
-
QuestInitialCheck.OnEventRaised +=
|
|
82
|
-
StartQuestEventChannel.OnEventRaised += RequestQuestStart;
|
|
89
|
+
QuestInitialCheck.OnEventRaised += Init;
|
|
83
90
|
QuestProgress.OnEventRaised += UpdateProgress;
|
|
84
91
|
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
85
92
|
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
86
93
|
QuestStep.sendNextStepId += InstantiateQuestStep;
|
|
87
94
|
QuestStep.stepCompleted += DestroyQuestStep;
|
|
95
|
+
QuestStep.stepActive += UpdateStepStatus;
|
|
88
96
|
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
private void Unsubscribe()
|
|
92
100
|
{
|
|
93
|
-
QuestInitialCheck.OnEventRaised -=
|
|
94
|
-
StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
|
|
101
|
+
QuestInitialCheck.OnEventRaised -= Init;
|
|
95
102
|
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
96
103
|
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
97
104
|
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
98
105
|
QuestStep.sendNextStepId -= InstantiateQuestStep;
|
|
99
106
|
QuestStep.stepCompleted -= DestroyQuestStep;
|
|
107
|
+
QuestStep.stepActive -= UpdateStepStatus;
|
|
100
108
|
|
|
101
109
|
}
|
|
102
110
|
#endregion
|
|
103
111
|
|
|
104
|
-
#region
|
|
112
|
+
#region Instantiations & Loading
|
|
105
113
|
public void InstantiateQuestStep(string id)
|
|
106
114
|
{
|
|
107
115
|
if (activeSteps.ContainsKey(id))
|
|
108
116
|
{
|
|
109
|
-
Debug.Log("Step already in active steps");
|
|
117
|
+
Debug.Log($"Step with id:[{id}] is already in the list of active steps");
|
|
110
118
|
return;
|
|
111
119
|
}
|
|
112
120
|
|
|
@@ -124,26 +132,59 @@ namespace jeanf.questsystem
|
|
|
124
132
|
activeSteps.Remove(id);
|
|
125
133
|
}
|
|
126
134
|
}
|
|
135
|
+
|
|
136
|
+
private void LoadDependencies()
|
|
137
|
+
{
|
|
138
|
+
foreach (string SceneToLoad in questSO.ScenesToLoad)
|
|
139
|
+
{
|
|
140
|
+
loadRequiredScenesEventChannel.RaiseEvent(SceneToLoad);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
foreach (int roomToUnlock in questSO.roomsToUnlock)
|
|
144
|
+
{
|
|
145
|
+
unlockDoorsEventChannel.RaiseEvent(roomToUnlock);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
127
148
|
#endregion
|
|
128
149
|
|
|
150
|
+
public void UpdateStepStatus(string id, QuestStepStatus status)
|
|
151
|
+
{
|
|
152
|
+
switch (status)
|
|
153
|
+
{
|
|
154
|
+
case QuestStepStatus.Completed when activeSteps.ContainsKey(id):
|
|
155
|
+
// put step in completed list
|
|
156
|
+
activeSteps.Remove(id);
|
|
157
|
+
completedSteps.Add(id, stepMap[id]);
|
|
158
|
+
break;
|
|
159
|
+
case QuestStepStatus.Active when !activeSteps.ContainsKey(id):
|
|
160
|
+
// put step in active list
|
|
161
|
+
activeSteps.Add(id, stepMap[id]);
|
|
162
|
+
break;
|
|
163
|
+
case QuestStepStatus.Inactive:
|
|
164
|
+
// do nothing
|
|
165
|
+
default:
|
|
166
|
+
// do nothing
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
129
170
|
|
|
130
171
|
#region quest process
|
|
131
172
|
private void Init(string id)
|
|
132
173
|
{
|
|
174
|
+
activeSteps.Clear();
|
|
175
|
+
activeSteps.TrimExcess();
|
|
176
|
+
completedSteps.Clear();
|
|
177
|
+
completedSteps.TrimExcess();
|
|
133
178
|
|
|
134
179
|
Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
|
|
135
180
|
if (!_startQuestOnEnable) return;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
Debug.Log($"Initial check for quest with id: [{id}], it is in the following state: [{currentQuestState}]");
|
|
142
|
-
Init(id);
|
|
181
|
+
if (!_startQuestOnEnable || id != questId) return;
|
|
182
|
+
clearToStart = true;
|
|
183
|
+
currentQuestState = QuestState.CAN_START;
|
|
184
|
+
requirementCheck.RaiseEvent(questId);
|
|
185
|
+
UpdateState();
|
|
143
186
|
}
|
|
144
187
|
|
|
145
|
-
|
|
146
|
-
|
|
147
188
|
private void UpdateState()
|
|
148
189
|
{
|
|
149
190
|
if (isDebug) Debug.Log($"Updating State...");
|
|
@@ -196,34 +237,28 @@ namespace jeanf.questsystem
|
|
|
196
237
|
UpdateState();
|
|
197
238
|
}
|
|
198
239
|
}
|
|
199
|
-
|
|
200
|
-
public void AllClear(bool value)
|
|
201
|
-
{
|
|
202
|
-
Debug.Log($"All clear for quest [{questId}], sending an update to the QuestManager");
|
|
203
|
-
clearToStart = value;
|
|
204
|
-
currentQuestState = QuestState.CAN_START;
|
|
205
|
-
requirementCheck.RaiseEvent(questId);
|
|
206
|
-
UpdateState();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private void RequestQuestStart(string id)
|
|
210
|
-
{
|
|
211
|
-
if(id!= questId) return;
|
|
212
|
-
|
|
213
|
-
Debug.Log($"Requesting start for quest [{id}]");
|
|
214
|
-
AllClear(true);
|
|
215
|
-
if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
|
|
216
|
-
}
|
|
217
240
|
#endregion
|
|
218
241
|
|
|
219
242
|
#region validation tools
|
|
220
243
|
|
|
221
|
-
#if UNITY_EDITOR
|
|
244
|
+
#if UNITY_EDITOR
|
|
222
245
|
public void OnValidate()
|
|
223
246
|
{
|
|
224
247
|
ValidityCheck();
|
|
225
248
|
}
|
|
226
|
-
#endif
|
|
249
|
+
#endif
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
#if UNITY_EDITOR
|
|
253
|
+
public void LogActiveSteps()
|
|
254
|
+
{
|
|
255
|
+
Debug.Log($"There is {activeSteps.Count} active steps at the moment.");
|
|
256
|
+
foreach (var step in activeSteps.Keys)
|
|
257
|
+
{
|
|
258
|
+
Debug.Log($"active step: {step}");
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
#endif
|
|
227
262
|
|
|
228
263
|
private void ValidityCheck()
|
|
229
264
|
{
|
|
@@ -264,19 +299,6 @@ namespace jeanf.questsystem
|
|
|
264
299
|
|
|
265
300
|
}
|
|
266
301
|
|
|
267
|
-
if (StartQuestEventChannel == null)
|
|
268
|
-
{
|
|
269
|
-
if (isDebug) Debug.Log($"{searching} {_}/StartQuestEventChannel in {searchLocation}", this);
|
|
270
|
-
StartQuestEventChannel = Resources.Load<StringEventChannelSO>($"{_}/StartQuestEventChannel");
|
|
271
|
-
if (StartQuestEventChannel == null)
|
|
272
|
-
{
|
|
273
|
-
errorMessages.Add($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}");
|
|
274
|
-
validityCheck = false;
|
|
275
|
-
invalidObjects.Add(StartQuestEventChannel);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
302
|
if (requirementCheck == null)
|
|
281
303
|
{
|
|
282
304
|
if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
|
|
@@ -301,4 +323,20 @@ namespace jeanf.questsystem
|
|
|
301
323
|
}
|
|
302
324
|
#endregion
|
|
303
325
|
}
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
#if UNITY_EDITOR
|
|
329
|
+
[CustomEditor(typeof(QuestItem))]
|
|
330
|
+
public class BoolEventOnClickEditor : Editor {
|
|
331
|
+
override public void OnInspectorGUI () {
|
|
332
|
+
DrawDefaultInspector();
|
|
333
|
+
GUILayout.Space(10);
|
|
334
|
+
var eventToSend = (QuestItem) target;
|
|
335
|
+
if(GUILayout.Button("Log active steps", GUILayout.Height(30))) {
|
|
336
|
+
eventToSend.LogActiveSteps(); // how do i call this?
|
|
337
|
+
}
|
|
338
|
+
GUILayout.Space(10);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
#endif
|
|
304
342
|
}
|
|
@@ -238,22 +238,22 @@ namespace jeanf.questsystem
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
-
private Quest LoadQuest(QuestSO
|
|
241
|
+
private Quest LoadQuest(QuestSO questSO)
|
|
242
242
|
{
|
|
243
243
|
Quest quest = null;
|
|
244
244
|
try
|
|
245
245
|
{
|
|
246
246
|
// load quest from saved data
|
|
247
|
-
if (PlayerPrefs.HasKey(
|
|
247
|
+
if (PlayerPrefs.HasKey(questSO.id) && loadSavedQuestState)
|
|
248
248
|
{
|
|
249
|
-
string serializedData = PlayerPrefs.GetString(
|
|
249
|
+
string serializedData = PlayerPrefs.GetString(questSO.id);
|
|
250
250
|
QuestData questData = JsonUtility.FromJson<QuestData>(serializedData);
|
|
251
|
-
quest = new Quest(
|
|
251
|
+
quest = new Quest(questSO, questData.state, questData.questStepIndex, questData.questStepStates);
|
|
252
252
|
}
|
|
253
253
|
// otherwise, initialize a new quest
|
|
254
254
|
else
|
|
255
255
|
{
|
|
256
|
-
quest = new Quest(
|
|
256
|
+
quest = new Quest(questSO);
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
259
|
catch (System.Exception e)
|
|
@@ -5,6 +5,7 @@ using UnityEngine;
|
|
|
5
5
|
using jeanf.propertyDrawer;
|
|
6
6
|
using jeanf.validationTools;
|
|
7
7
|
using System.Collections.Generic;
|
|
8
|
+
using UnityEngine.SceneManagement;
|
|
8
9
|
|
|
9
10
|
namespace jeanf.questsystem
|
|
10
11
|
{
|
|
@@ -27,6 +28,8 @@ namespace jeanf.questsystem
|
|
|
27
28
|
|
|
28
29
|
[Header("Requirements")] public int levelRequirement;
|
|
29
30
|
public QuestSO[] questPrerequisites;
|
|
31
|
+
public List<string> ScenesToLoad = new List<string>();
|
|
32
|
+
public List<int> roomsToUnlock = new List<int>();
|
|
30
33
|
|
|
31
34
|
[Header("Steps")] public QuestStep[] questSteps;
|
|
32
35
|
|
|
@@ -64,4 +67,4 @@ namespace jeanf.questsystem
|
|
|
64
67
|
}
|
|
65
68
|
#endif
|
|
66
69
|
}
|
|
67
|
-
}
|
|
70
|
+
}
|
|
@@ -23,8 +23,6 @@ namespace jeanf.questsystem
|
|
|
23
23
|
public string QuestId { get { return questId; } }
|
|
24
24
|
|
|
25
25
|
|
|
26
|
-
private float questStepProgress = 0;
|
|
27
|
-
|
|
28
26
|
[field: ReadOnly] [SerializeField] public QuestStepStatus stepStatus;
|
|
29
27
|
|
|
30
28
|
[Tooltip("This boolean has to be enabled if the quest step has an intro timeline.")]
|
|
@@ -42,6 +40,10 @@ namespace jeanf.questsystem
|
|
|
42
40
|
public bool isRootStep;
|
|
43
41
|
public delegate void StepCompleted(string id);
|
|
44
42
|
public static StepCompleted stepCompleted;
|
|
43
|
+
public delegate void StepActive(string id, QuestStepStatus stepStatus);
|
|
44
|
+
public static StepActive stepActive;
|
|
45
|
+
|
|
46
|
+
|
|
45
47
|
[Header("Quest Tooltip")]
|
|
46
48
|
[SerializeField] private QuestTooltipSO questTooltipSO;
|
|
47
49
|
|
|
@@ -64,6 +66,7 @@ namespace jeanf.questsystem
|
|
|
64
66
|
Debug.Log($"Initializing quest with questId: {questId}");
|
|
65
67
|
|
|
66
68
|
stepStatus = QuestStepStatus.Active;
|
|
69
|
+
stepActive?.Invoke(stepId, stepStatus);
|
|
67
70
|
|
|
68
71
|
|
|
69
72
|
if (sendQuestStepTooltip != null)
|
|
@@ -98,6 +101,7 @@ namespace jeanf.questsystem
|
|
|
98
101
|
sendNextStepId?.Invoke(questStep.stepId);
|
|
99
102
|
}
|
|
100
103
|
|
|
104
|
+
stepActive?.Invoke(stepId, stepStatus);
|
|
101
105
|
stepCompleted?.Invoke(stepId);
|
|
102
106
|
|
|
103
107
|
if (!isUsingIntroTimeline || !timeline) return;
|
|
@@ -39,17 +39,5 @@ namespace jeanf.questsystem
|
|
|
39
39
|
onQuestStateChange(quest);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
//public event Action<string, int, QuestStepState> onQuestStepStateChange;
|
|
44
|
-
|
|
45
|
-
//public void QuestStepStateChange(string id, int stepIndex, QuestStepState questStepState)
|
|
46
|
-
//{
|
|
47
|
-
// if (onQuestStepStateChange != null)
|
|
48
|
-
// {
|
|
49
|
-
// Debug.Log($"quest step state change: {id} -- stepstate: {questStepState}");
|
|
50
|
-
// onQuestStepStateChange(id, stepIndex, questStepState);
|
|
51
|
-
// }
|
|
52
|
-
//}
|
|
53
|
-
|
|
54
42
|
}
|
|
55
43
|
}
|