fr.jeanf.questsystem 0.0.32 → 0.0.34
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()
|
|
@@ -57,14 +62,6 @@ namespace jeanf.questsystem
|
|
|
57
62
|
stepMap.Add(questSO.questSteps[i].StepId, questSO.questSteps[i]);
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
|
-
|
|
61
|
-
foreach (QuestStep step in stepMap.Values)
|
|
62
|
-
{
|
|
63
|
-
if (step.isRootStep)
|
|
64
|
-
{
|
|
65
|
-
InstantiateQuestStep(step.StepId);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
private void OnEnable()
|
|
@@ -78,35 +75,35 @@ namespace jeanf.questsystem
|
|
|
78
75
|
|
|
79
76
|
private void Subscribe()
|
|
80
77
|
{
|
|
81
|
-
QuestInitialCheck.OnEventRaised +=
|
|
82
|
-
StartQuestEventChannel.OnEventRaised += RequestQuestStart;
|
|
78
|
+
QuestInitialCheck.OnEventRaised += Init;
|
|
83
79
|
QuestProgress.OnEventRaised += UpdateProgress;
|
|
84
80
|
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
85
81
|
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
86
82
|
QuestStep.sendNextStepId += InstantiateQuestStep;
|
|
87
83
|
QuestStep.stepCompleted += DestroyQuestStep;
|
|
84
|
+
QuestStep.stepActive += UpdateStepStatus;
|
|
88
85
|
|
|
89
86
|
}
|
|
90
87
|
|
|
91
88
|
private void Unsubscribe()
|
|
92
89
|
{
|
|
93
|
-
QuestInitialCheck.OnEventRaised -=
|
|
94
|
-
StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
|
|
90
|
+
QuestInitialCheck.OnEventRaised -= Init;
|
|
95
91
|
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
96
92
|
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
97
93
|
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
98
94
|
QuestStep.sendNextStepId -= InstantiateQuestStep;
|
|
99
95
|
QuestStep.stepCompleted -= DestroyQuestStep;
|
|
96
|
+
QuestStep.stepActive -= UpdateStepStatus;
|
|
100
97
|
|
|
101
98
|
}
|
|
102
99
|
#endregion
|
|
103
100
|
|
|
104
|
-
#region
|
|
101
|
+
#region Instantiations & Loading
|
|
105
102
|
public void InstantiateQuestStep(string id)
|
|
106
103
|
{
|
|
107
104
|
if (activeSteps.ContainsKey(id))
|
|
108
105
|
{
|
|
109
|
-
Debug.Log("Step already in active steps");
|
|
106
|
+
Debug.Log($"Step with id:[{id}] is already in the list of active steps");
|
|
110
107
|
return;
|
|
111
108
|
}
|
|
112
109
|
|
|
@@ -117,32 +114,73 @@ namespace jeanf.questsystem
|
|
|
117
114
|
}
|
|
118
115
|
|
|
119
116
|
public void DestroyQuestStep(string id)
|
|
120
|
-
|
|
117
|
+
{
|
|
121
118
|
if (activeSteps.ContainsKey(id))
|
|
122
119
|
{
|
|
123
120
|
Destroy(activeSteps[id].gameObject);
|
|
124
|
-
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private void LoadDependencies()
|
|
125
|
+
{
|
|
126
|
+
foreach (string SceneToLoad in questSO.ScenesToLoad)
|
|
127
|
+
{
|
|
128
|
+
loadRequiredScenesEventChannel.RaiseEvent(SceneToLoad);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
foreach (int roomToUnlock in questSO.roomsToUnlock)
|
|
132
|
+
{
|
|
133
|
+
unlockDoorsEventChannel.RaiseEvent(roomToUnlock);
|
|
125
134
|
}
|
|
126
135
|
}
|
|
127
136
|
#endregion
|
|
128
137
|
|
|
138
|
+
public void UpdateStepStatus(string id, QuestStepStatus status)
|
|
139
|
+
{
|
|
140
|
+
switch (status)
|
|
141
|
+
{
|
|
142
|
+
case QuestStepStatus.Completed when activeSteps.ContainsKey(id):
|
|
143
|
+
// put step in completed list
|
|
144
|
+
activeSteps.Remove(id);
|
|
145
|
+
completedSteps.Add(id, stepMap[id]);
|
|
146
|
+
break;
|
|
147
|
+
case QuestStepStatus.Active when !activeSteps.ContainsKey(id):
|
|
148
|
+
// put step in active list
|
|
149
|
+
activeSteps.Add(id, stepMap[id]);
|
|
150
|
+
break;
|
|
151
|
+
case QuestStepStatus.Inactive:
|
|
152
|
+
// do nothing
|
|
153
|
+
default:
|
|
154
|
+
// do nothing
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
129
158
|
|
|
130
159
|
#region quest process
|
|
131
160
|
private void Init(string id)
|
|
132
161
|
{
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
162
|
+
activeSteps.Clear();
|
|
163
|
+
activeSteps.TrimExcess();
|
|
164
|
+
completedSteps.Clear();
|
|
165
|
+
completedSteps.TrimExcess();
|
|
138
166
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
167
|
+
Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
|
|
168
|
+
if (!_startQuestOnEnable || id != questId) return;
|
|
169
|
+
clearToStart = true;
|
|
170
|
+
currentQuestState = QuestState.CAN_START;
|
|
171
|
+
requirementCheck.RaiseEvent(questId);
|
|
172
|
+
UpdateState();
|
|
144
173
|
|
|
174
|
+
foreach (QuestStep step in stepMap.Values)
|
|
175
|
+
{
|
|
176
|
+
if (step.isRootStep)
|
|
177
|
+
{
|
|
178
|
+
InstantiateQuestStep(step.StepId);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
145
181
|
|
|
182
|
+
LoadDependencies();
|
|
183
|
+
}
|
|
146
184
|
|
|
147
185
|
private void UpdateState()
|
|
148
186
|
{
|
|
@@ -196,34 +234,28 @@ namespace jeanf.questsystem
|
|
|
196
234
|
UpdateState();
|
|
197
235
|
}
|
|
198
236
|
}
|
|
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
237
|
#endregion
|
|
218
238
|
|
|
219
239
|
#region validation tools
|
|
220
240
|
|
|
221
|
-
#if UNITY_EDITOR
|
|
241
|
+
#if UNITY_EDITOR
|
|
222
242
|
public void OnValidate()
|
|
223
243
|
{
|
|
224
244
|
ValidityCheck();
|
|
225
245
|
}
|
|
226
|
-
#endif
|
|
246
|
+
#endif
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
#if UNITY_EDITOR
|
|
250
|
+
public void LogActiveSteps()
|
|
251
|
+
{
|
|
252
|
+
Debug.Log($"There is {activeSteps.Count} active steps at the moment.");
|
|
253
|
+
foreach (var step in activeSteps.Keys)
|
|
254
|
+
{
|
|
255
|
+
Debug.Log($"active step: {step}");
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
#endif
|
|
227
259
|
|
|
228
260
|
private void ValidityCheck()
|
|
229
261
|
{
|
|
@@ -264,19 +296,6 @@ namespace jeanf.questsystem
|
|
|
264
296
|
|
|
265
297
|
}
|
|
266
298
|
|
|
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
299
|
if (requirementCheck == null)
|
|
281
300
|
{
|
|
282
301
|
if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
|
|
@@ -301,4 +320,20 @@ namespace jeanf.questsystem
|
|
|
301
320
|
}
|
|
302
321
|
#endregion
|
|
303
322
|
}
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
#if UNITY_EDITOR
|
|
326
|
+
[CustomEditor(typeof(QuestItem))]
|
|
327
|
+
public class BoolEventOnClickEditor : Editor {
|
|
328
|
+
override public void OnInspectorGUI () {
|
|
329
|
+
DrawDefaultInspector();
|
|
330
|
+
GUILayout.Space(10);
|
|
331
|
+
var eventToSend = (QuestItem) target;
|
|
332
|
+
if(GUILayout.Button("Log active steps", GUILayout.Height(30))) {
|
|
333
|
+
eventToSend.LogActiveSteps(); // how do i call this?
|
|
334
|
+
}
|
|
335
|
+
GUILayout.Space(10);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
#endif
|
|
304
339
|
}
|
|
@@ -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)
|
|
@@ -97,8 +100,9 @@ namespace jeanf.questsystem
|
|
|
97
100
|
{
|
|
98
101
|
sendNextStepId?.Invoke(questStep.stepId);
|
|
99
102
|
}
|
|
100
|
-
|
|
101
103
|
stepCompleted?.Invoke(stepId);
|
|
104
|
+
stepActive?.Invoke(stepId, stepStatus);
|
|
105
|
+
|
|
102
106
|
|
|
103
107
|
if (!isUsingIntroTimeline || !timeline) return;
|
|
104
108
|
//if(isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: false");
|
|
@@ -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
|
}
|