diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 097d3ae..6450884 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -72,7 +72,6 @@ void ABlasterGameMode::OnMatchStateSet() } } - float ABlasterGameMode::CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage) { return BaseDamage; diff --git a/Source/Blaster/GameMode/TeamsGameMode.cpp b/Source/Blaster/GameMode/TeamsGameMode.cpp index 4c67a01..ee5a9f0 100644 --- a/Source/Blaster/GameMode/TeamsGameMode.cpp +++ b/Source/Blaster/GameMode/TeamsGameMode.cpp @@ -4,6 +4,7 @@ #include "TeamsGameMode.h" #include "Blaster/GameState/BlasterGameState.h" +#include "Blaster/PlayerController/BlasterPlayerController.h" #include "Kismet/GameplayStatics.h" ATeamsGameMode::ATeamsGameMode() @@ -82,3 +83,23 @@ float ATeamsGameMode::CalculateDamage(AController* Attacker, AController* Victim return BaseDamage; } + +void ATeamsGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController, + ABlasterPlayerController* AttackerController) +{ + Super::PlayerEliminated(EliminatedCharacter, VictimController, AttackerController); + + BGameState = (BGameState == nullptr) ? Cast(UGameplayStatics::GetGameState(this)) : BGameState; + const ABlasterPlayerState* AttackerPlayerState = AttackerController ? AttackerController->GetPlayerState() : nullptr; + if (BGameState && AttackerPlayerState) + { + if (AttackerPlayerState->GetTeam() == ETeam::ET_BlueTeam) + { + BGameState->BlueTeamScores(); + } + if (AttackerPlayerState->GetTeam() == ETeam::ET_RedTeam) + { + BGameState->RedTeamScores(); + } + } +} diff --git a/Source/Blaster/GameMode/TeamsGameMode.h b/Source/Blaster/GameMode/TeamsGameMode.h index d83ca6d..e85c035 100644 --- a/Source/Blaster/GameMode/TeamsGameMode.h +++ b/Source/Blaster/GameMode/TeamsGameMode.h @@ -19,7 +19,8 @@ public: virtual void PostLogin(APlayerController* NewPlayer) override; virtual void Logout(AController* Exiting) override; virtual float CalculateDamage(AController* Attacker, AController* Victim, float BaseDamage) override; - + virtual void PlayerEliminated(class ABlasterCharacter* EliminatedCharacter, class ABlasterPlayerController* VictimController, + class ABlasterPlayerController* AttackerController) override; protected: virtual void HandleMatchHasStarted() override; diff --git a/Source/Blaster/GameState/BlasterGameState.cpp b/Source/Blaster/GameState/BlasterGameState.cpp index 8a4a638..bc47089 100644 --- a/Source/Blaster/GameState/BlasterGameState.cpp +++ b/Source/Blaster/GameState/BlasterGameState.cpp @@ -3,6 +3,7 @@ #include "BlasterGameState.h" +#include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/PlayerState/BlasterPlayerState.h" #include "Net/UnrealNetwork.h" @@ -37,19 +38,33 @@ void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer) void ABlasterGameState::RedTeamScores() { ++RedTeamScore; + if (ABlasterPlayerController* BController = Cast(GetWorld()->GetFirstPlayerController())) + { + BController->SetHUDRedTeamScore(RedTeamScore); + } } void ABlasterGameState::BlueTeamScores() { ++BlueTeamScore; + if (ABlasterPlayerController* BController = Cast(GetWorld()->GetFirstPlayerController())) + { + BController->SetHUDBlueTeamScore(BlueTeamScore); + } } void ABlasterGameState::OnRep_RedTeamScore() { - + if (ABlasterPlayerController* BController = Cast(GetWorld()->GetFirstPlayerController())) + { + BController->SetHUDRedTeamScore(RedTeamScore); + } } void ABlasterGameState::OnRep_BlueTeamScore() { - + if (ABlasterPlayerController* BController = Cast(GetWorld()->GetFirstPlayerController())) + { + BController->SetHUDBlueTeamScore(BlueTeamScore); + } } diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index a0f00f6..6e6259a 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -660,7 +660,6 @@ void ABlasterPlayerController::OnRep_MatchState() void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch) { if (HasAuthority()) bShowTeamScores = bTeamsMatch; - BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; if (BlasterHUD) { @@ -668,16 +667,15 @@ void ABlasterPlayerController::HandleMatchHasStarted(bool bTeamsMatch) if (BlasterHUD->Announcement) { BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Hidden); - - if (!HasAuthority()) return; - if (bTeamsMatch) - { - InitTeamScores(); - } - else - { - HideTeamScores(); - } + } + if (!HasAuthority()) return; + if (bTeamsMatch) + { + InitTeamScores(); + } + else + { + HideTeamScores(); } } } @@ -722,10 +720,10 @@ void ABlasterPlayerController::HandleCooldown() } else if (TopPlayers.Num() > 1) { - InfoTextString = FString("Players tied for the win: \n"); - for (auto TiedPlayers : TopPlayers) + InfoTextString = FString("Players tied for the win:\n"); + for (auto TiedPlayer : TopPlayers) { - InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayers->GetPlayerName())); + InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayer->GetPlayerName())); } }