128 - Blaster Game State
This commit is contained in:
parent
884caf9974
commit
927ab3aaa1
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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<ABlasterGameMode>(UGameplayStatics::GetGameMode(this));
|
||||
bool bMatchNotInProgress = BlasterGameMode && BlasterGameMode->GetMatchState() != MatchState::InProgress;
|
||||
|
||||
if (Combat && Combat->EquippedWeapon && bMatchNotInProgress)
|
||||
{
|
||||
Combat->EquippedWeapon->Destroy();
|
||||
}
|
||||
|
|
|
@ -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<ABlasterPlayerState>(AttackerController->PlayerState) : nullptr;
|
||||
ABlasterPlayerState* VictimPlayerState = VictimController ? Cast<ABlasterPlayerState>(VictimController->PlayerState) : nullptr;
|
||||
|
||||
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState)
|
||||
ABlasterGameState* BlasterGameState = GetGameState<ABlasterGameState>();
|
||||
|
||||
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState && BlasterGameState)
|
||||
{
|
||||
AttackerPlayerState->IncreaseScore(1.f);
|
||||
BlasterGameState->UpdateTopScore(AttackerPlayerState);
|
||||
}
|
||||
if (VictimPlayerState)
|
||||
{
|
||||
|
|
|
@ -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<FLifetimeProperty>& 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||
void UpdateTopScore(class ABlasterPlayerState* ScoringPlayer);
|
||||
|
||||
UPROPERTY(Replicated)
|
||||
TArray<class ABlasterPlayerState*> TopScoringPlayers;
|
||||
|
||||
private:
|
||||
|
||||
float TopScore = 0.f;
|
||||
};
|
|
@ -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<ABlasterGameState>(UGameplayStatics::GetGameState(this));
|
||||
ABlasterPlayerState* BlasterPlayerState = GetPlayerState<ABlasterPlayerState>();
|
||||
if (BlasterGameState && BlasterPlayerState)
|
||||
{
|
||||
TArray<ABlasterPlayerState*> 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<ABlasterCharacter>(GetPawn());
|
||||
|
|
Loading…
Reference in New Issue