fr.jeanf.questsystem 0.0.65 → 0.0.66

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/LICENSE.meta ADDED
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: bd20a8962b0dd7047b383ce038428904
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
package/README.md CHANGED
@@ -19,4 +19,8 @@ Credits:
19
19
  - I simply implemented this code in my package registry and tweaked it to my liking. Overtime I will add quite a lot of functionalities but for now I focus on making it work with my custom Event System.
20
20
 
21
21
  Contributors:
22
- [Code] Felix Cotes-Charlebois <a href="https://github.com/Percevent13">
22
+ [Code] Felix Cotes-Charlebois <a href="https://github.com/Percevent13">
23
+
24
+ LICENCE:
25
+
26
+ <img src="https://licensebuttons.net/l/by-nc-sa/3.0/88x31.png"></img>
@@ -25,21 +25,26 @@ namespace jeanf.questsystem
25
25
  #endregion
26
26
 
27
27
  #region Step Dictionaries
28
- [Tooltip("Visual feedback for the quest state")] [Header("Quest")]
29
- [SerializeField] [Validation("A reference to a questSO is required")] private QuestSO questSO;
28
+ [Tooltip("Visual feedback for the quest state")]
29
+ [Header("Quest")]
30
+ [SerializeField][Validation("A reference to a questSO is required")] private QuestSO questSO;
30
31
  private Dictionary<string, QuestStep> stepMap = new Dictionary<string, QuestStep>();
31
32
  private Dictionary<string, QuestStep> activeSteps = new Dictionary<string, QuestStep>();
32
33
  private Dictionary<string, QuestStep> completedSteps = new Dictionary<string, QuestStep>();
34
+ private Dictionary<string, QuestStep> stepsInScene = new Dictionary<string, QuestStep>();
33
35
  private List<QuestStep> rootSteps = new List<QuestStep>();
34
36
  #endregion
35
37
 
36
38
 
37
39
  #region main data
38
- [SerializeField] [ReadOnly]
40
+ [SerializeField]
41
+ [ReadOnly]
39
42
  private bool clearToStart = false;
40
43
  private string questId;
41
44
  private QuestState currentQuestState;
42
- [ReadOnly][Range(0, 1)][SerializeField]
45
+ [ReadOnly]
46
+ [Range(0, 1)]
47
+ [SerializeField]
43
48
  private float progress = 0.0f;
44
49
  #endregion
45
50
 
@@ -48,15 +53,19 @@ namespace jeanf.questsystem
48
53
  public static ValidateStep ValidateStepEvent;
49
54
  // these events are Located in Assets/Resources/Quests/Channels - it is searched for at Awake time.
50
55
  // if they do not exist simply right click in the hierarchy and find >InitializeQuestSystem<
51
- [Header("Listening on:")]
52
- [SerializeField] [Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
53
- [SerializeField] [Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
56
+ [Header("Listening on:")]
57
+ [SerializeField][Validation("A reference to the QuestProgress SO is required")] private StringFloatEventChannelSO QuestProgress;
58
+ [SerializeField][Validation("A reference to the QuestInitialCheck SO is required")] private StringEventChannelSO QuestInitialCheck;
54
59
  [SerializeField] private VoidEventChannelSO resetChannel;
55
60
 
56
- [Header("Broadcasting on:")] [SerializeField] [Validation("A reference to the QuestRequirementCheck SO is required")]
61
+ [Header("Broadcasting on:")]
62
+ [SerializeField]
63
+ [Validation("A reference to the QuestRequirementCheck SO is required")]
57
64
  private StringEventChannelSO requirementCheck;
58
- [SerializeField][Validation("A reference to the LoadRequiredScenesEventChannel SO is required")] StringListEventChannelSO loadRequiredScenesEventChannel;
65
+ [SerializeField][Validation("A reference to the LoadRequiredScenesEventChannel SO is required")] StringListEventChannelSO loadRequiredScenesEventChannel;
59
66
  [SerializeField] IntEventChannelSO unlockDoorsEventChannel;
67
+ [SerializeField] StringEventChannelSO startStepChannel;
68
+ [SerializeField] StringEventChannelSO endStepChannel;
60
69
  #endregion
61
70
 
62
71
 
@@ -66,7 +75,7 @@ namespace jeanf.questsystem
66
75
  questId = questSO.id;
67
76
  for (int i = 0; i < questSO.rootSteps.Length; i++)
68
77
  {
69
- if(isDebug) Debug.Log($"id on awake {questSO.rootSteps[i].StepId}, added to {this.name}'s dictionary", this);
78
+ if (isDebug) Debug.Log($"id on awake {questSO.rootSteps[i].StepId}, added to {this.name}'s dictionary", this);
70
79
  AddStepToStepMap(questSO.rootSteps[i]);
71
80
  rootSteps.Add(questSO.rootSteps[i]);
72
81
  }
@@ -93,6 +102,8 @@ namespace jeanf.questsystem
93
102
  QuestStep.sendNextStepId += InstantiateQuestStep;
94
103
  QuestStep.stepActive += UpdateStepStatus;
95
104
  QuestStep.childStep += AddStepToStepMap;
105
+ if (startStepChannel != null) startStepChannel.OnEventRaised += InstantiateQuestStep;
106
+ if (endStepChannel != null) endStepChannel.OnEventRaised += UnloadQuestStep;
96
107
  }
97
108
  private void Unsubscribe()
98
109
  {
@@ -104,7 +115,8 @@ namespace jeanf.questsystem
104
115
  QuestStep.sendNextStepId -= InstantiateQuestStep;
105
116
  QuestStep.stepActive -= UpdateStepStatus;
106
117
  QuestStep.childStep -= AddStepToStepMap;
107
-
118
+ if (startStepChannel != null) startStepChannel.OnEventRaised -= InstantiateQuestStep;
119
+ if (endStepChannel != null) endStepChannel.OnEventRaised -= UnloadQuestStep;
108
120
 
109
121
  }
110
122
  #endregion
@@ -116,9 +128,21 @@ namespace jeanf.questsystem
116
128
  if (stepMap[id].stepStatus != QuestStepStatus.Inactive) return;
117
129
  if (activeSteps.ContainsKey(id)) return;
118
130
 
131
+
132
+ QuestStep instantiatedStep = Instantiate(stepMap[id], this.transform, true);
133
+ stepsInScene.Add(id, instantiatedStep);
134
+ }
119
135
 
