diff --git a/Content/Blueprints/Character/BP_BlasterCharacter.uasset b/Content/Blueprints/Character/BP_BlasterCharacter.uasset index 38e419d..05ab4a6 100644 Binary files a/Content/Blueprints/Character/BP_BlasterCharacter.uasset and b/Content/Blueprints/Character/BP_BlasterCharacter.uasset differ diff --git a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset index 55ad2cb..5ec6340 100644 Binary files a/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset and b/Content/Blueprints/GameModes/BP_BlasterGameMode.uasset differ diff --git a/Content/Blueprints/GameState/BP_BlasterGameState.uasset b/Content/Blueprints/GameState/BP_BlasterGameState.uasset new file mode 100644 index 0000000..c014c07 Binary files /dev/null and b/Content/Blueprints/GameState/BP_BlasterGameState.uasset differ diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 0aca14f..f0f2f26 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -110,6 +110,10 @@ void ABlasterCharacter::MulticastEliminated_Implementation() GetCharacterMovement()->DisableMovement(); GetCharacterMovement()->StopMovementImmediately(); bDisableGameplay = true; + if (Combat) + { + Combat->FireButtonPressed(false); + } // Disable collision GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetMesh()->SetCollisionEnabled(ECollisionEnabled::NoCollision); @@ -152,7 +156,11 @@ void ABlasterCharacter::Destroyed() { EliminationBotComponent->DestroyComponent(); } - if (Combat && Combat->EquippedWeapon) + + ABlasterGameMode* BlasterGameMode = Cast(UGameplayStatics::GetGameMode(this)); + bool bMatchNotInProgress = BlasterGameMode && BlasterGameMode->GetMatchState() != MatchState::InProgress; + + if (Combat && Combat->EquippedWeapon && bMatchNotInProgress) { Combat->EquippedWeapon->Destroy(); } diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 8660896..6596d07 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -4,6 +4,7 @@ #include "BlasterGameMode.h" #include "Blaster/Character/BlasterCharacter.h" +#include "Blaster/GameState/BlasterGameState.h" #include "Blaster/PlayerController/BlasterPlayerController.h" #include "Blaster/PlayerState/BlasterPlayerState.h" #include "GameFramework/PlayerStart.h" @@ -78,9 +79,12 @@ void ABlasterGameMode::PlayerEliminated(class ABlasterCharacter* EliminatedChara ABlasterPlayerState* AttackerPlayerState = AttackerController ? Cast(AttackerController->PlayerState) : nullptr; ABlasterPlayerState* VictimPlayerState = VictimController ? Cast(VictimController->PlayerState) : nullptr; - if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState) + ABlasterGameState* BlasterGameState = GetGameState(); + + if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState && BlasterGameState) { AttackerPlayerState->IncreaseScore(1.f); + BlasterGameState->UpdateTopScore(AttackerPlayerState); } if (VictimPlayerState) { diff --git a/Source/Blaster/GameState/BlasterGameState.cpp b/Source/Blaster/GameState/BlasterGameState.cpp new file mode 100644 index 0000000..7077045 --- /dev/null +++ b/Source/Blaster/GameState/BlasterGameState.cpp @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "BlasterGameState.h" + +#include "Blaster/PlayerState/BlasterPlayerState.h" +#include "Net/UnrealNetwork.h" + +void ABlasterGameState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const +{ + Super::GetLifetimeReplicatedProps(OutLifetimeProps); + + DOREPLIFETIME(ABlasterGameState, TopScoringPlayers); +} + +void ABlasterGameState::UpdateTopScore(ABlasterPlayerState* ScoringPlayer) +{ + if (TopScoringPlayers.Num() == 0) + { + TopScoringPlayers.Add(ScoringPlayer); + TopScore = ScoringPlayer->GetScore(); + } + else if (ScoringPlayer->GetScore() == TopScore) + { + TopScoringPlayers.AddUnique(ScoringPlayer); + } + else if (ScoringPlayer->GetScore() < TopScore) + { + TopScoringPlayers.Empty(); + TopScoringPlayers.AddUnique(ScoringPlayer); + TopScore = ScoringPlayer->GetScore(); + } + +} diff --git a/Source/Blaster/GameState/BlasterGameState.h b/Source/Blaster/GameState/BlasterGameState.h new file mode 100644 index 0000000..87cbf98 --- /dev/null +++ b/Source/Blaster/GameState/BlasterGameState.h @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/GameState.h" +#include "BlasterGameState.generated.h" + +/** + * + */ +UCLASS() +class BLASTER_API ABlasterGameState : public AGameState +{ + GENERATED_BODY() + +public: + virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; + void UpdateTopScore(class ABlasterPlayerState* ScoringPlayer); + + UPROPERTY(Replicated) + TArray TopScoringPlayers; + +private: + + float TopScore = 0.f; +}; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 8e494ed..c5d05b5 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -6,10 +6,12 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/Components/CombatComponent.h" #include "Blaster/GameMode/BlasterGameMode.h" +#include "Blaster/GameState/BlasterGameState.h" #include "Blaster/HUD/Announcement.h" #include "Blaster/HUD/BlasterHUD.h" #include "Blaster/HUD/CharacterOverlay.h" #include "Blaster/HUD/DebugWidget.h" +#include "Blaster/PlayerState/BlasterPlayerState.h" #include "Components/ProgressBar.h" #include "Components/TextBlock.h" #include "GameFramework/GameMode.h" @@ -304,6 +306,7 @@ void ABlasterPlayerController::SetHUDTime() void ABlasterPlayerController::PollInit() { + /* if (BlasterHUD && BlasterHUD->DebugWidget == nullptr) { BlasterHUD->AddDebugWidget(); @@ -312,6 +315,7 @@ void ABlasterPlayerController::PollInit() DebugWidget = BlasterHUD->DebugWidget; } } + */ if (CharacterOverlay == nullptr) { @@ -414,7 +418,36 @@ void ABlasterPlayerController::HandleCooldown() BlasterHUD->Announcement->SetVisibility(ESlateVisibility::Visible); FString AnnouncementText("New match starts in:"); BlasterHUD->Announcement->AnnouncementText->SetText(FText::FromString(AnnouncementText)); - BlasterHUD->Announcement->AnnouncementMessage->SetText(FText()); + + ABlasterGameState* BlasterGameState = Cast(UGameplayStatics::GetGameState(this)); + ABlasterPlayerState* BlasterPlayerState = GetPlayerState(); + if (BlasterGameState && BlasterPlayerState) + { + TArray TopPlayers = BlasterGameState->TopScoringPlayers; + FString InfoTextString; + if (TopPlayers.Num() == 0) + { + InfoTextString = FString("There is no winner."); + } + else if (TopPlayers.Num() == 1 && TopPlayers[0] == BlasterPlayerState) + { + InfoTextString = FString("You are the winner!"); + } + else if (TopPlayers.Num() == 1) + { + InfoTextString = FString::Printf(TEXT("%s won!"), *TopPlayers[0]->GetPlayerName()); + } + else if (TopPlayers.Num() > 1) + { + InfoTextString = FString("Players tied for the win: \n"); + for (auto TiedPlayers : TopPlayers) + { + InfoTextString.Append(FString::Printf(TEXT("%s\n"), *TiedPlayers->GetPlayerName())); + } + } + + BlasterHUD->Announcement->AnnouncementMessage->SetText(FText::FromString(InfoTextString)); + } } } ABlasterCharacter* BlasterCharacter = Cast(GetPawn());