206 - Player Bookkeeping
This commit is contained in:
parent
ca24ebf39e
commit
9de33b3f92
|
@ -171,21 +171,15 @@ void ABlasterCharacter::OnRep_ReplicatedMovement()
|
||||||
TimeSinceLastMovementReplication = 0.f;
|
TimeSinceLastMovementReplication = 0.f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::Eliminated()
|
void ABlasterCharacter::Eliminated(bool bPlayerLeftGame)
|
||||||
{
|
{
|
||||||
if (Combat) Combat->DropWeapons();
|
if (Combat) Combat->DropWeapons();
|
||||||
|
MulticastEliminated(bPlayerLeftGame);
|
||||||
MulticastEliminated();
|
|
||||||
GetWorldTimerManager().SetTimer(
|
|
||||||
EliminationTimer,
|
|
||||||
this,
|
|
||||||
&ABlasterCharacter::EliminationTimerFinished,
|
|
||||||
EliminationDelay
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::MulticastEliminated_Implementation()
|
void ABlasterCharacter::MulticastEliminated_Implementation(bool bPlayerLeftGame)
|
||||||
{
|
{
|
||||||
|
bLeftGame = bPlayerLeftGame;
|
||||||
if (BlasterPlayerController)
|
if (BlasterPlayerController)
|
||||||
{
|
{
|
||||||
BlasterPlayerController->SetHUDWeaponAmmo(0);
|
BlasterPlayerController->SetHUDWeaponAmmo(0);
|
||||||
|
@ -237,15 +231,36 @@ void ABlasterCharacter::MulticastEliminated_Implementation()
|
||||||
{
|
{
|
||||||
ShowSniperScopeWidget(false);
|
ShowSniperScopeWidget(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetWorldTimerManager().SetTimer(
|
||||||
|
EliminationTimer,
|
||||||
|
this,
|
||||||
|
&ABlasterCharacter::EliminationTimerFinished,
|
||||||
|
EliminationDelay
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::EliminationTimerFinished()
|
void ABlasterCharacter::EliminationTimerFinished()
|
||||||
{
|
{
|
||||||
ABlasterGameMode* BlasterGameMode = GetWorld()->GetAuthGameMode<ABlasterGameMode>();
|
ABlasterGameMode* BlasterGameMode = GetWorld()->GetAuthGameMode<ABlasterGameMode>();
|
||||||
if (BlasterGameMode)
|
if (BlasterGameMode && !bLeftGame)
|
||||||
{
|
{
|
||||||
BlasterGameMode->RequestRespawn(this, Controller);
|
BlasterGameMode->RequestRespawn(this, Controller);
|
||||||
}
|
}
|
||||||
|
if (bLeftGame && IsLocallyControlled())
|
||||||
|
{
|
||||||
|
OnLeftGame.Broadcast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ABlasterCharacter::ServerLeaveGame_Implementation()
|
||||||
|
{
|
||||||
|
ABlasterGameMode* BlasterGameMode = GetWorld()->GetAuthGameMode<ABlasterGameMode>();
|
||||||
|
BlasterPlayerState = BlasterPlayerState == nullptr ? GetPlayerState<ABlasterPlayerState>() : BlasterPlayerState;
|
||||||
|
if (BlasterGameMode && BlasterPlayerState)
|
||||||
|
{
|
||||||
|
BlasterGameMode->PlayerLeftGame(BlasterPlayerState);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ABlasterCharacter::Destroyed()
|
void ABlasterCharacter::Destroyed()
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "Sound/SoundCue.h"
|
#include "Sound/SoundCue.h"
|
||||||
#include "BlasterCharacter.generated.h"
|
#include "BlasterCharacter.generated.h"
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnLeftGame);
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class BLASTER_API ABlasterCharacter : public ACharacter, public IInteractWithCrosshairInterface
|
class BLASTER_API ABlasterCharacter : public ACharacter, public IInteractWithCrosshairInterface
|
||||||
{
|
{
|
||||||
|
@ -33,10 +35,10 @@ public:
|
||||||
void PlayThrowGrenadeMontage();
|
void PlayThrowGrenadeMontage();
|
||||||
void PlaySwapMontage();
|
void PlaySwapMontage();
|
||||||
|
|
||||||
void Eliminated();
|
void Eliminated(bool bPlayerLeftGame);
|
||||||
|
|
||||||
UFUNCTION(NetMulticast, Reliable)
|
UFUNCTION(NetMulticast, Reliable)
|
||||||
void MulticastEliminated();
|
void MulticastEliminated(bool bPlayerLeftGame);
|
||||||
|
|
||||||
UPROPERTY(Replicated)
|
UPROPERTY(Replicated)
|
||||||
bool bDisableGameplay = false;
|
bool bDisableGameplay = false;
|
||||||
|
@ -53,6 +55,11 @@ public:
|
||||||
TMap<FName, class UBoxComponent*> HitCollisionBoxes;
|
TMap<FName, class UBoxComponent*> HitCollisionBoxes;
|
||||||
|
|
||||||
bool bFinishedSwapping = false;
|
bool bFinishedSwapping = false;
|
||||||
|
|
||||||
|
UFUNCTION(Server, Reliable)
|
||||||
|
void ServerLeaveGame();
|
||||||
|
|
||||||
|
FOnLeftGame OnLeftGame;
|
||||||
protected:
|
protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
@ -244,6 +251,8 @@ private:
|
||||||
|
|
||||||
void EliminationTimerFinished();
|
void EliminationTimerFinished();
|
||||||
|
|
||||||
|
bool bLeftGame = false;
|
||||||
|
|
||||||
// Dissolve effect
|
// Dissolve effect
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
UTimelineComponent* DissolveTimeline;
|
UTimelineComponent* DissolveTimeline;
|
||||||
|
|
|
@ -93,7 +93,7 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara
|
||||||
|
|
||||||
if (EliminatedCharacter)
|
if (EliminatedCharacter)
|
||||||
{
|
{
|
||||||
EliminatedCharacter->Eliminated();
|
EliminatedCharacter->Eliminated(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,3 +112,18 @@ void ABlasterGameMode::RequestRespawn(ACharacter* EliminatedCharacter, AControll
|
||||||
RestartPlayerAtPlayerStart(EliminatedController, PlayerStarts[Selection]);
|
RestartPlayerAtPlayerStart(EliminatedController, PlayerStarts[Selection]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterGameMode::PlayerLeftGame(ABlasterPlayerState* PlayerLeaving)
|
||||||
|
{
|
||||||
|
if (PlayerLeaving == nullptr) return;
|
||||||
|
ABlasterGameState* BlasterGameState = GetGameState<ABlasterGameState>();
|
||||||
|
if (BlasterGameState && BlasterGameState->TopScoringPlayers.Contains(PlayerLeaving))
|
||||||
|
{
|
||||||
|
BlasterGameState->TopScoringPlayers.Remove(PlayerLeaving);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ABlasterCharacter* CharacterLeaving = Cast<ABlasterCharacter>(PlayerLeaving->GetPawn()))
|
||||||
|
{
|
||||||
|
CharacterLeaving->Eliminated(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blaster/PlayerState/BlasterPlayerState.h"
|
||||||
#include "GameFramework/GameMode.h"
|
#include "GameFramework/GameMode.h"
|
||||||
#include "BlasterGameMode.generated.h"
|
#include "BlasterGameMode.generated.h"
|
||||||
|
|
||||||
|
@ -26,7 +27,8 @@ public:
|
||||||
virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController,
|
virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController,
|
||||||
class ABlasterPlayerController* AttackerController);
|
class ABlasterPlayerController* AttackerController);
|
||||||
virtual void RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController);
|
virtual void RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController);
|
||||||
|
void PlayerLeftGame(ABlasterPlayerState* PlayerLeaving);
|
||||||
|
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
float WarmupTime = 10.f;
|
float WarmupTime = 10.f;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "ReturnToMainMenu.h"
|
#include "ReturnToMainMenu.h"
|
||||||
#include "MultiplayerSessionsSubsystem.h"
|
#include "MultiplayerSessionsSubsystem.h"
|
||||||
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
#include "Components/Button.h"
|
#include "Components/Button.h"
|
||||||
#include "GameFramework/GameModeBase.h"
|
#include "GameFramework/GameModeBase.h"
|
||||||
|
|
||||||
|
@ -74,12 +75,35 @@ void UReturnToMainMenu::MenuTearDown()
|
||||||
}
|
}
|
||||||
|
|
||||||
void UReturnToMainMenu::ReturnButtonClicked()
|
void UReturnToMainMenu::ReturnButtonClicked()
|
||||||
|
{
|
||||||
|
ReturnButton->SetIsEnabled(false);
|
||||||
|
|
||||||
|
if (const UWorld* World = GetWorld())
|
||||||
|
{
|
||||||
|
if (const APlayerController* FirstPlayerController = World->GetFirstPlayerController())
|
||||||
|
{
|
||||||
|
if (ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(FirstPlayerController->GetPawn()))
|
||||||
|
{
|
||||||
|
BlasterCharacter->ServerLeaveGame();
|
||||||
|
if (!BlasterCharacter->OnLeftGame.IsBound())
|
||||||
|
{
|
||||||
|
BlasterCharacter->OnLeftGame.AddDynamic(this, &UReturnToMainMenu::OnPlayerLeftGame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReturnButton->SetIsEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UReturnToMainMenu::OnPlayerLeftGame()
|
||||||
{
|
{
|
||||||
if (MultiplayerSessionsSubsystem)
|
if (MultiplayerSessionsSubsystem)
|
||||||
{
|
{
|
||||||
ReturnButton->SetIsEnabled(false);
|
|
||||||
MultiplayerSessionsSubsystem->DestroySession();
|
MultiplayerSessionsSubsystem->DestroySession();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UReturnToMainMenu::OnDestroySessionComplete(bool bWasSuccessful)
|
void UReturnToMainMenu::OnDestroySessionComplete(bool bWasSuccessful)
|
||||||
|
|
|
@ -20,8 +20,13 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool Initialize() override;
|
virtual bool Initialize() override;
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnDestroySessionComplete(bool bWasSuccessful);
|
void OnDestroySessionComplete(bool bWasSuccessful);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnPlayerLeftGame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY(meta = (BindWidget))
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
|
Loading…
Reference in New Issue