120
- Instantiate(stepMap[id], this.transform, true);
136
+ public void UnloadQuestStep(string id)
137
+ {
138
+ if (!stepMap.ContainsKey(id)) return;
139
+ if (stepMap[id].stepStatus != QuestStepStatus.Inactive) return;
140
+ if (!activeSteps.ContainsKey(id)) return;
121
141
 
142
+ activeSteps.Remove(id);
143
+ stepMap[id].stepStatus = QuestStepStatus.Inactive;
144
+ Destroy(stepsInScene[id].gameObject);
145
+ stepsInScene.Remove(id);
122
146
  }
123
147
  private void LoadDependencies()
124
148
  {
@@ -161,7 +185,7 @@ namespace jeanf.questsystem
161
185
  completedSteps.Clear();
162
186
  completedSteps.TrimExcess();
163
187
 
164
- if(isDebug) Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
188
+ if (isDebug) Debug.Log($"Quest [{id}]: _startQuestOnEnable value is: [{_startQuestOnEnable}]");
165
189
  if (!_startQuestOnEnable || id != questId) return;
166
190
  clearToStart = true;
167
191
  currentQuestState = QuestState.CAN_START;
@@ -204,21 +228,21 @@ namespace jeanf.questsystem
204
228
  switch (currentQuestState)
205
229
  {
206
230
  case QuestState.CAN_START:
207
- {
208
- if (isDebug) Debug.Log($"Starting quest: {questId}");
209
- GameEventsManager.instance.questEvents.StartQuest(questId);
210
- break;
211
- }
231
+ {
232
+ if (isDebug) Debug.Log($"Starting quest: {questId}");
233
+ GameEventsManager.instance.questEvents.StartQuest(questId);
234
+ break;
235
+ }
212
236
  case QuestState.CAN_FINISH:
213
- {
214
- if (isDebug) Debug.Log($"Finishing quest: {questId}");
215
- GameEventsManager.instance.questEvents.FinishQuest(questId);
216
- break;
217
- }
237
+ {
238
+ if (isDebug) Debug.Log($"Finishing quest: {questId}");
239
+ GameEventsManager.instance.questEvents.FinishQuest(questId);
240
+ break;
241
+ }
218
242
  case QuestState.REQUIREMENTS_NOT_MET:
219
- if(_startQuestOnEnable)
243
+ if (_startQuestOnEnable)
220
244
  {
221
- if(isDebug) Debug.Log($"forcing start of quest: {questId}");
245
+ if (isDebug) Debug.Log($"forcing start of quest: {questId}");
222
246
  GameEventsManager.instance.questEvents.StartQuest(questId);
223
247
  }
224
248
  break;
@@ -256,7 +280,7 @@ namespace jeanf.questsystem
256
280
  {
257
281
  var activeStep = activeSteps.ElementAt(i);
258
282
  var stepKey = activeStep.Key;
259
- if(activeSteps.ContainsKey(stepKey)) ValidateStepEvent.Invoke(stepKey);
283
+ if (activeSteps.ContainsKey(stepKey)) ValidateStepEvent.Invoke(stepKey);
260
284
  }
261
285
  }
262
286
  #endregion
@@ -276,7 +300,7 @@ namespace jeanf.questsystem
276
300
  Debug.Log($"active step: {step}");
277
301
  }
278
302
  }
279
- #endif
303
+ #endif
280
304
  private void ValidityCheck()
281
305
  {
282
306
  const string searching = "attempting to find";
@@ -302,7 +326,7 @@ namespace jeanf.questsystem
302
326
  }
303
327
 
304
328
  }
305
-
329
+
306
330
  if (questSO == null)
307
331
  {
308
332
  if (isDebug) Debug.Log($"There is no questSO in the questItem");
@@ -117,6 +117,10 @@ namespace jeanf.questsystem
117
117
  FinishQuestStep();
118
118
  }
119
119
 
120
+ public void AbortStep()
121
+ {
122
+ Destroy(this.gameObject);
123
+ }
120
124
  public void FinishQuestStep()
121
125
  {
122
126
  if(isDebug) Debug.Log($" ---- Step with id: {stepId} finished. Changing status to completed", this);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fr.jeanf.questsystem",
3
- "version": "0.0.65",
3
+ "version": "0.0.66",
4
4
  "displayName": "Quest system",
5
5
  "description": "This package uses Scriptable Objects to define quests.",
6
6
  "unity": "2021.3",