fr.jeanf.questsystem 0.0.8 → 0.0.10
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.
|
@@ -18,6 +18,8 @@ namespace jeanf.questsystem
|
|
|
18
18
|
var channelFolderPath = $"{questFolderPath}/{channelFolder}";
|
|
19
19
|
|
|
20
20
|
// files needed
|
|
21
|
+
var questStatusUpdate = "QuestStatusUpdate.asset";
|
|
22
|
+
var questRequirementCheck = "QuestRequirementCheck.asset";
|
|
21
23
|
var questProgressChannel = $"QuestsProgressChannel.asset";
|
|
22
24
|
var startQuestEventChannel = $"StartQuestEventChannel.asset";
|
|
23
25
|
|
|
@@ -30,22 +32,24 @@ namespace jeanf.questsystem
|
|
|
30
32
|
AssetDatabase.CreateFolder(questFolderPath, channelFolder);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
CreateStringEventFile(channelFolderPath, questStatusUpdate);
|
|
36
|
+
CreateStringEventFile(channelFolderPath, questRequirementCheck);
|
|
37
|
+
CreateStringEventFile(channelFolderPath, startQuestEventChannel);
|
|
38
|
+
CreateStringFloatEventFile(channelFolderPath, questProgressChannel);
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
public static void
|
|
41
|
+
public static void CreateStringEventFile(string path, string fileName)
|
|
38
42
|
{
|
|
39
|
-
if (File.Exists($"{path}/{
|
|
43
|
+
if (File.Exists($"{path}/{fileName}"))
|
|
40
44
|
{
|
|
41
|
-
Debug.Log($"file: [{path}/{
|
|
45
|
+
Debug.Log($"file: [{path}/{fileName}] was found.");
|
|
42
46
|
return;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
Debug.Log($"file: [{path}/{
|
|
49
|
+
Debug.Log($"file: [{path}/{fileName}] not found. Creating it for you.");
|
|
46
50
|
StringEventChannelSO asset = ScriptableObject.CreateInstance<StringEventChannelSO>();
|
|
47
51
|
|
|
48
|
-
AssetDatabase.CreateAsset(asset, $"{path}/{
|
|
52
|
+
AssetDatabase.CreateAsset(asset, $"{path}/{fileName}");
|
|
49
53
|
AssetDatabase.SaveAssets();
|
|
50
54
|
|
|
51
55
|
EditorUtility.FocusProjectWindow();
|
|
@@ -53,24 +57,25 @@ namespace jeanf.questsystem
|
|
|
53
57
|
Selection.activeObject = asset;
|
|
54
58
|
}
|
|
55
59
|
|
|
56
|
-
public static void
|
|
60
|
+
public static void CreateStringFloatEventFile(string path, string fileName)
|
|
57
61
|
{
|
|
58
|
-
if (File.Exists($"{path}/{
|
|
62
|
+
if (File.Exists($"{path}/{fileName}"))
|
|
59
63
|
{
|
|
60
|
-
Debug.Log($"file: [{path}/{
|
|
64
|
+
Debug.Log($"file: [{path}/{fileName}] was found.");
|
|
61
65
|
return;
|
|
62
66
|
}
|
|
63
67
|
|
|
64
|
-
Debug.Log($"file: [{path}/{
|
|
68
|
+
Debug.Log($"file: [{path}/{fileName}] not found. Creating it for you.");
|
|
65
69
|
StringFloatEventChannelSO asset = ScriptableObject.CreateInstance<StringFloatEventChannelSO>();
|
|
66
70
|
|
|
67
|
-
AssetDatabase.CreateAsset(asset, $"{path}/{
|
|
71
|
+
AssetDatabase.CreateAsset(asset, $"{path}/{fileName}");
|
|
68
72
|
AssetDatabase.SaveAssets();
|
|
69
73
|
|
|
70
74
|
EditorUtility.FocusProjectWindow();
|
|
71
75
|
|
|
72
76
|
Selection.activeObject = asset;
|
|
73
77
|
}
|
|
78
|
+
|
|
74
79
|
}
|
|
75
80
|
#endif
|
|
76
81
|
}
|
|
@@ -166,6 +166,8 @@ MonoBehaviour:
|
|
|
166
166
|
m_Name:
|
|
167
167
|
m_EditorClassIdentifier:
|
|
168
168
|
_isDebug: 1
|
|
169
|
+
_startQuestOnEnable: 0
|
|
169
170
|
questInfoForPoint: {fileID: 11400000, guid: b7b6381ae7b9c2244862b31a1ce5b2f5, type: 2}
|
|
170
171
|
progress: 0
|
|
171
172
|
clearToStart: 0
|
|
173
|
+
requirementCheck: {fileID: 0}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
2
3
|
using jeanf.EventSystem;
|
|
3
4
|
using UnityEngine;
|
|
4
5
|
using UnityEngine.Serialization;
|
|
5
6
|
using jeanf.propertyDrawer;
|
|
7
|
+
using jeanf.validationTools;
|
|
6
8
|
|
|
7
9
|
namespace jeanf.questsystem
|
|
8
10
|
{
|
|
9
|
-
public class QuestItem : MonoBehaviour, IDebugBehaviour
|
|
11
|
+
public class QuestItem : MonoBehaviour, IDebugBehaviour, IValidatable
|
|
10
12
|
{
|
|
11
13
|
public bool isDebug
|
|
12
14
|
{
|
|
13
15
|
get => _isDebug;
|
|
14
16
|
set => _isDebug = value;
|
|
15
17
|
}
|
|
18
|
+
public bool IsValid { get; private set; }
|
|
16
19
|
|
|
17
20
|
[SerializeField] private bool _isDebug = false;
|
|
18
21
|
[SerializeField] private bool _startQuestOnEnable = false;
|
|
@@ -31,36 +34,91 @@ namespace jeanf.questsystem
|
|
|
31
34
|
|
|
32
35
|
// these events are Located in Assets/Resources/Quests/Channels - it is searched for at Awake time.
|
|
33
36
|
// if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
|
|
34
|
-
|
|
35
|
-
private
|
|
37
|
+
[Header("Listening on:")]
|
|
38
|
+
[SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
|
|
39
|
+
[SerializeField] [Validation("A reference to the StartQuestEventChannel SO is required")] private StringEventChannelSO StartQuestEventChannel;
|
|
40
|
+
|
|
41
|
+
[Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
|
|
42
|
+
private StringEventChannelSO requirementCheck;
|
|
36
43
|
|
|
37
44
|
public void OnValidate()
|
|
45
|
+
{
|
|
46
|
+
#if UNITY_EDITOR
|
|
47
|
+
ValididtyCheck();
|
|
48
|
+
#endif
|
|
49
|
+
|
|
50
|
+
questId = questInfoForPoint.id;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private void ValididtyCheck()
|
|
38
54
|
{
|
|
39
55
|
const string searching = "attempting to find";
|
|
40
56
|
const string _ = "Quests/Channels"; // search target
|
|
41
57
|
const string searchLocation = "the resources folder";
|
|
42
58
|
const string readInstructions = "please read the package instruction for further help";
|
|
43
|
-
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
var validityCheck = true;
|
|
62
|
+
var invalidObjects = new List<object>();
|
|
63
|
+
var errorMessages = new List<string>();
|
|
64
|
+
|
|
44
65
|
if (QuestProgress == null)
|
|
45
66
|
{
|
|
46
67
|
if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation} ", this);
|
|
47
68
|
QuestProgress = Resources.Load<StringFloatEventChannelSO>($"{_}/QuestsProgressChannel");
|
|
48
69
|
if (QuestProgress == null)
|
|
49
|
-
|
|
70
|
+
{
|
|
71
|
+
errorMessages.Add($"{_}/QuestsProgressChannel is not in {searchLocation} {readInstructions}");
|
|
72
|
+
validityCheck = false;
|
|
73
|
+
invalidObjects.Add(QuestProgress);
|
|
74
|
+
}
|
|
75
|
+
|
|
50
76
|
}
|
|
51
77
|
|
|
52
78
|
if (StartQuestEventChannel == null)
|
|
53
79
|
{
|
|
54
80
|
if (isDebug) Debug.Log($"{searching} {_}/StartQuestEventChannel in {searchLocation}", this);
|
|
55
81
|
StartQuestEventChannel = Resources.Load<StringEventChannelSO>($"{_}/StartQuestEventChannel");
|
|
56
|
-
if (
|
|
57
|
-
|
|
82
|
+
if (StartQuestEventChannel == null)
|
|
83
|
+
{
|
|
84
|
+
errorMessages.Add($"{_}/StartQuestEventChannel is not {searchLocation} {readInstructions}");
|
|
85
|
+
validityCheck = false;
|
|
86
|
+
invalidObjects.Add(StartQuestEventChannel);
|
|
87
|
+
}
|
|
58
88
|
}
|
|
59
89
|
|
|
60
|
-
|
|
90
|
+
|
|
91
|
+
if (requirementCheck == null)
|
|
92
|
+
{
|
|
93
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
|
|
94
|
+
requirementCheck = Resources.Load<StringEventChannelSO>($"{_}/QuestRequirementCheck");
|
|
95
|
+
if (requirementCheck == null)
|
|
96
|
+
{
|
|
97
|
+
errorMessages.Add($"{_}/QuestRequirementCheck is not {searchLocation} {readInstructions}");
|
|
98
|
+
validityCheck = false;
|
|
99
|
+
invalidObjects.Add(requirementCheck);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
IsValid = validityCheck;
|
|
104
|
+
if(!IsValid) return;
|
|
105
|
+
|
|
106
|
+
if (IsValid && !Application.isPlaying) return;
|
|
107
|
+
for(var i = 0 ; i < invalidObjects.Count ; i++)
|
|
108
|
+
{
|
|
109
|
+
Debug.LogError($"Error: {errorMessages[i]} " , this.gameObject);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private void OnEnable()
|
|
114
|
+
{
|
|
115
|
+
Subscribe();
|
|
116
|
+
|
|
117
|
+
requirementCheck.RaiseEvent(questId);
|
|
118
|
+
if (!_startQuestOnEnable) return;
|
|
119
|
+
RequestQuestStart(questId);
|
|
61
120
|
}
|
|
62
121
|
|
|
63
|
-
private void OnEnable() => Subscribe();
|
|
64
122
|
private void OnDisable() => Unsubscribe();
|
|
65
123
|
private void OnDestroy() => Unsubscribe();
|
|
66
124
|
|
|
@@ -90,6 +148,12 @@ namespace jeanf.questsystem
|
|
|
90
148
|
|
|
91
149
|
if (isDebug) Debug.Log($"All is clear, continuing ...");
|
|
92
150
|
|
|
151
|
+
if (currentQuestState.Equals(QuestState.REQUIREMENTS_NOT_MET) && _startQuestOnEnable)
|
|
152
|
+
{
|
|
153
|
+
if(isDebug) Debug.Log($"forcing start of quest: {questId}");
|
|
154
|
+
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
155
|
+
}
|
|
156
|
+
|
|
93
157
|
// start or finish a quest
|
|
94
158
|
if (currentQuestState.Equals(QuestState.CAN_START))
|
|
95
159
|
{
|
|
@@ -118,15 +182,14 @@ namespace jeanf.questsystem
|
|
|
118
182
|
if (quest.info.id.Equals(questId))
|
|
119
183
|
{
|
|
120
184
|
currentQuestState = quest.state;
|
|
121
|
-
|
|
122
|
-
// start on enable option
|
|
123
|
-
if (_startQuestOnEnable && quest.state == QuestState.CAN_START) RequestQuestStart(quest.info.id);
|
|
124
185
|
}
|
|
125
186
|
}
|
|
126
187
|
|
|
127
188
|
public void AllClear(bool value)
|
|
128
189
|
{
|
|
129
190
|
clearToStart = value;
|
|
191
|
+
currentQuestState = QuestState.CAN_START;
|
|
192
|
+
requirementCheck.RaiseEvent(questId);
|
|
130
193
|
UpdateState();
|
|
131
194
|
}
|
|
132
195
|
|
|
@@ -136,5 +199,6 @@ namespace jeanf.questsystem
|
|
|
136
199
|
AllClear(true);
|
|
137
200
|
if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
|
|
138
201
|
}
|
|
202
|
+
|
|
139
203
|
}
|
|
140
204
|
}
|
|
@@ -2,27 +2,31 @@ using System;
|
|
|
2
2
|
using System.Collections;
|
|
3
3
|
using System.Collections.Generic;
|
|
4
4
|
using jeanf.EventSystem;
|
|
5
|
+
using jeanf.validationTools;
|
|
5
6
|
using UnityEngine;
|
|
6
7
|
using UnityEngine.Serialization;
|
|
7
8
|
|
|
8
9
|
namespace jeanf.questsystem
|
|
9
10
|
{
|
|
10
|
-
public class QuestManager : MonoBehaviour, IDebugBehaviour
|
|
11
|
+
public class QuestManager : MonoBehaviour, IDebugBehaviour, IValidatable
|
|
11
12
|
{
|
|
12
13
|
public bool isDebug
|
|
13
14
|
{
|
|
14
15
|
get => _isDebug;
|
|
15
16
|
set => _isDebug = value;
|
|
16
17
|
}
|
|
18
|
+
public bool IsValid { get; private set; }
|
|
17
19
|
|
|
18
20
|
[SerializeField] private bool _isDebug = false;
|
|
19
21
|
|
|
20
22
|
[FormerlySerializedAs("loadQuestState")] [Header("Config")] [SerializeField]
|
|
21
23
|
private bool loadSavedQuestState = true;
|
|
22
24
|
|
|
23
|
-
[Header("Broadcasting on:")]
|
|
24
|
-
private StringEventChannelSO questStatusUpdateChannel;
|
|
25
|
-
private StringFloatEventChannelSO questProgress;
|
|
25
|
+
[Header("Broadcasting on:")]
|
|
26
|
+
[SerializeField] [Validation("A reference to the questStatusUpdateChannel is required.")] private StringEventChannelSO questStatusUpdateChannel;
|
|
27
|
+
[SerializeField] [Validation("A reference to the questProgress is required.")] private StringFloatEventChannelSO questProgress;
|
|
28
|
+
|
|
29
|
+
[Header("Listening on:")] [SerializeField] [Validation("A reference to the questStatusUpdateRequested is required.")] private StringEventChannelSO questStatusUpdateRequested;
|
|
26
30
|
|
|
27
31
|
private Dictionary<string, Quest> questMap;
|
|
28
32
|
|
|
@@ -43,6 +47,8 @@ namespace jeanf.questsystem
|
|
|
43
47
|
GameEventsManager.instance.questEvents.onQuestStepStateChange += QuestStepStateChange;
|
|
44
48
|
|
|
45
49
|
GameEventsManager.instance.playerEvents.onPlayerLevelChange += PlayerLevelChange;
|
|
50
|
+
|
|
51
|
+
questStatusUpdateRequested.OnEventRaised += ctx => CheckRequirementsMet(questMap[ctx]);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
private void OnDisable()
|
|
@@ -97,6 +103,8 @@ namespace jeanf.questsystem
|
|
|
97
103
|
meetsRequirements = false;
|
|
98
104
|
}
|
|
99
105
|
}
|
|
106
|
+
|
|
107
|
+
if(isDebug) Debug.Log($"checking requirements for quest: {quest.info.name}, [{quest.info.id}], meetsRequirements: {meetsRequirements}");
|
|
100
108
|
|
|
101
109
|
return meetsRequirements;
|
|
102
110
|
}
|
|
@@ -269,5 +277,68 @@ namespace jeanf.questsystem
|
|
|
269
277
|
|
|
270
278
|
return quest;
|
|
271
279
|
}
|
|
280
|
+
private void ValididtyCheck()
|
|
281
|
+
{
|
|
282
|
+
const string searching = "attempting to find";
|
|
283
|
+
const string _ = "Quests/Channels"; // search target
|
|
284
|
+
const string searchLocation = "the resources folder";
|
|
285
|
+
const string readInstructions = "please read the package instruction for further help";
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
var validityCheck = true;
|
|
289
|
+
var invalidObjects = new List<object>();
|
|
290
|
+
var errorMessages = new List<string>();
|
|
291
|
+
|
|
292
|
+
if (questStatusUpdateChannel == null)
|
|
293
|
+
{
|
|
294
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestStatusUpdate in {searchLocation}", this);
|
|
295
|
+
questStatusUpdateChannel = Resources.Load<StringEventChannelSO>($"{_}/QuestStatusUpdate");
|
|
296
|
+
if (questStatusUpdateChannel == null)
|
|
297
|
+
{
|
|
298
|
+
errorMessages.Add($"{_}/QuestStatusUpdate is not {searchLocation} {readInstructions}");
|
|
299
|
+
validityCheck = false;
|
|
300
|
+
invalidObjects.Add(questStatusUpdateChannel);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (questProgress == null)
|
|
305
|
+
{
|
|
306
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestsProgressChannel in {searchLocation}", this);
|
|
307
|
+
questProgress = Resources.Load<StringFloatEventChannelSO>($"{_}/QuestsProgressChannel");
|
|
308
|
+
if (questProgress == null)
|
|
309
|
+
{
|
|
310
|
+
errorMessages.Add($"{_}/QuestsProgressChannel is not {searchLocation} {readInstructions}");
|
|
311
|
+
validityCheck = false;
|
|
312
|
+
invalidObjects.Add(questProgress);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
if (questStatusUpdateRequested == null)
|
|
317
|
+
{
|
|
318
|
+
if (isDebug) Debug.Log($"{searching} {_}/QuestRequirementCheck in {searchLocation}", this);
|
|
319
|
+
questStatusUpdateRequested = Resources.Load<StringEventChannelSO>($"{_}/QuestRequirementCheck");
|
|
320
|
+
if (questStatusUpdateRequested == null)
|
|
321
|
+
{
|
|
322
|
+
errorMessages.Add($"{_}/QuestRequirementCheck is not {searchLocation} {readInstructions}");
|
|
323
|
+
validityCheck = false;
|
|
324
|
+
invalidObjects.Add(questStatusUpdateRequested);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
IsValid = validityCheck;
|
|
329
|
+
if(!IsValid) return;
|
|
330
|
+
|
|
331
|
+
if (IsValid && !Application.isPlaying) return;
|
|
332
|
+
for(var i = 0 ; i < invalidObjects.Count ; i++)
|
|
333
|
+
{
|
|
334
|
+
Debug.LogError($"Error: {errorMessages[i]} " , this.gameObject);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
public void OnValidate()
|
|
338
|
+
{
|
|
339
|
+
#if UNITY_EDITOR
|
|
340
|
+
ValididtyCheck();
|
|
341
|
+
#endif
|
|
342
|
+
}
|
|
272
343
|
}
|
|
273
344
|
}
|