fr.jeanf.questsystem 0.0.7 → 0.0.9
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,3 +1,4 @@
|
|
|
1
|
+
using System;
|
|
1
2
|
using jeanf.EventSystem;
|
|
2
3
|
using UnityEngine;
|
|
3
4
|
using UnityEngine.Serialization;
|
|
@@ -14,6 +15,7 @@ namespace jeanf.questsystem
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
[SerializeField] private bool _isDebug = false;
|
|
18
|
+
[SerializeField] private bool _startQuestOnEnable = false;
|
|
17
19
|
|
|
18
20
|
[Tooltip("Visual feedback for the quest state")] [Header("Quest")] [SerializeField]
|
|
19
21
|
private QuestInfoSO questInfoForPoint;
|
|
@@ -21,7 +23,7 @@ namespace jeanf.questsystem
|
|
|
21
23
|
[ReadOnly] [Range(0, 1)] [SerializeField]
|
|
22
24
|
private float progress = 0.0f;
|
|
23
25
|
|
|
24
|
-
[
|
|
26
|
+
[SerializeField] [ReadOnly]
|
|
25
27
|
private bool clearToStart = false;
|
|
26
28
|
|
|
27
29
|
private string questId;
|
|
@@ -32,6 +34,9 @@ namespace jeanf.questsystem
|
|
|
32
34
|
private StringFloatEventChannelSO QuestProgress;
|
|
33
35
|
private StringEventChannelSO StartQuestEventChannel;
|
|
34
36
|
|
|
37
|
+
[Header("Broadcasting on:")] [SerializeField]
|
|
38
|
+
private StringEventChannelSO requirementCheck;
|
|
39
|
+
|
|
35
40
|
public void OnValidate()
|
|
36
41
|
{
|
|
37
42
|
const string searching = "attempting to find";
|
|
@@ -59,6 +64,18 @@ namespace jeanf.questsystem
|
|
|
59
64
|
}
|
|
60
65
|
|
|
61
66
|
private void OnEnable()
|
|
67
|
+
{
|
|
68
|
+
Subscribe();
|
|
69
|
+
|
|
70
|
+
requirementCheck.RaiseEvent(questId);
|
|
71
|
+
if (!_startQuestOnEnable) return;
|
|
72
|
+
RequestQuestStart(questId);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private void OnDisable() => Unsubscribe();
|
|
76
|
+
private void OnDestroy() => Unsubscribe();
|
|
77
|
+
|
|
78
|
+
private void Subscribe()
|
|
62
79
|
{
|
|
63
80
|
StartQuestEventChannel.OnEventRaised += RequestQuestStart;
|
|
64
81
|
QuestProgress.OnEventRaised += UpdateProgress;
|
|
@@ -66,9 +83,6 @@ namespace jeanf.questsystem
|
|
|
66
83
|
GameEventsManager.instance.inputEvents.onSubmitPressed += UpdateState;
|
|
67
84
|
}
|
|
68
85
|
|
|
69
|
-
private void OnDisable() => Unsubscribe();
|
|
70
|
-
private void OnDestroy() => Unsubscribe();
|
|
71
|
-
|
|
72
86
|
private void Unsubscribe()
|
|
73
87
|
{
|
|
74
88
|
StartQuestEventChannel.OnEventRaised -= RequestQuestStart;
|
|
@@ -87,6 +101,12 @@ namespace jeanf.questsystem
|
|
|
87
101
|
|
|
88
102
|
if (isDebug) Debug.Log($"All is clear, continuing ...");
|
|
89
103
|
|
|
104
|
+
if (currentQuestState.Equals(QuestState.REQUIREMENTS_NOT_MET) && _startQuestOnEnable)
|
|
105
|
+
{
|
|
106
|
+
if(isDebug) Debug.Log($"forcing start of quest: {questId}");
|
|
107
|
+
GameEventsManager.instance.questEvents.StartQuest(questId);
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
// start or finish a quest
|
|
91
111
|
if (currentQuestState.Equals(QuestState.CAN_START))
|
|
92
112
|
{
|
|
@@ -121,6 +141,8 @@ namespace jeanf.questsystem
|
|
|
121
141
|
public void AllClear(bool value)
|
|
122
142
|
{
|
|
123
143
|
clearToStart = value;
|
|
144
|
+
currentQuestState = QuestState.CAN_START;
|
|
145
|
+
requirementCheck.RaiseEvent(questId);
|
|
124
146
|
UpdateState();
|
|
125
147
|
}
|
|
126
148
|
|
|
@@ -128,6 +150,7 @@ namespace jeanf.questsystem
|
|
|
128
150
|
{
|
|
129
151
|
if(id!= questId) return;
|
|
130
152
|
AllClear(true);
|
|
153
|
+
if(isDebug) Debug.Log($"Quest start was requested for quest {id}.", this);
|
|
131
154
|
}
|
|
132
155
|
}
|
|
133
156
|
}
|
|
@@ -24,6 +24,8 @@ namespace jeanf.questsystem
|
|
|
24
24
|
private StringEventChannelSO questStatusUpdateChannel;
|
|
25
25
|
private StringFloatEventChannelSO questProgress;
|
|
26
26
|
|
|
27
|
+
[Header("Listening on:")] [SerializeField] private StringEventChannelSO questStatusUpdateRequested;
|
|
28
|
+
|
|
27
29
|
private Dictionary<string, Quest> questMap;
|
|
28
30
|
|
|
29
31
|
// quest start requirements
|
|
@@ -43,6 +45,8 @@ namespace jeanf.questsystem
|
|
|
43
45
|
GameEventsManager.instance.questEvents.onQuestStepStateChange += QuestStepStateChange;
|
|
44
46
|
|
|
45
47
|
GameEventsManager.instance.playerEvents.onPlayerLevelChange += PlayerLevelChange;
|
|
48
|
+
|
|
49
|
+
questStatusUpdateRequested.OnEventRaised += ctx => CheckRequirementsMet(questMap[ctx]);
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
private void OnDisable()
|
|
@@ -97,6 +101,8 @@ namespace jeanf.questsystem
|
|
|
97
101
|
meetsRequirements = false;
|
|
98
102
|
}
|
|
99
103
|
}
|
|
104
|
+
|
|
105
|
+
if(isDebug) Debug.Log($"checking requirements for quest: {quest.info.name}, [{quest.info.id}], meetsRequirements: {meetsRequirements}");
|
|
100
106
|
|
|
101
107
|
return meetsRequirements;
|
|
102
108
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using jeanf.EventSystem;
|
|
3
|
+
using UnityEditor;
|
|
4
|
+
using UnityEngine;
|
|
2
5
|
|
|
3
6
|
namespace jeanf.questsystem
|
|
4
7
|
{
|
|
@@ -10,6 +13,7 @@ namespace jeanf.questsystem
|
|
|
10
13
|
{
|
|
11
14
|
if (onStartQuest != null)
|
|
12
15
|
{
|
|
16
|
+
Debug.Log($"starting quest: {id}");
|
|
13
17
|
onStartQuest(id);
|
|
14
18
|
}
|
|
15
19
|
}
|
|
@@ -20,6 +24,7 @@ namespace jeanf.questsystem
|
|
|
20
24
|
{
|
|
21
25
|
if (onAdvanceQuest != null)
|
|
22
26
|
{
|
|
27
|
+
Debug.Log($"advancing quest: {id}");
|
|
23
28
|
onAdvanceQuest(id);
|
|
24
29
|
}
|
|
25
30
|
}
|
|
@@ -30,6 +35,7 @@ namespace jeanf.questsystem
|
|
|
30
35
|
{
|
|
31
36
|
if (onFinishQuest != null)
|
|
32
37
|
{
|
|
38
|
+
Debug.Log($"finishing quest: {id}");
|
|
33
39
|
onFinishQuest(id);
|
|
34
40
|
}
|
|
35
41
|
}
|
|
@@ -40,6 +46,7 @@ namespace jeanf.questsystem
|
|
|
40
46
|
{
|
|
41
47
|
if (onQuestStateChange != null)
|
|
42
48
|
{
|
|
49
|
+
Debug.Log($"quest state change: {quest.info.id} -- state: {quest.state}");
|
|
43
50
|
onQuestStateChange(quest);
|
|
44
51
|
}
|
|
45
52
|
}
|
|
@@ -50,8 +57,10 @@ namespace jeanf.questsystem
|
|
|
50
57
|
{
|
|
51
58
|
if (onQuestStepStateChange != null)
|
|
52
59
|
{
|
|
60
|
+
Debug.Log($"quest step state change: {id} -- stepstate: {questStepState}");
|
|
53
61
|
onQuestStepStateChange(id, stepIndex, questStepState);
|
|
54
62
|
}
|
|
55
63
|
}
|
|
64
|
+
|
|
56
65
|
}
|
|
57
66
|
}
|