LEAP Documentation 40220
Documentation for the LEAP project
ProjectXGameMode.h
Go to the documentation of this file.
1// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "GameFramework/GameMode.h"
7#include "ProjectXGameMode.generated.h"
8
11class APlayerStart;
14class UVehicleSeatComponent;
15class ULevelInfo;
16
17namespace MatchState
18{
19 extern PROJECTX_API const FName WarmUp;
20}
21
22class AProjectXPlayerStateTeam;
23
24USTRUCT(Blueprintable)
26{
27 GENERATED_USTRUCT_BODY()
28
29public:
30 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
31 int32 StartingTicketCount = INDEX_NONE;
32
33 TArray<class APlayerStart*> PlayerStarts;
34};
35
36UENUM(BlueprintType)
37enum class ETeamJoinResponse : uint8
38{
39 Success = 0,
40 AlreadyOnTeam = 1,
41 TeamFull = 2,
42 TeamUnbalance = 3,
43 InvalidTeam = 4,
44 Failure = 5,
45 None = 255
46};
47
48/* Events that will be broadcasted to client/clients relevant to team games. */
49UENUM(BlueprintType)
50enum class ETeamGameEvent : uint8
51{
53
54 None = 255
55};
56
57UENUM()
58enum class EEndGameEvent : uint8
59{
61 EndGameTeam = 1,
65};
66
67USTRUCT()
69{
70 GENERATED_USTRUCT_BODY()
71
73 FEndGameEvent(const int32 InWinningTeam) : WinningTeam(InWinningTeam) {}
74 int32 WinningTeam = INDEX_NONE;
75};
76
77USTRUCT(Blueprintable)
79{
80 GENERATED_USTRUCT_BODY()
81
82 /* Which actor to spawn */
83 UPROPERTY(EditInstanceOnly, BlueprintReadWrite)
84 TSubclassOf<class AActor> SpawnableActor = nullptr;
85 /* The chance of this actor spawning is SpawnWeight / AllSpawnWeights. If you have 3 actors with 100 weight, your chance to spawn would be 100/300 or 1 in 3. */
86 UPROPERTY(EditInstanceOnly, BlueprintReadWrite, meta = (ClampMin = "-1.0", ClampMax = "1000.0", UIMin = "-1.0", UIMax = "1000.0"))
87 float SpawnWeight = 100.0f;
88 /* Spawn this actor indefinitely so long as the system is running.*/
89 UPROPERTY(EditInstanceOnly, BlueprintReadWrite)
90 bool bSpawnIndefinitely = true;
91 /* Check this box if this only needs to spawn on the server. (For example, AI) */
92 UPROPERTY(EditInstanceOnly, BlueprintReadWrite)
93 bool bAuthorityOnly = false;
94 /* What is the minimum and maximum number of actors of this type that should be spawned?*/
95 UPROPERTY(EditInstanceOnly, BlueprintReadWrite, meta = (EditCondition = "!bSpawnIndefinitely"))
96 FVector2D SpawnMinMax = FVector2D(1.0f, 2.0f);
97
98 FORCEINLINE const float GetMaxSpawn() const { return SpawnMinMax.Y; }
99 FORCEINLINE const float GetMinSpawn() const { return SpawnMinMax.X; }
100
101 bool operator!=(const FActorSpawnInfo& rhs) const
102 {
103 return SpawnableActor != rhs.SpawnableActor || SpawnWeight != rhs.SpawnWeight || bSpawnIndefinitely != rhs.bSpawnIndefinitely || SpawnedCount != rhs.SpawnedCount;
104 }
105 bool operator==(const FActorSpawnInfo& rhs) const
106 {
107 return SpawnableActor == rhs.SpawnableActor && SpawnWeight == rhs.SpawnWeight && bSpawnIndefinitely == rhs.bSpawnIndefinitely && SpawnedCount == rhs.SpawnedCount;
108 }
109
110 uint32 SpawnedCount = 0;
111};
112
113UCLASS(config = Game)
114class AProjectXGameMode : public AGameMode
115{
116 GENERATED_UCLASS_BODY()
117
118public:
119 FORCEINLINE TSubclassOf<AHUD> GetHUDClass() const { return HUDClass; }
120 FORCEINLINE TSubclassOf<AHUD> GetSpectatorHUDClass() const { return SpectatorHUDClass; }
121 FORCEINLINE TSubclassOf<class ULocalMessage> GetExperienceEventMessageClass() const { return ExperienceEventMessageClass; }
122 int32 GetMaxPlayers() const;
123 FORCEINLINE int32 GetAverageFramerate() const { return AverageFrameRate; }
124 FORCEINLINE int32 GetHighestAverageFramerate() const { return HighestFrameRate; }
125 FORCEINLINE int32 GetLowestAverageFramerate() const { return LowestFrameRate; }
126 FORCEINLINE int32 GetShortestFrame() const { return ShortestFrame; }
127 FORCEINLINE int32 GetLongestFrame() const { return LongestFrame; }
128 UExperienceConfiguration* GetExperienceConfiguration() const;
129
130 /* gets the default gamemode object for clients to get config properties. */
131 UFUNCTION(BlueprintPure, Category = GameMode, meta = (WorldContext = "WorldContextObject"))
132 static AProjectXGameMode* GetGameModeDefaultObject(const UObject* WorldContextObject);
133
134 UFUNCTION(BlueprintPure)
135 bool AreLoadoutsEnabled() const {return bLoadoutsEnabled;}
136
137 const TMap<uint8, FTeamInfo>& GetTeamConfig() const { return TeamStartingConfig; }
138 virtual APawn* SpawnDefaultPawnAtTransform_Implementation(AController* NewPlayer, const FTransform& SpawnTransform) override;
139 float GetRedeployRespawnTime() const { return RedeployRespawnTime; }
140 float GetReviveDuration() const {return ReviveDuration;}
141 bool GetPreventsIdleKickWhileDead() const { return bPreventIdleKickWhileDead; }
142
143public:
144 /* When victory is called, how long does the server wait to reload the map? */
145 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
146 float RestartMatchTime = 5.0f;
147
148 virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
149 virtual void Tick(float DeltaSeconds) override;
150 virtual void InitGameState() override;
151 virtual void UpdateNetDriver();
152 virtual void StartPlay() override;
153 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
154 virtual void OnDeath(AController* Killed, AController* Killer, TSubclassOf<class UProjectXDamageType> DamageType, bool bWasHeadshot);
155 virtual void OnTeamKill(APlayerController* Killer, APlayerController* Killed);
156 virtual void StartMatch() override;
157 virtual void EndWarmUp();
158 virtual void RequestServerRestart();
159 virtual bool IsMatchInProgress() const override;
160 virtual void OnMatchStateSet() override;
161 virtual void EndMatch();
162 virtual void SetNextMapOverrideByName(const FName& NextMapName);
163 virtual void FinishMatch(FEndGameEvent const& EndGameEvent);
164 virtual void MatchStartRequest();
165 virtual bool CanRestart() const;
166
167 virtual bool IsMatchInWarmUp() const;
168 /* Called RestartMatchTime after EndMatch() is called, decides if we're restarting the map or if we're travelling to a new one. */
169 UFUNCTION()
170 virtual void EndMatchTimer();
171
172 UFUNCTION(BlueprintCallable, Category = GameMode)
173 virtual bool RequestServerTravel(const FString& URL);
174
175 virtual void RestartPlayer(AController* NewPlayer) override;
176 virtual void FinishRestartPlayer(AController* NewPlayer, const FRotator& StartRotation);
177
178 virtual void PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage) override;
179 virtual APlayerController* Login(UPlayer* NewPlayer, ENetRole InRemoteRole, const FString& Portal, const FString& Options, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage) override;
180 virtual void PostLogin(APlayerController* NewPlayer) override;
181 virtual void Logout(AController* Exiting) override;
182
183 virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;
184 virtual UClass* GetDefaultPawnClassForController_Implementation(AController* Player) override;
185 virtual UClass* GetDefaultHUDClassForController(APlayerController* Player) const;
186
187 virtual void InitializeHUDForPlayer_Implementation(APlayerController* NewPlayer) override;
188
189 void RegisterPostGameLineup(AActor* PostGamePodium);
190
191 float GetPassiveUltChargeAmount();
192
193 void UpdateGameModeWinStat(AProjectXPlayerState* const PXPlayerState);
194
195 FORCEINLINE int32 GetPlayerMaxDeployables() const { return MaxPlayerDeployables; }
196
197 UFUNCTION(BlueprintCallable)
198 virtual bool ConsumeTicket(int32 Team, int32 Amount = 1);
199 virtual ETeamJoinResponse JoinTeam(APlayerController* PlayerController, uint8 Team);
200 virtual ETeamJoinResponse CanJoinTeam(APlayerController* PlayerController, uint8 Team) const;
201
202 TArray<FActorSpawnInfo> GetWorldDropsOverrideArray() const { return WorldDropsOverride; }
203
204 /* Default number of max players for this gamemode. Can be overridden by ini and commandline. */
205 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
206 int32 MaxPlayers = 16;
207 /* Default number of max spectators for this gamemode. Can be overridden by ini and commandline. */
208 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Config, Category = GameMode)
209 int32 MaxSpectators = 8;
210 /* Largest allowed difference in team sizes for this gamemode. Can be overridden by ini and commandline. */
211 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Config, Category = GameMode)
212 int32 MaxTeamImbalance = 1;
213 /* When the first player joins, how long do we wait before starting the match? */
214 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
215 float MatchStartTime = 5.0f;
216 /* Editor override for the setting 'MatchStartTime' */
217 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
218 float MatchStartTimeEditor = 3.0f;
219 /* The match will end if match length exceeds this value (seconds). -1 is no limit. */
220 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
221 float MatchLength = -1.0f;
222 /*do players use loadouts*/
223 UPROPERTY(EditDefaultsOnly, Config, BlueprintReadOnly, Category = GameMode)
224 bool bLoadoutsEnabled = true;
225 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameMode, meta = (DisplayName = "Minimum Redeploy Respawn Delay"))
226 float RedeployRespawnTime = 10.0f;
227 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameMode)
228 bool bCanSwapTeams = true;
229 /*This is a max number of deployables for each player per category IE (Turrets)*/
230 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameMode)
231 int32 MaxPlayerDeployables = 1;
232 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameMode)
233 float ReviveDuration = 30.0f;
234 /* If true, does not let the player be kicked when spectating */
235 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = GameMode)
236 bool bPreventIdleKickWhileDead = false;
238 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Classes, meta = (DisplayName = "Spectator HUD Class"))
239 TSubclassOf<AHUD> SpectatorHUDClass = NULL;
240 UPROPERTY(EditDefaultsOnly, Config, Category = GameMode)
241 TArray<FActorSpawnInfo> WorldDropsOverride;
242 /* How long does this game mode keep waiting for players before asking for a restart? (seconds). Ignored if time is < 0 */
243 UPROPERTY(EditDefaultsOnly, Config, BlueprintReadOnly, Category = GameMode)
244 float ServerRestartTime = 0.f;
245
246 UPROPERTY(EditDefaultsOnly, globalconfig, Category = Classes)
247 TSubclassOf<class ULocalMessage> GameModeBroadcastMessage;
248 UPROPERTY(EditDefaultsOnly, globalconfig, Category = Classes)
249 TSubclassOf<class ULocalMessage> KillBroadcastMessage;
250 UPROPERTY(EditDefaultsOnly, globalconfig, Category = Classes)
251 TSubclassOf<class ULocalMessage> HeadshotKillBroadcastMessage;
252 UPROPERTY(EditDefaultsOnly, globalconfig, Category = Classes)
253 TSubclassOf<class ULocalMessage> MatchStartRequestMessage;
254
256 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Classes, meta = (DisplayName = "Experience Event Class"))
257 TSubclassOf<UExperienceConfiguration> ExperienceConfigurationClass = NULL;
258 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = Classes, meta = (DisplayName = "Experience Message Class"))
259 TSubclassOf<ULocalMessage> ExperienceEventMessageClass = NULL;
260
261 /* Team start information such as spawn points */
262 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
263 TMap<uint8, FTeamInfo> TeamStartingConfig;
264 int32 MaxTeamSize = 0;
265
266 UPROPERTY(GlobalConfig)
267 int32 TeamKillsToWarning = 2;
268 UPROPERTY(GlobalConfig)
269 int32 TeamKillsToKick = 5;
270 UPROPERTY(GlobalConfig)
271 int32 TeamKillsToSessionKick = 8;
272 UPROPERTY(Config)
273 float MatchLengthOverride = -1.0f;
274 UPROPERTY(Config)
275 float MaxPlayersOverride = -1.0f;
276 UPROPERTY(Config)
277 int32 MaxPlayerDeployablesOverride = -1;
278 UPROPERTY(Config)
279 TArray<int32> StartingTicketCountOverride;
280
281 /* Rate at which the ultimate will charge passivly*/
282 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode)
283 UCurveFloat* ChargeRateCurve;
284
285 UPROPERTY(EditDefaultsOnly, Category = Classes)
286 TSubclassOf<class ULocalMessage> TeamGameBroadcastMessage = NULL;
287
288 FTimerHandle WarmUpTimer; //Timer for warmup
289 FTimerHandle MatchTimer; //Timer for match
290 FTimerHandle ServerResetTimer; //Timer for the server to call a restart since it's been sitting idle for too long
291
292 TArray<APlayerStart*> LobbyPlayerStarts;
293 TArray<APlayerStart*> MatchPlayerStarts;
294
295 virtual TSubclassOf<AGameSession> GetGameSessionClass() const override;
296 virtual void HandleMatchIsWaitingToStart() override;
297 virtual void HandleMatchHasStarted() override;
298 virtual void HandleMatchWarmupEnded();
299
300
301 virtual void CalculateTicketWinCondition();
302 virtual void CalculateTimeOutWinCondition();
303 virtual int32 GetWinningTeamByTickets();
304 //Called when a player initially joins the game. Attempts to assign the player to a preferred team and squad given their URL options or from their previous player state if applicable.
305 virtual void AssignPlayerTeam(APlayerController* PlayerController, const FString& Options);
306 virtual bool AssignPlayerTeamFromTarget(const FString& Target, APlayerController* PlayerController);
307 virtual void AutoAssignPlayerTeam(APlayerController* PlayerController);
308
309 virtual void CollectGamePlayObjects();
310
311 void OnAntiCheatKickRequired(APlayerController* Player, const FString& KickReason);
312 void OnAntiCheatMessageToClient(APlayerController* Recipient, TArrayView<const uint8> Message);
313
314private:
315 friend class AProjectXGameState;
316
317 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode, meta = (AllowPrivateAccess = true))
318 bool bUseMapRotation = true;
319 UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = GameMode, meta = (AllowPrivateAccess = true))
320 TSubclassOf<AActor> PodiumClass;
321 /* where in the world to spawn the podium*/
322 UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = GameMode, meta = (AllowPrivateAccess = true))
323 FVector PodiumSpawnLocation = FVector(0, 20000, 0);
324 TMap<uint8, TArray<class APlayerStart*>> TeamStartLocations;
325
326 TWeakObjectPtr<ULevelInfo> NextMapOverride = NULL;
327 TArray<float> FrameRateList;
328 int32 AverageFrameRate = 0;
329 int32 LowestFrameRate = MAX_int32;
330 int32 HighestFrameRate = 0;
331 float ShortestFrame = MAX_FLT;
332 float LongestFrame = 0.0f;
333 bool bIsAntiCheatServerSessionActive = false;
334};
ETeamGameEvent
Definition: ProjectXGameMode.h:51
EEndGameEvent
Definition: ProjectXGameMode.h:59
ETeamJoinResponse
Definition: ProjectXGameMode.h:38
Definition: ProjectXGameMode.h:115
FORCEINLINE TSubclassOf< class ULocalMessage > GetExperienceEventMessageClass() const
Definition: ProjectXGameMode.h:121
FORCEINLINE int32 GetAverageFramerate() const
Definition: ProjectXGameMode.h:123
float GetRedeployRespawnTime() const
Definition: ProjectXGameMode.h:139
FORCEINLINE int32 GetLowestAverageFramerate() const
Definition: ProjectXGameMode.h:125
float GetReviveDuration() const
Definition: ProjectXGameMode.h:140
FORCEINLINE int32 GetLongestFrame() const
Definition: ProjectXGameMode.h:127
TArray< FActorSpawnInfo > GetWorldDropsOverrideArray() const
Definition: ProjectXGameMode.h:202
FORCEINLINE int32 GetHighestAverageFramerate() const
Definition: ProjectXGameMode.h:124
const TMap< uint8, FTeamInfo > & GetTeamConfig() const
Definition: ProjectXGameMode.h:137
FORCEINLINE int32 GetShortestFrame() const
Definition: ProjectXGameMode.h:126
FORCEINLINE TSubclassOf< AHUD > GetHUDClass() const
Definition: ProjectXGameMode.h:119
FORCEINLINE TSubclassOf< AHUD > GetSpectatorHUDClass() const
Definition: ProjectXGameMode.h:120
bool GetPreventsIdleKickWhileDead() const
Definition: ProjectXGameMode.h:141
Definition: ProjectXGameState.h:158
Definition: ProjectXPlayerController.h:83
Definition: ProjectXPlayerState.h:238
Definition: ProjectXVehicle.h:56
Definition: ExperienceConfiguration.h:15
Definition: LevelInfo.h:14
Definition: ProjectXDamageType.h:62
Definition: ProjectXGameMode.cpp:47
const FName WarmUp
Definition: ProjectXGameMode.cpp:48
Definition: ProjectXGameMode.h:79
uint32 SpawnedCount
Definition: ProjectXGameMode.h:110
bool bSpawnIndefinitely
Definition: ProjectXGameMode.h:90
TSubclassOf< class AActor > SpawnableActor
Definition: ProjectXGameMode.h:84
float SpawnWeight
Definition: ProjectXGameMode.h:87
FORCEINLINE const float GetMinSpawn() const
Definition: ProjectXGameMode.h:99
bool operator==(const FActorSpawnInfo &rhs) const
Definition: ProjectXGameMode.h:105
bool operator!=(const FActorSpawnInfo &rhs) const
Definition: ProjectXGameMode.h:101
Definition: ProjectXGameMode.h:69
FEndGameEvent(const int32 InWinningTeam)
Definition: ProjectXGameMode.h:73
Definition: ProjectXGameMode.h:26