fr.jeanf.questsystem 0.0.20 → 0.0.22
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.
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
[ScriptableObjectDrawer]
|
|
10
10
|
public class QuestInfoSO : ScriptableObject
|
|
11
11
|
{
|
|
12
|
-
[field: Space(10)][field: ReadOnly] [
|
|
12
|
+
[field: Space(10)] [field: ReadOnly] [SerializeField] public string id = string.Empty;
|
|
13
13
|
|
|
14
14
|
[Header("General")] public string displayName;
|
|
15
15
|
|
|
@@ -2,7 +2,6 @@ using System;
|
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using jeanf.EventSystem;
|
|
4
4
|
using UnityEngine;
|
|
5
|
-
using UnityEngine.Serialization;
|
|
6
5
|
using jeanf.propertyDrawer;
|
|
7
6
|
using jeanf.validationTools;
|
|
8
7
|
|
|
@@ -37,18 +36,22 @@ namespace jeanf.questsystem
|
|
|
37
36
|
[Header("Listening on:")]
|
|
38
37
|
[SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
|
|
39
38
|
[SerializeField] [Validation("A reference to the StartQuestEventChannel SO is required")] private StringEventChannelSO StartQuestEventChannel;
|
|
39
|
+
[SerializeField] [Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
|
|
40
40
|
|
|
41
41
|
[Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
|
|
42
42
|
private StringEventChannelSO requirementCheck;
|
|
43
43
|
|
|
44
|
+
private void Awake()
|
|
45
|
+
{
|
|
46
|
+
questId = questInfoForPoint.id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#if UNITY_EDITOR
|
|
44
50
|
public void OnValidate()
|
|
45
51
|
{
|
|
46
|
-
#if UNITY_EDITOR
|
|
47
52
|
ValidityCheck();
|
|
48
|
-
#endif
|
|
49
|
-
|
|
50
|
-
questId = questInfoForPoint.id;
|
|
51
53
|
}
|
|
54
|
+
#endif
|
|
52
55
|
|
|
53
56
|
private void ValidityCheck()
|
|
54
57
|
{
|
|
@@ -62,6 +65,20 @@ namespace jeanf.questsystem
|
|
|
62
65
|
var invalidObjects = new List<object>();
|
|
63
66
|
var errorMessages = new List<string>();
|
|
64
67
|
|
|
68
|
+
|
|
69
|
+
if (QuestInitialCheck == null)
|
|
70
|
+
{
|
|
71
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestInitialCheck in {searchLocation} ", this);
|
|
72
|
+
QuestInitialCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestInitialCheck");
|
|
73
|
+
if (QuestProgress == null)
|
|
74
|
+
{
|
|
75
|
+
errorMessages.Add($"{_}/QuestInitialCheck is not in {searchLocation} {readInstructions}");
|
|
76
|
+
validityCheck = false;
|
|
77
|
+
invalidObjects.Add(QuestProgress);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
65
82
|
if (QuestProgress == null)
|
|
66
83
|
{
|
|
67
84
|
if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation} ", this);
|
|
@@ -101,9 +118,10 @@ namespace jeanf.questsystem
|
|
|
101
118
|
}
|
|
102
119
|
|
|
103
120
|
IsValid = validityCheck;
|
|
121
|
+
|
|
104
122
|
if(!IsValid) return;
|
|
105
|
-
|
|
106
123
|
if (IsValid && !Application.isPlaying) return;
|
|
124
|
+
|
|
107
125
|
for(var i = 0 ; i < invalidObjects.Count ; i++)
|
|
108
126
|
{
|
|
109
127
|
Debug.LogError($"Error: {errorMessages[i]} " , this.gameObject);
|
|
@@ -113,17 +131,30 @@ namespace jeanf.questsystem
|
|
|
113
131
|
private void OnEnable()
|
|
114
132
|
{
|
|
115
133
|
Subscribe();
|
|
134
|
+
|
|
135
|
+
Init(questId);
|
|
136
|
+
}
|
|
116
137
|
|
|
117
|
-
|
|
138
|
+
private void Init(string id)
|
|
139
|
+
{
|
|
140
|
+
|
|
141
|
+
Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
|
|
118
142
|
if (!_startQuestOnEnable) return;
|
|
119
143
|
RequestQuestStart(questId);
|
|
120
144
|
}
|
|
121
145
|
|
|
146
|
+
private void InitialCheckFromQuestManager( string id)
|
|
147
|
+
{
|
|
148
|
+
Debug.Log($"Initial check for quest with id: [{id}], it is in the following state: [{currentQuestState}]");
|
|
149
|
+
Init(id);
|
|
150
|
+
}
|
|
151
|
+
|
|
122
152
|
private void OnDisable() => Unsubscribe();
|
|
123
153
|
private void OnDestroy() => Unsubscribe();
|
|
124
154
|
|
|
125
155
|
private void Subscribe()
|
|
126
156
|
{
|
|
157
|
+
QuestInitialCheck.OnEventRaised += InitialCheckFromQuestManager;
|
|
127
158
|
StartQuestEventChannel.OnEventRaised += RequestQuestStart;
|
|
128
159
|
QuestProgress.OnEventRaised += UpdateProgress;
|
|
129
160
|
GameEventsManager.instance.questEvents.onQuestStateChange += QuestStateChange;
|
|
@@ -132,48 +163,54 @@ namespace jeanf.questsystem
|
|
|
132
163
|
|
|
133
164
|
private void Unsubscribe()
|
|
134
165
|
{
|
|
166
|
+
QuestInitialCheck.OnEventRaised -= InitialCheckFromQuestManager;
|
|
135
167
|
StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
|
|
136
168
|
QuestProgress.OnEventRaised -= UpdateProgress;
|
|
137
169
|
GameEventsManager.instance.questEvents.onQuestStateChange -= QuestStateChange;
|
|
138
170
|
GameEventsManager.instance.inputEvents.onSubmitPressed -= UpdateState;
|
|
139
171
|
}
|
|
140
172
|
|
|
141
|
-
|
|
173
|
+
private void UpdateState()
|
|
142
174
|
{
|
|
143
175
|
if (isDebug) Debug.Log($"Updating State...");
|
|
144
|
-
if (!clearToStart)
|
|
145
|
-
{
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
176
|
+
if (!clearToStart) return;
|
|
149
177
|
if (isDebug) Debug.Log($"All is clear, continuing ...");
|
|
150
178
|
|
|
151
|
-
|
|
152
|
-
{
|
|
153
|
-
if(isDebug) Debug.Log($"forcing start of quest: {questId}");
|
|
154
|
-
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// start or finish a quest
|
|
158
|
-
if (currentQuestState.Equals(QuestState.CAN_START))
|
|
159
|
-
{
|
|
160
|
-
if (isDebug) Debug.Log($"Starting quest: {questId}");
|
|
161
|
-
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
162
|
-
}
|
|
163
|
-
else if (currentQuestState.Equals(QuestState.CAN_FINISH))
|
|
179
|
+
switch (currentQuestState)
|
|
164
180
|
{
|
|
165
|
-
|
|
166
|
-
|
|
181
|
+
case QuestState.CAN_START:
|
|
182
|
+
{
|
|
183
|
+
if (isDebug) Debug.Log($"Starting quest: {questId}");
|
|
184
|
+
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case QuestState.CAN_FINISH:
|
|
188
|
+
{
|
|
189
|
+
if (isDebug) Debug.Log($"Finishing quest: {questId}");
|
|
190
|
+
GameEventsManager.instance.questEvents.FinishQuest(questId);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
case QuestState.REQUIREMENTS_NOT_MET:
|
|
194
|
+
if(_startQuestOnEnable)
|
|
195
|
+
{
|
|
196
|
+
if(isDebug) Debug.Log($"forcing start of quest: {questId}");
|
|
197
|
+
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
case QuestState.IN_PROGRESS:
|
|
201
|
+
break;
|
|
202
|
+
case QuestState.FINISHED:
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
throw new ArgumentOutOfRangeException();
|
|
167
206
|
}
|
|
168
207
|
}
|
|
169
208
|
|
|
170
209
|
private void UpdateProgress(string id, float progress)
|
|
171
210
|
{
|
|
172
|
-
if (id
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (isDebug) Debug.Log($"questid [{id}] progress = {progress * 100}%");
|
|
176
|
-
}
|
|
211
|
+
if (id != questId) return;
|
|
212
|
+
this.progress = progress;
|
|
213
|
+
if (isDebug) Debug.Log($"questid [{id}] progress = {progress * 100}%");
|
|
177
214
|
}
|
|
178
215
|
|
|
179
216
|
private void QuestStateChange(Quest quest)
|
|
@@ -187,15 +224,18 @@ namespace jeanf.questsystem
|
|
|
187
224
|
|
|
188
225
|
public void AllClear(bool value)
|
|
189
226
|
{
|
|
227
|
+
Debug.Log($"All clear for quest [{questId}], sending an update to the QuestManager");
|
|
190
228
|
clearToStart = value;
|
|
191
229
|
currentQuestState = QuestState.CAN_START;
|
|
192
230
|
requirementCheck.RaiseEvent(questId);
|
|
193
231
|
UpdateState();
|
|
194
232
|
}
|
|
195
233
|
|
|
196
|
-
|
|
234
|
+
private void RequestQuestStart(string id)
|
|
197
235
|
{
|
|
198
236
|
if(id!= questId) return;
|
|
237
|
+
|
|
238
|
+
Debug.Log($"Requesting start for quest [{id}]");
|
|
199
239
|
AllClear(true);
|
|
200
240
|
if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
|
|
201
241
|
}
|
|
@@ -25,6 +25,7 @@ namespace jeanf.questsystem
|
|
|
25
25
|
[Header("Broadcasting on:")]
|
|
26
26
|
[SerializeField] [Validation("A reference to the questStatusUpdateChannel is required.")] private StringEventChannelSO questStatusUpdateChannel;
|
|
27
27
|
[SerializeField] [Validation("A reference to the questProgress is required.")] private StringFloatEventChannelSO questProgress;
|
|
28
|
+
[SerializeField] [Validation("A reference to the questInitialCheck channel is required.")] private StringEventChannelSO QuestInitialCheck;
|
|
28
29
|
|
|
29
30
|
[Header("Listening on:")] [SerializeField] [Validation("A reference to the questStatusUpdateRequested is required.")] private StringEventChannelSO questStatusUpdateRequested;
|
|
30
31
|
|
|
@@ -36,6 +37,11 @@ namespace jeanf.questsystem
|
|
|
36
37
|
private void Awake()
|
|
37
38
|
{
|
|
38
39
|
questMap = CreateQuestMap();
|
|
40
|
+
|
|
41
|
+
foreach (var quest in questMap)
|
|
42
|
+
{
|
|
43
|
+
CheckIfQuestIsAlreadyLoaded(quest.Key);
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
private void OnEnable()
|
|
@@ -78,6 +84,11 @@ namespace jeanf.questsystem
|
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
|
|
87
|
+
private void CheckIfQuestIsAlreadyLoaded(string id)
|
|
88
|
+
{
|
|
89
|
+
QuestInitialCheck.RaiseEvent(id);
|
|
90
|
+
}
|
|
91
|
+
|
|
81
92
|
private void ChangeQuestState(string id, QuestState state)
|
|
82
93
|
{
|
|
83
94
|
Quest quest = GetQuestById(id);
|
|
@@ -199,19 +210,22 @@ namespace jeanf.questsystem
|
|
|
199
210
|
// loads all QuestInfoSO Scriptable Objects under the Assets/Resources/Quests folder
|
|
200
211
|
QuestInfoSO[] allQuests = Resources.LoadAll<QuestInfoSO>("Quests");
|
|
201
212
|
// Create the quest map
|
|
202
|
-
Dictionary<string, Quest>
|
|
213
|
+
Dictionary<string, Quest> questMap = new Dictionary<string, Quest>();
|
|
203
214
|
foreach (QuestInfoSO questInfo in allQuests)
|
|
204
215
|
{
|
|
205
|
-
|
|
216
|
+
var id = questInfo.id;
|
|
217
|
+
if (questMap.ContainsKey(id))
|
|
206
218
|
{
|
|
207
219
|
Debug.LogWarning("Duplicate ID found when creating quest map: " + questInfo.id);
|
|
208
220
|
}
|
|
209
|
-
|
|
210
|
-
|
|
221
|
+
else
|
|
222
|
+
{
|
|
223
|
+
questMap.Add(id, LoadQuest(questInfo));
|
|
224
|
+
}
|
|
211
225
|
if(isDebug) Debug.Log($"Adding {questInfo.name} to the questmap, its id is: {questInfo.id}");
|
|
212
226
|
}
|
|
213
227
|
|
|
214
|
-
return
|
|
228
|
+
return questMap;
|
|
215
229
|
}
|
|
216
230
|
|
|
217
231
|
private Quest GetQuestById(string id)
|
|
@@ -289,6 +303,18 @@ namespace jeanf.questsystem
|
|
|
289
303
|
var invalidObjects = new List<object>();
|
|
290
304
|
var errorMessages = new List<string>();
|
|
291
305
|
|
|
306
|
+
if (QuestInitialCheck == null)
|
|
307
|
+
{
|
|
308
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestInitialCheck in {searchLocation}", this);
|
|
309
|
+
QuestInitialCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestInitialCheck");
|
|
310
|
+
if (QuestInitialCheck == null)
|
|
311
|
+
{
|
|
312
|
+
errorMessages.Add($"{_}/QuestInitialCheck is not {searchLocation} {readInstructions}");
|
|
313
|
+
validityCheck = false;
|
|
314
|
+
invalidObjects.Add(QuestInitialCheck);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
292
318
|
if (questStatusUpdateChannel == null)
|
|
293
319
|
{
|
|
294
320
|
if (isDebug) Debug.Log($"{searching} {_}/QuestStatusUpdate in {searchLocation}", this);
|
|
@@ -50,19 +50,15 @@ namespace jeanf.questsystem
|
|
|
50
50
|
|
|
51
51
|
protected void FinishQuestStep()
|
|
52
52
|
{
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if(isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: false");
|
|
63
|
-
//_timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
53
|
+
if (isFinished) return;
|
|
54
|
+
isFinished = true;
|
|
55
|
+
if(questId != null) GameEventsManager.instance.questEvents.AdvanceQuest(questId);
|
|
56
|
+
if(this.gameObject) Destroy(this.gameObject);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (!isUsingIntroTimeline || !timeline) return;
|
|
60
|
+
//if(isDebug) Debug.Log($"sending trigger to timeline: {timeline.name}, triggerValue: false");
|
|
61
|
+
//_timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
|
|
66
62
|
}
|
|
67
63
|
|
|
68
64
|
protected void ChangeState(string newState)
|