Payback 0.0.1
CK Graduation Project
로딩중...
검색중...
일치하는것 없음
StageSubsystem.h
이 파일의 문서화 페이지로 가기
1#pragma once
2#include "CK_UE.h"
9#include "Subsystems/WorldSubsystem.h"
10#include "UObject/ScriptInterface.h"
11#include "StageSubsystem.generated.h"
12
13
14struct TargetableQuery;
16struct FStoryboardEntry;
17class AEncounterField;
19class UStageSubsystem;
24
25DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEnemyRemainingCountChanged, int32, RemainingCount);
26
27DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnWaveManagerReadyToSpawning, const FWaveDataCollection&, WaveDataCollection);
28
29DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnWaveStarted, const FWaveDataCollection&, WaveDataCollection, const int32, CurrentWaveIndex);
30
31DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnWaveCleared, const FWaveDataCollection&, WaveDataCollection, const int32, ClearedWaveIndex, const int32, NextWaveIndex);
32
33
34USTRUCT(BlueprintType)
36{
37 GENERATED_BODY()
38
39public:
41 {
42 CurrentWaveRemainingEnemyCount += FMath::Max(Count, 0);
43 }
44
46 {
47 CurrentWaveRemainingEnemyCount = FMath::Max(CurrentWaveRemainingEnemyCount - FMath::Max(Count, 0), 0);
48 }
49
50 void SetCurrentStageID(const FName InStageID)
51 {
52 CurrentStageID = InStageID;
53 }
54
55 void SetNextWaveCountdownEndTime(const float InEndTime)
56 {
57 NextWaveCountdownEndTime = InEndTime;
58 }
59
60 void SetCurrentWaveRemainingEnemyCount(const int32 Count)
61 {
62 CurrentWaveRemainingEnemyCount = FMath::Max(Count, 0);
63 }
64
65 void Reset()
66 {
67 CurrentStageID = NAME_None;
68 NextWaveCountdownEndTime = 0.0f;
69 CurrentWaveRemainingEnemyCount = 0;
70 }
71
72public:
73 FORCEINLINE FName GetCurrentStageID() const
74 {
75 return CurrentStageID;
76 }
77
78 FORCEINLINE float GetNextWaveCountdownEndTime() const
79 {
80 return NextWaveCountdownEndTime;
81 }
82
83 FORCEINLINE int32 GetCurrentWaveRemainingEnemyCount() const
84 {
85 return CurrentWaveRemainingEnemyCount;
86 }
87
88private:
89 UPROPERTY(Transient)
90 FName CurrentStageID = NAME_None;
91
92 UPROPERTY(Transient)
93 float NextWaveCountdownEndTime = 0.f;
94
95 UPROPERTY(Transient)
96 int32 CurrentWaveRemainingEnemyCount = 0;
97};
98
99
100UCLASS()
101class CK_UE_API UStageSubsystem : public UWorldSubsystem, public IStreamingEventListenerInterface
102{
103 GENERATED_BODY()
104
105public:
106 virtual void Deinitialize() override;
107 virtual void OnLevelLoaded(ULevel* NewLevel, const ULevelStreamingData* LevelStreamingData) override;
108 virtual void OnLevelUnloaded() override;
109 virtual void OnLevelStreamingStarted() override { }
110 virtual void OnLevelStreamingEnded() override { }
111
112 void SetCurrentWaveRemainingEnemyCount(int32 Count);
113 void IncreaseCurrentWaveRemainingEnemyCount(int32 Count);
114 void DecreaseCurrentWaveRemainingEnemyCount(int32 Count = 1);
115 void RegisterEncounterField(AEncounterField* EncounterField);
116 void UnregisterEncounterField(const AEncounterField* EncounterField);
117 void NotifyNextWaveCountdownStarted(float Duration);
118 void NotifyNextWaveCountdownStopped();
119
120 ASpawnHub* GetOrCreateSpawnHub();
121 TargetableQuery GetStageTargetableQueryHandle() const;
122
123 // BP는 int8 핀을 지원하지 않으므로 입력만 int32로 받고 저장은 int8로 한다.
124 UFUNCTION(BlueprintCallable, Category = "StageEvent", meta = (AutoCreateRefTerm = "ListeningTags,ListenerContext"))
125 FGuid RegisterListener
126 (
127 const TScriptInterface<IStageEventListenerInterface>& Listener,
128 const TArray<FName>& ListeningEventIDs,
129 const FGameplayTagContainer& ListeningTags,
130 int32 Priority = 0,
131 const FInstancedStruct& ListenerContext = FInstancedStruct()
132 );
133
134 UFUNCTION(BlueprintCallable, Category = "StageEvent")
135 void UnregisterListener(FGuid SubscriptionHandle);
136
137 UFUNCTION(BlueprintCallable, Category = "StageEvent")
138 void UnregisterListeners(const TScriptInterface<IStageEventListenerInterface>& Listener);
139
140 UFUNCTION(BlueprintCallable, Category = "StageEvent")
141 void DispatchStageEvent(const FStageEventMessage& Message, const AActor* Caller = nullptr);
142
143 void ProcessStageEventProcessor(UStageEventProcessor* Processor, const FStageEventMessage& Message, const FGameplayTag& CommonEventTag);
144
145 int32 GetProcessorTriggerCount(const UStageEventProcessor* Processor) const;
146 int32 IncrementProcessorTriggerCount(const UStageEventProcessor* Processor);
147 int32 DecrementProcessorTriggerCount(const UStageEventProcessor* Processor);
148 void NotifyProcessorTriggered(const FName EventID, const AActor* Caller, const UStageEventProcessor* Processor);
149
150 FName GetLastPlayerTriggeredEventID() const;
151 bool RollbackLastPlayerTriggeredProcessorCounts(const FName EventID);
152
153public:
154 // 등록된 EncounterField의 활성 웨이브 인덱스. 활성 웨이브가 없으면 INDEX_NONE.
155 UFUNCTION(BlueprintPure, Category = "Stage")
156 int32 CurrentWaveIndex() const;
157
158 // 등록된 EncounterField의 활성 웨이브 ID. 활성 웨이브가 없으면 NAME_None.
159 UFUNCTION(BlueprintPure, Category = "Stage")
160 FName GetWaveID() const;
161
162 UFUNCTION(BlueprintPure, Category = "Stage|Enemy")
163 int32 GetTotalSpawnRemainingCount() const;
164
165 UFUNCTION(BlueprintPure, Category = "Stage|Enemy")
166 int32 GetCurrentWaveRemainingEnemyCount() const;
167
168 UFUNCTION(BlueprintPure, Category = "Stage|Enemy")
169 int32 GetSpawnedEnemyCount() const;
170
171 UFUNCTION(BlueprintCallable, Category = "Stage|Enemy")
172 void NotifyEnemyRemainingCountChanged();
173
174 UFUNCTION(BlueprintPure, Category = "Stage|Wave")
175 float GetNextWaveCountdownRemainingTime() const;
176
177 UFUNCTION(BlueprintPure, Category = "Stage|Wave")
178 bool IsNextWaveCountdownActive() const;
179
180public:
181 UFUNCTION(BlueprintCallable, Category = "StageEvent")
182 void ResetProcessorTriggerCount(UStageEventProcessor* Processor);
183
184 UFUNCTION(BlueprintCallable, Category = "StageEvent")
185 void ResetAllProcessorTriggerCounts();
186
187public:
188 UFUNCTION(BlueprintPure, Category = "Stage")
189 FORCEINLINE ASpawnHub* GetSpawnHub() const
190 {
191 return SpawnHub;
192 }
193
194 UFUNCTION(BlueprintPure, Category = "Stage")
195 FORCEINLINE FName GetCurrentStageID() const
196 {
197 return StageProgress.GetCurrentStageID();
198 }
199
200public:
201 template <CSpawnSystem TSpawnSystem>
202 TSpawnSystem* GetOrCreateSpawnSystem();
203
204private:
205 bool EnsureStageDictionaryLoaded();
206 const FStoryboardEntry* ResolveEntry(const FName EventID) const;
207 const UStoryboardDefinition* ResolveStoryboard() const;
208 bool IsPlayerEventCaller(const AActor* Caller) const;
209 void NotifyStageEventListeners(const FStageEventMessage& Event, const TArray<FStageEventSubscription>& Subscriptions);
210 TArray<FStageEventSubscription> GatherListeners(const FStageEventMessage& Message);
211
212public:
213 UPROPERTY(BlueprintAssignable, Category = "Wave")
214 FOnWaveManagerReadyToSpawning ReadyToSpawn;
215
216 UPROPERTY(BlueprintAssignable, Category = "Wave")
217 FOnWaveStarted OnWaveStarted;
218
219 UPROPERTY(BlueprintAssignable, Category = "Wave")
220 FOnWaveCleared OnWaveCleared;
221
222 UPROPERTY(BlueprintAssignable, Category = "Enemy")
223 FOnSpawnedEnemyKilled OnSpawnedEnemyKilled;
224
225 UPROPERTY(BlueprintAssignable, Category = "Enemy")
226 FOnEnemyRemainingCountChanged OnEnemyRemainingCountChanged;
227
228protected:
229 UPROPERTY(Transient)
230 TObjectPtr<ASpawnHub> SpawnHub;
231
232private:
233 UPROPERTY(Transient)
234 TWeakObjectPtr<AEncounterField> ActiveEncounterField;
235
236 UPROPERTY(Transient)
237 FStageProgressState StageProgress;
238
239 UPROPERTY(Transient)
240 TObjectPtr<UStageDictionary> CachedStageDictionary;
241
242 TArray<TWeakObjectPtr<const UStageEventProcessor>> LastPlayerTriggeredProcessors;
243 TMap<TWeakObjectPtr<const UStageEventProcessor>, int32> ProcessorTriggerCounts;
244 UPROPERTY(Transient)
245 TArray<FStageEventSubscription> ListenerSubscriptions;
246
247 FName LastPlayerTriggeredEventID = NAME_None;
248 int32 PlayerTriggeredDispatchSerial = 0;
249 int32 ActivePlayerTriggeredDispatchSerial = INDEX_NONE;
250 int32 LastPlayerTriggeredDispatchSerial = INDEX_NONE;
251
252public:
253 friend struct FStageManagementHandle;
254};
255
256
257template <CSpawnSystem TSpawnSystem>
258TSpawnSystem* UStageSubsystem::GetOrCreateSpawnSystem()
259{
260 ASpawnHub* Hub = GetOrCreateSpawnHub();
261 return Hub ? Hub->GetOrCreateSpawnSystem<TSpawnSystem>() : nullptr;
262}
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnWaveCleared, const FWaveDataCollection &, WaveDataCollection, const int32, ClearedWaveIndex, const int32, NextWaveIndex)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEnemyRemainingCountChanged, int32, RemainingCount)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnWaveStarted, const FWaveDataCollection &, WaveDataCollection, const int32, CurrentWaveIndex)
Definition EncounterField.h:27
Definition SpawnHub.h:27
UActorComponent * GetOrCreateSpawnSystem(UPARAM(meta=(MustImplement="/Script/CK_UE.SpawnSystemInterface")) TSubclassOf< UActorComponent > SpawnSystemClass)
Definition StageEventListenerInterface.h:17
Definition StreamingEventListenerInterface.h:23
Definition LevelStreamingData.h:17
Definition StageDictionary.h:14
Definition StageEventProcessor.h:31
Definition StageSubsystem.h:102
virtual void OnLevelStreamingStarted() override
Definition StageSubsystem.h:109
virtual void OnLevelStreamingEnded() override
Definition StageSubsystem.h:110
Definition StoryboardDefinition.h:36
Definition SpawnHub.h:18
Definition StageEventContext.h:15
Definition StageEventMessage.h:14
Represents a subscription to stage events in a system.
Definition StageEventSubscription.h:31
Definition StageSubsystem.h:36
FORCEINLINE FName GetCurrentStageID() const
Definition StageSubsystem.h:73
FORCEINLINE int32 GetCurrentWaveRemainingEnemyCount() const
Definition StageSubsystem.h:83
void SetNextWaveCountdownEndTime(const float InEndTime)
Definition StageSubsystem.h:55
void SetCurrentStageID(const FName InStageID)
Definition StageSubsystem.h:50
void IncreaseCurrentWaveRemainingEnemyCount(const int32 Count)
Definition StageSubsystem.h:40
void DecreaseCurrentWaveRemainingEnemyCount(const int32 Count)
Definition StageSubsystem.h:45
void SetCurrentWaveRemainingEnemyCount(const int32 Count)
Definition StageSubsystem.h:60
FORCEINLINE float GetNextWaveCountdownEndTime() const
Definition StageSubsystem.h:78
void Reset()
Definition StageSubsystem.h:65
Definition StoryboardDefinition.h:17
Definition StageManifest.h:94
Definition TargetableQuery.h:93