2022-05-07 15:11:53 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "BlasterGameMode.h"
|
|
|
|
|
2022-05-07 17:10:32 +00:00
|
|
|
#include "Blaster/Character/BlasterCharacter.h"
|
2022-05-09 14:33:48 +00:00
|
|
|
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
|
|
|
#include "Blaster/PlayerState/BlasterPlayerState.h"
|
2022-05-07 18:34:40 +00:00
|
|
|
#include "GameFramework/PlayerStart.h"
|
|
|
|
#include "Kismet/GameplayStatics.h"
|
2022-05-07 17:10:32 +00:00
|
|
|
|
|
|
|
void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController,
|
|
|
|
ABlasterPlayerController* AttackerController)
|
2022-05-07 15:11:53 +00:00
|
|
|
{
|
2022-05-09 14:33:48 +00:00
|
|
|
ABlasterPlayerState* AttackerPlayerState = AttackerController ? Cast<ABlasterPlayerState>(AttackerController->PlayerState) : nullptr;
|
|
|
|
ABlasterPlayerState* VictimPlayerState = VictimController ? Cast<ABlasterPlayerState>(VictimController->PlayerState) : nullptr;
|
|
|
|
|
|
|
|
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState)
|
|
|
|
{
|
|
|
|
AttackerPlayerState->IncreaseScore(1.f);
|
|
|
|
}
|
2022-05-09 15:16:41 +00:00
|
|
|
if (VictimPlayerState)
|
|
|
|
{
|
|
|
|
VictimPlayerState->IncreaseDefeats(1);
|
|
|
|
}
|
2022-05-09 14:33:48 +00:00
|
|
|
|
2022-05-07 17:10:32 +00:00
|
|
|
if (EliminatedCharacter)
|
|
|
|
{
|
|
|
|
EliminatedCharacter->Eliminated();
|
|
|
|
}
|
2022-05-07 18:34:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ABlasterGameMode::RequestRespawn(ACharacter* EliminatedCharacter, AController* EliminatedController)
|
|
|
|
{
|
|
|
|
if (EliminatedCharacter)
|
|
|
|
{
|
|
|
|
EliminatedCharacter->Reset();
|
|
|
|
EliminatedCharacter->Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (EliminatedController)
|
|
|
|
{
|
|
|
|
TArray<AActor*> PlayerStarts;
|
|
|
|
UGameplayStatics::GetAllActorsOfClass(this, APlayerStart::StaticClass(), PlayerStarts);
|
|
|
|
const int32 Selection = FMath::RandRange(0, PlayerStarts.Num() - 1);
|
|
|
|
RestartPlayerAtPlayerStart(EliminatedController, PlayerStarts[Selection]);
|
|
|
|
}
|
2022-05-07 15:11:53 +00:00
|
|
|
}
|