fr.jeanf.questsystem 0.0.47 → 0.0.48
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.
- package/Runtime/Scripts/Core/Quest.cs +23 -23
- package/Runtime/Scripts/Core/QuestData.cs +2 -2
- package/Runtime/Scripts/Core/QuestItem.cs +49 -23
- package/Runtime/Scripts/Core/QuestManager.cs +1 -1
- package/Runtime/Scripts/Core/QuestSO.cs +2 -2
- package/Runtime/Scripts/Core/QuestStep.cs +12 -3
- package/package.json +1 -1
|
@@ -16,7 +16,7 @@ namespace jeanf.questsystem
|
|
|
16
16
|
|
|
17
17
|
// state info
|
|
18
18
|
public QuestState state;
|
|
19
|
-
private QuestStepState
|
|
19
|
+
private List<QuestStepState> questStepStates;
|
|
20
20
|
public StringEventChannelSO messageChannel;
|
|
21
21
|
public bool sendMessageOnInitialization = false;
|
|
22
22
|
public string messageToSendOnInit = "";
|
|
@@ -27,7 +27,7 @@ namespace jeanf.questsystem
|
|
|
27
27
|
{
|
|
28
28
|
this.questSO = questSO;
|
|
29
29
|
this.state = QuestState.REQUIREMENTS_NOT_MET;
|
|
30
|
-
this.questStepStates = new QuestStepState
|
|
30
|
+
this.questStepStates = new List<QuestStepState>();
|
|
31
31
|
this.messageChannel = questSO.messageChannel;
|
|
32
32
|
//init
|
|
33
33
|
this.sendMessageOnInitialization = questSO.sendMessageOnInitialization;
|
|
@@ -35,14 +35,14 @@ namespace jeanf.questsystem
|
|
|
35
35
|
//finish
|
|
36
36
|
this.sendMessageOnFinish = questSO.sendMessageOnFinish;
|
|
37
37
|
this.messageToSendOnFinish = questSO.messageToSendOnFinish;
|
|
38
|
-
for (int i = 0; i < questStepStates.
|
|
38
|
+
for (int i = 0; i < questStepStates.Count; i++)
|
|
39
39
|
{
|
|
40
40
|
questStepStates[i] = new QuestStepState();
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
public Quest(QuestSO questQuestSo, QuestState questState, int currentQuestStepIndex,
|
|
45
|
-
QuestStepState
|
|
45
|
+
List<QuestStepState> questStepStates)
|
|
46
46
|
{
|
|
47
47
|
this.questSO = questQuestSo;
|
|
48
48
|
this.state = questState;
|
|
@@ -50,29 +50,29 @@ namespace jeanf.questsystem
|
|
|
50
50
|
|
|
51
51
|
//if the quest step states and prefabs are different lengths,
|
|
52
52
|
//something has changed during development and the saved data is out of sync.
|
|
53
|
-
if (this.questStepStates.Length != this.questSO.questSteps.Length)
|
|
54
|
-
{
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
53
|
+
//if (this.questStepStates.Length != this.questSO.questSteps.Length)
|
|
54
|
+
//{
|
|
55
|
+
// Debug.LogWarning("Quest Step Prefabs and Quest Step States are "
|
|
56
|
+
// + "of different lengths. This indicates something changed "
|
|
57
|
+
// + "with the QuestInfo and the saved data is now out of sync. "
|
|
58
|
+
// + "Reset your data - as this might cause issues. QuestId: " + this.questSO.id);
|
|
59
|
+
//}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
|
|
64
|
-
public void StoreQuestStepState(QuestStepState questStepState, int stepIndex)
|
|
65
|
-
{
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
64
|
+
//public void StoreQuestStepState(QuestStepState questStepState, int stepIndex)
|
|
65
|
+
//{
|
|
66
|
+
// if (stepIndex < questStepStates.Count)
|
|
67
|
+
// {
|
|
68
|
+
// questStepStates[stepIndex].state = questStepState.state;
|
|
69
|
+
// }
|
|
70
|
+
// else
|
|
71
|
+
// {
|
|
72
|
+
// Debug.LogWarning("Tried to access quest step data, but stepIndex was out of range: "
|
|
73
|
+
// + "Quest Id = " + questSO.id + ", Step Index = " + stepIndex);
|
|
74
|
+
// }
|
|
75
|
+
//}
|
|
76
76
|
|
|
77
77
|
//public QuestData GetQuestData()
|
|
78
78
|
//{
|
|
@@ -12,9 +12,9 @@ namespace jeanf.questsystem
|
|
|
12
12
|
// old constructor (linear structure)
|
|
13
13
|
public QuestState state;
|
|
14
14
|
public int questStepIndex;
|
|
15
|
-
public QuestStepState
|
|
15
|
+
public List<QuestStepState> questStepStates;
|
|
16
16
|
|
|
17
|
-
public QuestData(QuestState state, int questStepIndex, QuestStepState
|
|
17
|
+
public QuestData(QuestState state, int questStepIndex, List<QuestStepState> questStepStates)
|
|
18
18
|
{
|
|
19
19
|
this.state = state;
|
|
20
20
|
this.questStepIndex = questStepIndex;
|
|
@@ -5,6 +5,7 @@ using UnityEngine;
|
|
|
5
5
|
using jeanf.propertyDrawer;
|
|
6
6
|
using jeanf.validationTools;
|
|
7
7
|
using UnityEditor;
|
|
8
|
+
using System.Linq;
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
namespace jeanf.questsystem
|
|
@@ -21,11 +22,12 @@ namespace jeanf.questsystem
|
|
|
21
22
|
[SerializeField] private bool _isDebug = false;
|
|
22
23
|
[SerializeField] private bool _startQuestOnEnable = false;
|
|
23
24
|
|
|
24
|
-
[Tooltip("Visual feedback for the quest state")] [Header("Quest")]
|
|
25
|
-
private QuestSO questSO;
|
|
25
|
+
[Tooltip("Visual feedback for the quest state")] [Header("Quest")]
|
|
26
|
+
[SerializeField] [Validation("A reference to a questSO is required")] private QuestSO questSO;
|
|
26
27
|
private Dictionary<string, QuestStep> stepMap = new Dictionary<string, QuestStep>();
|
|
27
28
|
private Dictionary<string, QuestStep> activeSteps = new Dictionary<string, QuestStep>();
|
|
28
29
|
private Dictionary<string, QuestStep> completedSteps = new Dictionary<string, QuestStep>();
|
|
30
|
+
private List<QuestStep> rootSteps = new List<QuestStep>();
|
|
29
31
|
|
|
30
32
|
|
|
31
33
|
[ReadOnly] [Range(0, 1)] [SerializeField]
|
|
@@ -45,20 +47,18 @@ namespace jeanf.questsystem
|
|
|
45
47
|
|
|
46
48
|
[Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
|
|
47
49
|
private StringEventChannelSO requirementCheck;
|
|
48
|
-
[SerializeField]
|
|
50
|
+
[SerializeField][Validation("A reference to the LoadRequiredScenesEventChannel SO is required")] StringListEventChannelSO loadRequiredScenesEventChannel;
|
|
49
51
|
[SerializeField] IntEventChannelSO unlockDoorsEventChannel;
|
|
50
52
|
|
|
51
53
|
#region Awake/Enable/Disable
|
|
52
54
|
private void Awake()
|
|
53
55
|
{
|
|
54
56
|
questId = questSO.id;
|
|
55
|
-
for (int i = 0; i < questSO.
|
|
57
|
+
for (int i = 0; i < questSO.rootSteps.Length; i++)
|
|
56
58
|
{
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
stepMap.Add(questSO.questSteps[i].StepId, questSO.questSteps[i]);
|
|
61
|
-
}
|
|
59
|
+
Debug.Log($"id on awake {questSO.rootSteps[i].StepId}, added to {this.name}'s dictionary", this);
|
|
60
|
+
AddStepToStepMap(questSO.rootSteps[i]);
|
|
61
|
+
rootSteps.Add(questSO.rootSteps[i]);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -80,6 +80,7 @@ namespace jeanf.questsystem
|
|
|
80
80
|
QuestStep.sendNextStepId += InstantiateQuestStep;
|
|
81
81
|
//QuestStep.stepCompleted += DestroyQuestStep;
|
|
82
82
|
QuestStep.stepActive += UpdateStepStatus;
|
|
83
|
+
QuestStep.childStep += AddStepToStepMap;
|
|
83
84
|
|
|
84
85
|
}
|
|
85
86
|
|
|
@@ -92,10 +93,12 @@ namespace jeanf.questsystem
|
|
|
92
93
|
QuestStep.sendNextStepId -= InstantiateQuestStep;
|
|
93
94
|
//QuestStep.stepCompleted -= DestroyQuestStep;
|
|
94
95
|
QuestStep.stepActive -= UpdateStepStatus;
|
|
96
|
+
QuestStep.childStep -= AddStepToStepMap;
|
|
97
|
+
|
|
95
98
|
|
|
96
99
|
}
|
|
97
100
|
#endregion
|
|
98
|
-
|
|
101
|
+
|
|
99
102
|
#region Instantiations & Loading
|
|
100
103
|
public void InstantiateQuestStep(string id)
|
|
101
104
|
{
|
|
@@ -109,10 +112,7 @@ namespace jeanf.questsystem
|
|
|
109
112
|
|
|
110
113
|
private void LoadDependencies()
|
|
111
114
|
{
|
|
112
|
-
|
|
113
|
-
{
|
|
114
|
-
loadRequiredScenesEventChannel.RaiseEvent(SceneToLoad);
|
|
115
|
-
}
|
|
115
|
+
loadRequiredScenesEventChannel.RaiseEvent(questSO.ScenesToLoad);
|
|
116
116
|
|
|
117
117
|
foreach (int roomToUnlock in questSO.roomsToUnlock)
|
|
118
118
|
{
|
|
@@ -142,6 +142,14 @@ namespace jeanf.questsystem
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
private void AddStepToStepMap(QuestStep step)
|
|
146
|
+
{
|
|
147
|
+
if (!stepMap.ContainsKey(step.StepId))
|
|
148
|
+
{
|
|
149
|
+
stepMap.Add(step.StepId, step);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
145
153
|
#region quest process
|
|
146
154
|
private void Init(string id)
|
|
147
155
|
{
|
|
@@ -157,12 +165,9 @@ namespace jeanf.questsystem
|
|
|
157
165
|
requirementCheck.RaiseEvent(questId);
|
|
158
166
|
UpdateState();
|
|
159
167
|
|
|
160
|
-
foreach (QuestStep step in
|
|
168
|
+
foreach (QuestStep step in rootSteps)
|
|
161
169
|
{
|
|
162
|
-
|
|
163
|
-
{
|
|
164
|
-
InstantiateQuestStep(step.StepId);
|
|
165
|
-
}
|
|
170
|
+
InstantiateQuestStep(step.StepId);
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
LoadDependencies();
|
|
@@ -229,10 +234,10 @@ namespace jeanf.questsystem
|
|
|
229
234
|
{
|
|
230
235
|
ValidityCheck();
|
|
231
236
|
}
|
|
232
|
-
|
|
237
|
+
|
|
233
238
|
|
|
234
239
|
|
|
235
|
-
|
|
240
|
+
|
|
236
241
|
public void LogActiveSteps()
|
|
237
242
|
{
|
|
238
243
|
Debug.Log($"There is {activeSteps.Count} active steps at the moment.");
|
|
@@ -260,14 +265,22 @@ namespace jeanf.questsystem
|
|
|
260
265
|
{
|
|
261
266
|
if (isDebug) Debug.Log($"{searching} {_}/QuestInitialCheck in {searchLocation} ", this);
|
|
262
267
|
QuestInitialCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestInitialCheck");
|
|
263
|
-
if (
|
|
268
|
+
if (QuestInitialCheck == null)
|
|
264
269
|
{
|
|
265
270
|
errorMessages.Add($"{_}/QuestInitialCheck is not in {searchLocation} {readInstructions}");
|
|
266
271
|
validityCheck = false;
|
|
267
|
-
invalidObjects.Add(
|
|
272
|
+
invalidObjects.Add(QuestInitialCheck);
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
}
|
|
276
|
+
|
|
277
|
+
if (questSO == null)
|
|
278
|
+
{
|
|
279
|
+
if (isDebug) Debug.Log($"There is no questSO in the questItem");
|
|
280
|
+
validityCheck = false;
|
|
281
|
+
invalidObjects.Add(questSO);
|
|
282
|
+
}
|
|
283
|
+
|
|
271
284
|
|
|
272
285
|
if (QuestProgress == null)
|
|
273
286
|
{
|
|
@@ -282,6 +295,19 @@ namespace jeanf.questsystem
|
|
|
282
295
|
|
|
283
296
|
}
|
|
284
297
|
|
|
298
|
+
if (loadRequiredScenesEventChannel == null)
|
|
299
|
+
{
|
|
300
|
+
if (isDebug) Debug.Log($"{searching} {_}/loadRequiredScenesEventChannel in {searchLocation} ", this);
|
|
301
|
+
loadRequiredScenesEventChannel = Resources.Load<StringListEventChannelSO>($"{_}/LoadRequiredScenesEventChannel");
|
|
302
|
+
if (loadRequiredScenesEventChannel == null)
|
|
303
|
+
{
|
|
304
|
+
errorMessages.Add($"{_}/loadRequiredScenesEventChannel is not in {searchLocation} {readInstructions}");
|
|
305
|
+
validityCheck = false;
|
|
306
|
+
invalidObjects.Add(loadRequiredScenesEventChannel);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
}
|
|
310
|
+
|
|
285
311
|
if (requirementCheck == null)
|
|
286
312
|
{
|
|
287
313
|
if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
|
|
@@ -50,7 +50,7 @@ namespace jeanf.questsystem
|
|
|
50
50
|
{
|
|
51
51
|
GameEventsManager.instance.questEvents.onStartQuest += StartQuest;
|
|
52
52
|
GameEventsManager.instance.questEvents.onFinishQuest += FinishQuest;
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
//GameEventsManager.instance.questEvents.onQuestStepStateChange += QuestStepStateChange;
|
|
55
55
|
|
|
56
56
|
GameEventsManager.instance.playerEvents.onPlayerLevelChange += PlayerLevelChange;
|
|
@@ -20,7 +20,7 @@ namespace jeanf.questsystem
|
|
|
20
20
|
[Header("General")] public string displayName;
|
|
21
21
|
|
|
22
22
|
[Header("Custom messages init/finish")]
|
|
23
|
-
[SerializeField] public StringEventChannelSO messageChannel;
|
|
23
|
+
[SerializeField] public StringEventChannelSO messageChannel;
|
|
24
24
|
[SerializeField] public bool sendMessageOnInitialization = false;
|
|
25
25
|
[SerializeField] public string messageToSendOnInitialization = "";
|
|
26
26
|
[SerializeField] public bool sendMessageOnFinish = false;
|
|
@@ -31,7 +31,7 @@ namespace jeanf.questsystem
|
|
|
31
31
|
public List<string> ScenesToLoad = new List<string>();
|
|
32
32
|
public List<int> roomsToUnlock = new List<int>();
|
|
33
33
|
|
|
34
|
-
[Header("Steps")] public QuestStep[]
|
|
34
|
+
[Header("Steps")] public QuestStep[] rootSteps;
|
|
35
35
|
|
|
36
36
|
[Header("Rewards")] public string unlockedScenario;
|
|
37
37
|
|
|
@@ -4,6 +4,7 @@ using UnityEngine;
|
|
|
4
4
|
using UnityEngine.Playables;
|
|
5
5
|
using System.Collections.Generic;
|
|
6
6
|
using GraphProcessor;
|
|
7
|
+
using jeanf.validationTools;
|
|
7
8
|
|
|
8
9
|
namespace jeanf.questsystem
|
|
9
10
|
{
|
|
@@ -31,12 +32,13 @@ namespace jeanf.questsystem
|
|
|
31
32
|
public List<QuestStep> questStepsToTrigger = new List<QuestStep>();
|
|
32
33
|
public delegate void SendNextStepId(string id);
|
|
33
34
|
public static SendNextStepId sendNextStepId;
|
|
34
|
-
|
|
35
|
+
|
|
35
36
|
public delegate void StepCompleted(string id);
|
|
36
37
|
public static StepCompleted stepCompleted;
|
|
37
38
|
public delegate void StepActive(string id, QuestStepStatus stepStatus);
|
|
38
39
|
public static StepActive stepActive;
|
|
39
|
-
|
|
40
|
+
public delegate void ChildStep(QuestStep step);
|
|
41
|
+
public static ChildStep childStep;
|
|
40
42
|
|
|
41
43
|
[Header("Quest Tooltip")]
|
|
42
44
|
[SerializeField] private QuestTooltipSO questTooltipSO;
|
|
@@ -62,7 +64,7 @@ namespace jeanf.questsystem
|
|
|
62
64
|
stepStatus = QuestStepStatus.Active;
|
|
63
65
|
stepActive?.Invoke(stepId, stepStatus);
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
if (sendQuestStepTooltip != null)
|
|
67
69
|
{
|
|
68
70
|
DisplayActiveQuestStep();
|
|
@@ -72,6 +74,11 @@ namespace jeanf.questsystem
|
|
|
72
74
|
if (isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: true");
|
|
73
75
|
_timelineTriggerEventChannelSo.RaiseEvent(timeline, true);
|
|
74
76
|
}
|
|
77
|
+
|
|
78
|
+
foreach(QuestStep questStep in questStepsToTrigger)
|
|
79
|
+
{
|
|
80
|
+
childStep?.Invoke(questStep);
|
|
81
|
+
}
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
|
|
@@ -122,8 +129,10 @@ namespace jeanf.questsystem
|
|
|
122
129
|
stepId = $"{System.Guid.NewGuid()}";
|
|
123
130
|
UnityEditor.EditorUtility.SetDirty(this);
|
|
124
131
|
}
|
|
132
|
+
|
|
125
133
|
#endif
|
|
126
134
|
|
|
135
|
+
|
|
127
136
|
public bool isDebug { get; set; }
|
|
128
137
|
|
|
129
138
|
public QuestStepStatus GetStatus()
|