fr.jeanf.questsystem 0.0.46 → 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 +51 -32
- 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,34 +93,26 @@ 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
|
{
|
|
102
105
|
if (stepMap[id].stepStatus != QuestStepStatus.Inactive) return;
|
|
103
106
|
if (activeSteps.ContainsKey(id)) return;
|
|
104
107
|
if (!stepMap.ContainsKey(id)) return;
|
|
105
|
-
|
|
106
|
-
if(!activeSteps.ContainsKey(id)) activeSteps.Add(id,Instantiate(stepMap[id], this.transform, true));
|
|
107
|
-
}
|
|
108
108
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (activeSteps.ContainsKey(id))
|
|
112
|
-
{
|
|
113
|
-
//Destroy(activeSteps[id].gameObject);
|
|
114
|
-
}
|
|
109
|
+
Instantiate(stepMap[id], this.transform, true);
|
|
110
|
+
//if(!activeSteps.ContainsKey(id)) activeSteps.Add(id,Instantiate(stepMap[id], this.transform, true));
|
|
115
111
|
}
|
|
116
112
|
|
|
117
113
|
private void LoadDependencies()
|
|
118
114
|
{
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
loadRequiredScenesEventChannel.RaiseEvent(SceneToLoad);
|
|
122
|
-
}
|
|
115
|
+
loadRequiredScenesEventChannel.RaiseEvent(questSO.ScenesToLoad);
|
|
123
116
|
|
|
124
117
|
foreach (int roomToUnlock in questSO.roomsToUnlock)
|
|
125
118
|
{
|
|
@@ -149,6 +142,14 @@ namespace jeanf.questsystem
|
|
|
149
142
|
}
|
|
150
143
|
}
|
|
151
144
|
|
|
145
|
+
private void AddStepToStepMap(QuestStep step)
|
|
146
|
+
{
|
|
147
|
+
if (!stepMap.ContainsKey(step.StepId))
|
|
148
|
+
{
|
|
149
|
+
stepMap.Add(step.StepId, step);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
}
|
|
152
153
|
#region quest process
|
|
153
154
|
private void Init(string id)
|
|
154
155
|
{
|
|
@@ -164,12 +165,9 @@ namespace jeanf.questsystem
|
|
|
164
165
|
requirementCheck.RaiseEvent(questId);
|
|
165
166
|
UpdateState();
|
|
166
167
|
|
|
167
|
-
foreach (QuestStep step in
|
|
168
|
+
foreach (QuestStep step in rootSteps)
|
|
168
169
|
{
|
|
169
|
-
|
|
170
|
-
{
|
|
171
|
-
InstantiateQuestStep(step.StepId);
|
|
172
|
-
}
|
|
170
|
+
InstantiateQuestStep(step.StepId);
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
LoadDependencies();
|
|
@@ -236,10 +234,10 @@ namespace jeanf.questsystem
|
|
|
236
234
|
{
|
|
237
235
|
ValidityCheck();
|
|
238
236
|
}
|
|
239
|
-
|
|
237
|
+
|
|
240
238
|
|
|
241
239
|
|
|
242
|
-
|
|
240
|
+
|
|
243
241
|
public void LogActiveSteps()
|
|
244
242
|
{
|
|
245
243
|
Debug.Log($"There is {activeSteps.Count} active steps at the moment.");
|
|
@@ -267,14 +265,22 @@ namespace jeanf.questsystem
|
|
|
267
265
|
{
|
|
268
266
|
if (isDebug) Debug.Log($"{searching} {_}/QuestInitialCheck in {searchLocation} ", this);
|
|
269
267
|
QuestInitialCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestInitialCheck");
|
|
270
|
-
if (
|
|
268
|
+
if (QuestInitialCheck == null)
|
|
271
269
|
{
|
|
272
270
|
errorMessages.Add($"{_}/QuestInitialCheck is not in {searchLocation} {readInstructions}");
|
|
273
271
|
validityCheck = false;
|
|
274
|
-
invalidObjects.Add(
|
|
272
|
+
invalidObjects.Add(QuestInitialCheck);
|
|
275
273
|
}
|
|
276
274
|
|
|
277
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
|
+
|
|
278
284
|
|
|
279
285
|
if (QuestProgress == null)
|
|
280
286
|
{
|
|
@@ -289,6 +295,19 @@ namespace jeanf.questsystem
|
|
|
289
295
|
|
|
290
296
|
}
|
|
291
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
|
+
|
|
292
311
|
if (requirementCheck == null)
|
|
293
312
|
{
|
|
294
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()
|