LEAP Documentation 40220
Documentation for the LEAP project
WaveSpawner.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2022. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/Actor.h"
8#include "SpawnInterface.h"
9#include "Engine/DataTable.h"
10#include "Engine/DataAsset.h"
11#include "WeakInterfacePtr.h"
12#include "WaveSpawner.generated.h"
13
14class ULocalMessage;
15class USoundCue;
16class UAfflictionInstance;
18
19USTRUCT(Blueprintable)
21{
22 GENERATED_USTRUCT_BODY()
23
24 /* Drag as many spwners as you'd like to be activated for this wave. Only actors implementing ISpawnInterface can be used */
25 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (MustImplement = "ISpawnInterface"))
26 TArray<AActor*> SpawnersToActivate;
27 /* If true, the system will track all enemies spawned and end the wave if all spawned ai have been killed. This feature will not work if any of your spawners are set to spawn indefinitely. */
28 UPROPERTY(EditAnywhere, BlueprintReadWrite)
29 bool bEndWaveIfAllEnemiesKilled = false;
30 /* Should we respawn fallen AI? This will determine the group size to respawn them in. Example: If 4, the player would have to kill 4 enemies before they all respawn in one batch. 1 would spawn them 1 by 1. -1 will ignore this feature.*/
31 UPROPERTY(EditAnywhere, BlueprintReadWrite)
32 float RespawnGroupSize = INDEX_NONE;
33 /* An optional delay which will occur the moment the player has killed "RespawnGroupSize" enemies in order to fill a shuttle. This wait time will be queued prior to respawning the AI. */
34 UPROPERTY(EditAnywhere, BlueprintReadWrite)
35 float RespawnDelay = 10.0f;
36 /* Spaces out respawns by 'RespawnDelay' so that if 'RespawnDelay' were 10s, 3 respawns would take 10s, 20s and 30s rather than all spawning at once 10s later. */
37 UPROPERTY(EditAnywhere, BlueprintReadWrite)
38 bool bStaggeredRespawns = true;
39 /* Should we end the wave if a certain number of enemies are killed? -1 will ignore this feature. */
40 UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (EditCondition = "!bEndWaveIfAllEnemiesKilled"))
41 float NumEnemiesKilledToEndWave = INDEX_NONE;
42 /* Should we end the wave if a certain amount of time has expired? -1 will ignore this feature. Not compatible with "WaveFailureTime". This will take precedence if both are set. */
43 UPROPERTY(EditAnywhere, BlueprintReadWrite)
44 float TimeToEndWave = INDEX_NONE;
45 /* Does this wave need a cooldown different than the standard one? Override here. -1 will ignore this feature */
46 UPROPERTY(EditAnywhere, BlueprintReadWrite)
47 float WaveCooldownOverride = INDEX_NONE;
48 /* Should the game end in failure if the wave was not completed before this time ends? -1 will ignore this feature. Not compatible with "TimeToEndWave". "TimeToEndWave" will take precedence if both are set */
49 UPROPERTY(EditAnywhere, BlueprintReadWrite)
50 float WaveFailureTime = INDEX_NONE;
51
52 // Spawners can destroy themselves, so we can't consider configuration data to be reliable data
53 TArray<TWeakObjectPtr<AActor>> CachedSpawnerWeakPtrs;
54 int32 CompletedSpawns = 0;
55
56 bool IsWaveSpawningComplete() const { return CompletedSpawns >= SpawnersToActivate.Num(); }
57};
58
59UENUM(BlueprintType)
60enum class EWaveSpawnerState : uint8
61{
62 Idle = 0,
63 Spawning = 1,
64 InProgress = 2,
65 CoolingDown = 3,
66 Completed = 4,
67 Invalid = 255
68};
69
70UENUM(BlueprintType)
71enum class EWaveTimerType : uint8
72{
73 NONE = 0,
74 Survive = 1,
75 Cooldown = 2,
77};
78
79USTRUCT(BlueprintType)
81{
82 GENERATED_USTRUCT_BODY()
84public:
85 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
86 USoundCue* WaveCue = NULL;
87 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
88 FString AnnouncerVoiceToPlay = "";
89 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
90 FText WaveNarrativeMessage;
91 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
92 FText WaveMessage;
93};
94
95USTRUCT(BlueprintType)
96struct PROJECTX_API FWaveData : public FTableRowBase
97{
98 GENERATED_BODY()
99public:
100 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
101 TMap<EWaveSpawnerState, FWaveStateInfo> WaveDisplayInfo;
102 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Customization)
103 bool bDisplayKillProgress = false;
104 UPROPERTY(EditAnywhere,BlueprintReadWrite, Category = Cusomtization)
105 FText KillDescriptionText;
106};
107
108DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWaveSpawnerWaveStartedSignature, AWaveSpawner* const, WaveSpawner);
109DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FWaveSpawnerCompletedSignature, AWaveSpawner* const, WaveSpawner, bool, bSuccess);
110DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FWaveSpawnerMobDefeatedSignature, AWaveSpawner* const, WaveSpawner, int32, DefeatedMobCount);
111DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FWaveSpawnerMobCountUpdatedSignature, AWaveSpawner* const, WaveSpawner, int32, TotalMobCount, int32, DefeatedMobCount);
112
113UCLASS()
114class PROJECTX_API AWaveSpawner : public AActor, public IReactsToMatchEvents, public ISpawnInterface
115{
116 GENERATED_BODY()
117
118public:
119 /* Run when the match starts, if false, the spawner will begin spawning actors immediately. */
120 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (EditCondition = "!bExecutesOnBeginPlay"))
121 bool bExecuteOnMatchStart = true;
122 /* Run when the map loads, if false, the spawner will begin spawning actors immediately. */
123 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (EditCondition = "!bExecuteOnMatchStart"))
124 bool bExecutesOnBeginPlay = false;
125 /* Time to wait before beginning the wave */
126 UPROPERTY(BlueprintReadWrite, EditAnywhere)
127 float StartTimeDelay = 0.0f;
128 /* Amount of time for a wave to cooldown after completion before begining the next wave */
129 UPROPERTY(BlueprintReadWrite, EditAnywhere)
130 float WaveCooldownTime = 15.0f;
131 /* Should the match end in victory if all waves have been completed? */
132 UPROPERTY(BlueprintReadWrite, EditAnywhere)
133 bool bEndGameWithVictoryIfAllWavesCompleted = false;
134 /* What vehicle should be used to deliver respawned actors? */
135 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (MustImplement = "ISpawnInterface"))
136 TSubclassOf<AActor> RespawnActor = nullptr;
137 /* What team is the enemy ai on? This is used for victory/fail conditions. You will still want to set teams on your ai spawners. */
138 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (EditCondition = "bDebug"))
139 int32 EnemyTeam = 99;
140 /* Should we print information about what the spawnwer is doing for debug purposes? */
141 UPROPERTY(BlueprintReadWrite, EditAnywhere)
142 bool bDebug = false;
143 /* This can get spammy, but is useful for tracking more details about the spawner */
144 UPROPERTY(BlueprintReadWrite, EditAnywhere, meta = (EditCondition = "bDebug"))
145 bool bVerboseDebug = false;
146 /* Wave definitions containing information on how each wave should execute */
147 UPROPERTY(BlueprintReadWrite, EditAnywhere)
148 TArray<FWaveSpawnInfo> Waves;
149 /* is this the game modes primary wave spawner, one of them in the level needs to be*/
150 UPROPERTY(BlueprintReadWrite, EditAnywhere)
151 bool bPrimarySpawner = false;
152 UPROPERTY(BlueprintReadOnly)
153 float SurviveTimeMultiplier = 1.0f;
154 UPROPERTY(BlueprintReadOnly)
155 float WaveFailureTimeMultiplier = 1.0f;
156
157 AWaveSpawner();
158
159 UFUNCTION(BlueprintPure)
160 FORCEINLINE int32 GetCurrentWave() const { return CurrentWave; }
161 UFUNCTION(BlueprintPure)
162 FORCEINLINE int32 GetTotalWaves() const { return Waves.Num(); }
163 UFUNCTION(BlueprintPure)
164 FORCEINLINE int32 GetTotalKills() const { return TotalMobsKilled; }
165 UFUNCTION(BlueprintPure)
166 FORCEINLINE float GetWaveProgress() const { return (float)GetCurrentWave() / (float)GetTotalWaves(); }
167 UFUNCTION(BlueprintPure)
168 FORCEINLINE EWaveSpawnerState GetWaveSpawnerState() const { return SpawningState; };
169 UFUNCTION(BlueprintPure)
170 FORCEINLINE bool IsADefeatEnemyWave(int32 Wave) const {return Waves.IsValidIndex(Wave) ? Waves[Wave].bEndWaveIfAllEnemiesKilled : false;}
171 UFUNCTION(BlueprintPure)
172 int32 GetNumberOfEnemiesNeededToProgress(int32 Wave) const;
173 UFUNCTION(BlueprintCallable)
174 virtual void SpawnWave();
175 UFUNCTION(BlueprintCallable)
176 virtual void EndWave();
177
178 UFUNCTION(BlueprintPure)
179 static void GetWaveSpawnerStateFromPackedInt(const int32 Data, int32& Wave, EWaveSpawnerState& State);
180
181 void RegisterActiveObjective(AProjectXSpawnerObjective* const Objective);
182 virtual int32 GetPackedWaveState();
183 virtual void SetWaveSpawnerState(const EWaveSpawnerState NewState);
184 virtual void BroadcastWaveStateToPlayer(APlayerController* const SpecificPlayer);
185 virtual void NextWave();
186 virtual void BeginSpawning_Implementation() override;
187 virtual void MatchStarted() override;
188 virtual void BeginPlay() override;
189 virtual bool ImplementsSpawnCompleteCallback() const override { return true; }
190 virtual void RespawnMobs(const FVector Location, TArray<TSubclassOf<AActor>> MobList);
191 virtual void CancelRespawns();
192 virtual void GameOver(const bool bVictory);
193 virtual int32 GetPlayerTeam() const;
194 virtual void WipeMobs();
195 bool HasWaveBeenDefeated() const;
196 bool EnemiesRemainingToEndWave() const;
197
198 UFUNCTION()
199 void RespawnerFinsished(AActor* Actor, EEndPlayReason::Type EndPlayReason);
200 UFUNCTION()
201 void EventComplete(bool bSuccess);
202 UFUNCTION()
203 void OnMobSpawned(AProjectXCharacter* SpawnedPlayerState);
204 UFUNCTION()
205 void OnMobDestroyed(AProjectXCharacter* SpawnedPlayerState, FVector SpawnLocation);
206 UFUNCTION()
207 void OnSpawnerCompleted(UObject* Spawner);
208 void ApplyWaveAffliction();
209 UPROPERTY(BlueprintAssignable)
210 FWaveSpawnerCompletedSignature OnWaveSpawnerEventsCompletedEvent;
211 UPROPERTY(BlueprintAssignable)
212 FWaveSpawnerCompletedSignature OnWaveCompletedEvent;
213 UPROPERTY(BlueprintAssignable)
214 FWaveSpawnerWaveStartedSignature OnWaveStartedEvent;
215 UPROPERTY(BlueprintAssignable)
216 FWaveSpawnerMobDefeatedSignature OnMobsDefeatedEvent;
217 UPROPERTY(BlueprintAssignable)
218 FWaveSpawnerCompletedSignature OnTimedWaveCompletedEvent;
219 UPROPERTY(BlueprintAssignable)
220 FWaveSpawnerMobCountUpdatedSignature OnMobCountUpdatedSignature;
221 UPROPERTY(BlueprintAssignable)
222 FWaveSpawnerWaveStartedSignature OnWaveProgress;
223
224protected:
225 /* Affliction to be applied to enemies that are spawned*/
226 UPROPERTY(EditAnywhere, BlueprintReadWrite)
227 TSubclassOf<UAfflictionInstance> SpawnedCharacterAffliction = NULL;
228 /* at what percentage of the wave being killed will it trigger this affliction*/
229 UPROPERTY(EditAnywhere, BlueprintReadWrite)
230 float CharacterAfflictionTriggerPercentage = 0.5f;
231
232private:
234 int32 CurrentWave = 0;
235 int32 TotalMobsKilled = 0;
236 int32 TotalMobsSpawned = 0;
237 bool bAppliedWaveAffliction = false;
238 TArray<TWeakObjectPtr<AActor>> ActiveRespawners;
239 TArray<TSubclassOf<AActor>> MobRespawnList;
240 TWeakObjectPtr< AProjectXSpawnerObjective> ActiveObjective = NULL;
241 TArray<TWeakObjectPtr<AProjectXCharacter>> SpawnedCharacters = TArray<TWeakObjectPtr<AProjectXCharacter>>();
242 uint32 QueuedRespawns = 0;
243};
EWaveTimerType
Definition: WaveSpawner.h:72
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FWaveSpawnerMobCountUpdatedSignature, AWaveSpawner *const, WaveSpawner, int32, TotalMobCount, int32, DefeatedMobCount)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWaveSpawnerWaveStartedSignature, AWaveSpawner *const, WaveSpawner)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FWaveSpawnerCompletedSignature, AWaveSpawner *const, WaveSpawner, bool, bSuccess)
EWaveSpawnerState
Definition: WaveSpawner.h:61
Definition: ProjectXCharacter.h:128
Definition: ProjectXSpawnerObjective.h:53
bool bDebug
Definition: ProjectXSpawnerObjective.h:133
virtual void BeginSpawning_Implementation() override
Definition: ProjectXSpawnerObjective.cpp:86
virtual void BeginPlay() override
Definition: ProjectXSpawnerObjective.cpp:28
Definition: WaveSpawner.h:115
virtual bool ImplementsSpawnCompleteCallback() const override
Definition: WaveSpawner.h:189
Definition: ReactsToMatchEvents.h:16
virtual void MatchStarted()
Definition: ReactsToMatchEvents.cpp:11
Definition: SpawnInterface.h:24
Definition: WaveSpawner.h:97
Definition: WaveSpawner.h:21
Definition: WaveSpawner.h:81