fr.jeanf.questsystem 0.0.4 → 0.0.5

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.
@@ -1,5 +1,7 @@
1
1
  using System.Collections;
2
2
  using System.Collections.Generic;
3
+ using jeanf.EventSystem;
4
+ using jeanf.propertyDrawer;
3
5
  using UnityEngine;
4
6
 
5
7
  namespace jeanf.questsystem
@@ -14,6 +16,11 @@ namespace jeanf.questsystem
14
16
  private int currentQuestStepIndex;
15
17
  public int currentStep;
16
18
  private QuestStepState[] questStepStates;
19
+ public StringEventChannelSO messageChannel;
20
+ public bool sendMessageOnInitialization = false;
21
+ public string messageToSendOnInit = "";
22
+ public bool sendMessageOnFinish = false;
23
+ public string messageToSendOnFinish = "";
17
24
 
18
25
  public Quest(QuestInfoSO questInfo)
19
26
  {
@@ -21,6 +28,13 @@ namespace jeanf.questsystem
21
28
  this.state = QuestState.REQUIREMENTS_NOT_MET;
22
29
  this.currentQuestStepIndex = currentStep = 0;
23
30
  this.questStepStates = new QuestStepState[info.questStepPrefabs.Length];
31
+ this.messageChannel = questInfo.messageChannel;
32
+ //init
33
+ this.sendMessageOnInitialization = questInfo.sendMessageOnInitialization;
34
+ this.messageToSendOnInit = questInfo.messageToSendOnInitialization;
35
+ //finish
36
+ this.sendMessageOnFinish = questInfo.sendMessageOnFinish;
37
+ this.messageToSendOnFinish = questInfo.messageToSendOnFinish;
24
38
  for (int i = 0; i < questStepStates.Length; i++)
25
39
  {
26
40
  questStepStates[i] = new QuestStepState();
@@ -47,6 +61,7 @@ namespace jeanf.questsystem
47
61
  }
48
62
  }
49
63
 
64
+
50
65
  public void MoveToNextStep()
51
66
  {
52
67
  currentQuestStepIndex++;
@@ -1,6 +1,5 @@
1
- using System.Collections;
2
- using System.Collections.Generic;
3
- using UnityEngine;
1
+ using jeanf.EventSystem;
2
+ using UnityEngine;
4
3
  using jeanf.propertyDrawer;
5
4
 
6
5
  namespace jeanf.questsystem
@@ -9,9 +8,16 @@ using UnityEngine;
9
8
  [ScriptableObjectDrawer]
10
9
  public class QuestInfoSO : ScriptableObject
11
10
  {
12
- [field: SerializeField] public string id { get; private set; }
11
+ public string id { get; private set; }
13
12
 
14
13
  [Header("General")] public string displayName;
14
+
15
+ [Header("Custom messages init/finish")]
16
+ [SerializeField] public StringEventChannelSO messageChannel;
17
+ [SerializeField] public bool sendMessageOnInitialization = false;
18
+ [SerializeField] public string messageToSendOnInitialization = "";
19
+ [SerializeField] public bool sendMessageOnFinish = false;
20
+ [SerializeField] public string messageToSendOnFinish = "";
15
21
 
16
22
  [Header("Requirements")] public int levelRequirement;
17
23
  public QuestInfoSO[] questPrerequisites;
@@ -1,3 +1,4 @@
1
+ using System;
1
2
  using System.Collections;
2
3
  using System.Collections.Generic;
3
4
  using jeanf.EventSystem;
@@ -21,8 +22,6 @@ namespace jeanf.questsystem
21
22
 
22
23
  [Header("Broadcasting on:")] [SerializeField]
23
24
  private StringEventChannelSO questStatusUpdateChannel;
24
-
25
- [Header("Broadcasting on:")] [SerializeField]
26
25
  private StringFloatEventChannelSO questProgress;
27
26
 
28
27
  private Dictionary<string, Quest> questMap;
@@ -121,6 +120,9 @@ namespace jeanf.questsystem
121
120
  quest.InstantiateCurrentQuestStep(this.transform);
122
121
  ChangeQuestState(quest.info.id, QuestState.IN_PROGRESS);
123
122
  SaveQuest(quest);
123
+ if (!quest.sendMessageOnInitialization) return;
124
+ quest.messageChannel.RaiseEvent(quest.messageToSendOnInit);
125
+ if(isDebug) Debug.Log($"quest id:{id} started, a message was attatched to the initialization: {quest.messageToSendOnInit}");
124
126
  }
125
127
 
126
128
  private void AdvanceQuest(string id)
@@ -135,13 +137,12 @@ namespace jeanf.questsystem
135
137
  this);
136
138
  questStatusUpdateChannel.RaiseEvent(
137
139
  $"[{quest.info.id}]quest state: {quest.state} - {quest.currentStep} over {quest.info.questStepPrefabs.Length} steps done");
