This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ShooterGameMode.h
183 lines (124 loc) · 5.26 KB
/
ShooterGameMode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "OnlineIdentityInterface.h"
#include "ShooterPlayerController.h"
#include "A2S/A2SServer.h"
#include "A2S/A2SServerSettings.h"
#include "Discoverability/Discoverability.h"
#include "Discoverability/DiscoverabilitySettings.h"
#include "ShooterGameMode.generated.h"
class AShooterAIController;
class AShooterPlayerState;
class AShooterPickup;
class FUniqueNetId;
UCLASS(config=Game)
class AShooterGameMode : public AGameMode
{
GENERATED_UCLASS_BODY()
/** The bot pawn class */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=GameMode)
TSubclassOf<APawn> BotPawnClass;
UFUNCTION(exec)
void SetAllowBots(bool bInAllowBots, int32 InMaxBots = 8);
virtual void PreInitializeComponents() override;
/** Initialize the game. This is called before actors' PreInitializeComponents. */
virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
/** Accept or reject a player attempting to join the server. Fails login if you set the ErrorMessage to a non-empty string. */
virtual void PreLogin(const FString& Options, const FString& Address, const FUniqueNetIdRepl& UniqueId, FString& ErrorMessage) override;
/** starts match warmup */
virtual void PostLogin(APlayerController* NewPlayer) override;
/** Tries to spawn the player's pawn */
virtual void RestartPlayer(AController* NewPlayer) override;
/** select best spawn point for player */
virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;
/** always pick new random spawn */
virtual bool ShouldSpawnAtStartSpot(AController* Player) override;
/** returns default pawn class for given controller */
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;
/** prevents friendly fire */
virtual float ModifyDamage(float Damage, AActor* DamagedActor, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) const;
/** notify about kills */
virtual void Killed(AController* Killer, AController* KilledPlayer, APawn* KilledPawn, const UDamageType* DamageType);
/** can players damage each other? */
virtual bool CanDealDamage(AShooterPlayerState* DamageInstigator, AShooterPlayerState* DamagedPlayer) const;
/** always create cheat manager */
virtual bool AllowCheats(APlayerController* P) override;
/** update remaining time */
virtual void DefaultTimer();
/** called before startmatch */
virtual void HandleMatchIsWaitingToStart() override;
/** starts new match */
virtual void HandleMatchHasStarted() override;
/** new player joins */
virtual void HandleStartingNewPlayer_Implementation(APlayerController* NewPlayer) override;
/** hides the onscreen hud and restarts the map */
virtual void RestartGame() override;
/** Creates AIControllers for all bots */
void CreateBotControllers();
/** Create a bot */
AShooterAIController* CreateBot(int32 BotNum);
virtual void PostInitProperties() override;
virtual void BeginPlay() override;
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
protected:
/** delay between first player login and starting match */
UPROPERTY(config)
int32 WarmupTime;
/** match duration */
UPROPERTY(config)
int32 RoundTime;
UPROPERTY(config)
int32 TimeBetweenMatches;
/** score for kill */
UPROPERTY(config)
int32 KillScore;
/** score for death */
UPROPERTY(config)
int32 DeathScore;
/** scale for self instigated damage */
UPROPERTY(config)
float DamageSelfScale;
UPROPERTY(config)
int32 MaxBots;
UPROPERTY()
TArray<AShooterAIController*> BotControllers;
UPROPERTY(config)
TSubclassOf<AShooterPlayerController> PlatformPlayerControllerClass;
/** Handle for efficient management of DefaultTimer timer */
FTimerHandle TimerHandle_DefaultTimer;
bool bNeedsBotCreation;
bool bAllowBots;
UA2SServer* A2SServer;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FA2SServerSettings A2SSettings;
UDiscoverability* Discoverability;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
FDiscoverabilitySettings DiscoverabilitySettings;
/** spawning all bots for this game */
void StartBots();
/** initialization for bot after creation */
virtual void InitBot(AShooterAIController* AIC, int32 BotNum);
/** check who won */
virtual void DetermineMatchWinner();
/** check if PlayerState is a winner */
virtual bool IsWinner(AShooterPlayerState* PlayerState) const;
/** check if player can use spawnpoint */
virtual bool IsSpawnpointAllowed(APlayerStart* SpawnPoint, AController* Player) const;
/** check if player should use spawnpoint */
virtual bool IsSpawnpointPreferred(APlayerStart* SpawnPoint, AController* Player) const;
/** Returns game session class to use */
virtual TSubclassOf<AGameSession> GetGameSessionClass() const override;
/** Tracks if a game has joined the server at least once */
bool bHasPlayerConnected = false;
public:
/** finish current match and lock players */
UFUNCTION(exec)
void FinishMatch();
/*Finishes the match and bumps everyone to main menu.*/
/*Only GameInstance should call this function */
void RequestFinishAndExitToMainMenu();
/** get the name of the bots count option used in server travel URL */
static FString GetBotsCountOptionName();
UPROPERTY()
TArray<AShooterPickup*> LevelPickups;
};