-
Notifications
You must be signed in to change notification settings - Fork 0
/
BonkGameModeBase.h
226 lines (165 loc) · 6.18 KB
/
BonkGameModeBase.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "BonkGameModeBase.generated.h"
class UBonkPlayer;
class ABonkCameraActor;
class ABonkPlayerPawn;
class APlayerStart;
class UBonkHUD;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPreRoundStart, int32, RoundNumber);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnRoundStart, int32, RoundNumber);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnRoundEnd, int32, RoundNumber);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerJoined, int32, PlayerIndex);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerReady, int32, PlayerIndex);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnShopEntered);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTeamRoundWin, const FText&, TeamName);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTeamMatchWin, const FText&, TeamName);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnPlayerSwitchedTeam, int32, PlayerIndex, int32, TeamIndex);
USTRUCT(BlueprintType)
struct FTeamStructure
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FText TeamName;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FColor TeamColor;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
int32 WinCount;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TArray<UBonkPlayer*> TeamPlayers;
FTeamStructure()
{
WinCount = 0;
}
};
UCLASS()
class BONK_API ABonkGameModeBase : public AGameModeBase
{
GENERATED_BODY()
public:
ABonkGameModeBase();
UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Bonk GameMode", WorldContext="WorldContext"))
static ABonkGameModeBase* Get(UObject* WorldContext);
// Use for first time start match, will call StartRound.
UFUNCTION(BlueprintCallable)
void StartMatch();
// Used to setup the round (like camera switch, spawning players, incrementing the round) and let something else (like a countdown) handle starting of the round.
UFUNCTION(BlueprintCallable)
void StartPreRound();
UFUNCTION(BlueprintCallable)
void StartRound();
UFUNCTION(BlueprintCallable)
void EndRound();
UFUNCTION(BlueprintCallable)
void GoToShop();
void EndMatch(const FTeamStructure& WinningTeam);
UPROPERTY(BlueprintAssignable)
FOnPreRoundStart OnPreRoundStart;
UPROPERTY(BlueprintAssignable)
FOnRoundStart OnRoundStart;
UPROPERTY(BlueprintAssignable)
FOnRoundEnd OnRoundEnd;
UPROPERTY(BlueprintAssignable)
FOnPlayerJoined OnPlayerJoined;
UPROPERTY(BlueprintAssignable)
FOnPlayerReady OnPlayerReady;
UPROPERTY(BlueprintAssignable)
FOnPlayerSwitchedTeam OnPlayerSwitchedTeam;
UPROPERTY(BlueprintAssignable)
FOnTeamRoundWin OnTeamRoundWin;
UPROPERTY(BlueprintAssignable)
FOnTeamMatchWin OnTeamMatchWin;
UPROPERTY(BlueprintAssignable, BlueprintCallable)
FOnShopEntered OnShopEntered;
UFUNCTION(BlueprintCallable)
void SwitchTeamForPlayer(int32 PlayerIndex, int32 NewTeamIndex);
// Indicates that a player has chosen their team and is ready to start the match.
UFUNCTION(BlueprintCallable)
void LockInPlayer(int32 Index);
UFUNCTION(BlueprintPure)
bool CheckAllPlayersLockedIn();
UFUNCTION(BlueprintPure)
bool CanStartMatch();
// Testing
UFUNCTION(BlueprintCallable)
void PlayerDied(int32 PlayerIndex, int32 PlayerKillerIndex);
UPROPERTY(EditAnywhere)
bool bIsDebugging;
UFUNCTION(BlueprintPure)
UBonkPlayer* GetPlayer(int32 PlayerIndex);
UFUNCTION(BlueprintPure)
const TArray<UBonkPlayer*>& GetPlayers();
UFUNCTION(BlueprintPure)
const FTeamStructure& GetTeam(int32 TeamIndex);
UFUNCTION(BlueprintPure)
const TArray<FTeamStructure>& GetTeams();
UFUNCTION(BlueprintPure)
int32 GetCurrentRound();
UFUNCTION(BlueprintPure)
UBonkHUD* GetHUD();
UFUNCTION(BlueprintCallable)
void EnablePlayerInputs();
UFUNCTION(BlueprintCallable)
void DisablePlayerInputs();
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
int32 VolumeIndex;
protected:
virtual void BeginPlay() override;
private:
UPROPERTY(EditAnywhere)
TSubclassOf<ABonkPlayerPawn> PlayerPawnClass;
UPROPERTY(EditAnywhere)
TSubclassOf<UBonkHUD> HUDWidgetClass;
UPROPERTY(EditAnywhere)
TArray<FTeamStructure> Teams;
UPROPERTY(EditAnywhere)
TArray<UBonkPlayer*> Players;
UPROPERTY(VisibleAnywhere)
TArray<APlayerStart*> PlayerStarts;
UPROPERTY(VisibleAnywhere)
TArray<ACameraActor*> Cameras;
UPROPERTY(VisibleAnywhere)
ABonkCameraActor* GameCamera;
UPROPERTY(VisibleAnywhere)
UBonkHUD* HUD;
UPROPERTY(VisibleAnywhere)
FName CurrentCamera;
UPROPERTY(VisibleAnywhere)
int32 CurrentRound;
// Amount of round wins required to win the match.
UPROPERTY(EditAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess))
int32 RoundsToWin;
// The minimum amount of players required to start a match.
UPROPERTY(EditAnywhere)
int32 MinimumPlayers;
UPROPERTY(VisibleAnywhere)
bool bIsRoundLive;
// This will create the UObject that will hold the player's match data.
void RegisterPlayer(int32 Index);
// Creates the pawns used to gather player inputs during the lobby phase.
void CreateLobbyPawns();
void CreateHUD();
// We always want a player 0 in the lobby.
void AddPlayerZeroToLobby();
void DestroyPlayerPawns();
void DestroyLobbyPawns();
void DestroyCameras();
// This only needs to be called right before the match starts. Assigns all the players and locks them to their chosen team.
void AddPlayersToTeams();
void GatherPlayerStarts();
void GatherCameras();
void TransitionToCamera(const FName& Tag);
void SpawnPlayers();
// This is a workaround to prevent the game camera being switched when Player 0's pawn gets destroyed.
// By default the PlayerController will try to find a new ViewTarget whenever they lose possession of something.
// Since we only use a single locked camera we don't want this behaviour.
UFUNCTION()
void RescueCamera(AActor* Actor);
bool CheckForRoundWin(FTeamStructure& OutWinningTeam);
bool CheckForMatchWin(FTeamStructure& OutWinningTeam);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPlayerDied, int32, PlayerIndex);
UPROPERTY(BlueprintAssignable)
FOnPlayerDied OnPlayerDied;
};