138
- var progress = (float)quest.currentStep / quest.info.questStepPrefabs.Length;
139
- if (isDebug) Debug.Log($"[{quest.info.id}] progress: {progress * 100}%", this);
140
- questProgress.RaiseEvent(quest.info.id, progress);
141
140
 
141
+
142
142
  // if there are more steps, instantiate the next one
143
143
  if (quest.CurrentStepExists())
144
144
  {
145
+ UpdateProgress(quest);
145
146
  quest.InstantiateCurrentQuestStep(this.transform);
146
147
  }
147
148
  // if there are no more steps, then we've finished all of them for this quest
@@ -153,14 +154,24 @@ namespace jeanf.questsystem
153
154
  SaveQuest(quest);
154
155
  }
155
156
 
157
+ private void UpdateProgress(Quest quest)
158
+ {
159
+ var progress = (float)quest.currentStep / quest.info.questStepPrefabs.Length;
160
+ if (quest.info.id == null) Debug.Log("C'est null");;
161
+ if (isDebug) Debug.Log($"[{quest.info.id}] progress: {progress * 100}%", this);
162
+ questProgress.RaiseEvent(quest.info.id, progress);
163
+ }
164
+
156
165
  private void FinishQuest(string id)
157
166
  {
158
167
  Quest quest = GetQuestById(id);
168
+ UpdateProgress(quest);
159
169
  ClaimRewards(quest);
160
170
  ChangeQuestState(quest.info.id, QuestState.FINISHED);
161
171
  questStatusUpdateChannel.RaiseEvent($"[{quest.info.id}] quest is finished.");
162
172
  questProgress.RaiseEvent(quest.info.id, 1);
163
173
  SaveQuest(quest);
174
+ if (!quest.sendMessageOnFinish) return;
164
175
  }
165
176
 
166
177
  private void ClaimRewards(Quest quest)
@@ -1,9 +1,7 @@
1
- using System.Collections;
2
- using System.Collections.Generic;
3
1
  using jeanf.EventSystem;
4
2
  using jeanf.propertyDrawer ;
5
3
  using UnityEngine;
6
- using jeanf.propertyDrawer;
4
+ using UnityEngine.Playables;
7
5
 
8
6
  namespace jeanf.questsystem
9
7
  {
@@ -13,9 +11,15 @@ namespace jeanf.questsystem
13
11
  private string questId;
14
12
  private int stepIndex;
15
13
  private float questStepProgress = 0;
14
+
15
+ [Tooltip("This boolean has to be enabled if the quest step has an intro timeline.")]
16
+ public bool isUsingIntroTimeline = false;
17
+
18
+ [DrawIf("isUsingIntroTimeline", true, ComparisonType.Equals, DisablingType.DontDraw)]
19
+ [SerializeField] private TimelineTriggerEventChannelSO _timelineTriggerEventChannelSo;
20
+ [DrawIf("isUsingIntroTimeline", true, ComparisonType.Equals, DisablingType.DontDraw)]
21
+ [SerializeField] private PlayableAsset timeline;
16
22
 
17
- [SerializeField] private bool sendEventOnInit = false;
18
- //[DrawIf("sendEventOnInit", true, ComparisonType.Equals)]
19
23
 
20
24
  public void InitializeQuestStep(string questId, int stepIndex, string questStepState)
21
25
  {
@@ -25,6 +29,11 @@ namespace jeanf.questsystem
25
29
  {
26
30
  SetQuestStepState(questStepState);
27
31
  }
32
+
33
+ if (isUsingIntroTimeline && timeline)
34
+ {
35
+ _timelineTriggerEventChannelSo.RaiseEvent(timeline, true);
36
+ }
28
37
  }
29
38
 
30
39
  protected void FinishQuestStep()
@@ -34,6 +43,12 @@ namespace jeanf.questsystem
34
43
  isFinished = true;
35
44
  GameEventsManager.instance.questEvents.AdvanceQuest(questId);
36
45
  Destroy(this.gameObject);
46
+
47
+
48
+ if (isUsingIntroTimeline && timeline)
49
+ {
50
+ _timelineTriggerEventChannelSo.RaiseEvent(timeline, false);
51
+ }
37
52
  }
38
53
  }
39
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name":"fr.jeanf.questsystem",
3
- "version":"0.0.4",
3
+ "version":"0.0.5",
4
4
  "displayName":"Quest system",
5
5
  "description":"This package uses Scriptable Objects to define quests.",
6
6
  "unity": "2021.3",
@@ -14,7 +14,7 @@
14
14
  "url":"https://jeanfrancoisrobin.art"
15
15
  },
16
16
  "dependencies": {
17
- "fr.jeanf.propertydrawer": "1.1.1"
17
+ "fr.jeanf.propertydrawer": "1.1.6"
18
18
  },
19
19
  "samples": [
20
20