blaster/Source/Blaster/GameMode/BlasterGameMode.cpp

49 lines
1.6 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "BlasterGameMode.h"
#include "Blaster/Character/BlasterCharacter.h"
#include "Blaster/PlayerController/BlasterPlayerController.h"
#include "Blaster/PlayerState/BlasterPlayerState.h"
#include "GameFramework/PlayerStart.h"
#include "Kismet/GameplayStatics.h"
void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, ABlasterPlayerController* VictimController,
ABlasterPlayerController* AttackerController)
{
ABlasterPlayerState* AttackerPlayerState = AttackerController ? Cast<ABlasterPlayerState>(AttackerController->PlayerState) : nullptr;
ABlasterPlayerState* VictimPlayerState = VictimController ? Cast<ABlasterPlayerState>(VictimController->PlayerState) : nullptr;
if (AttackerPlayerState && AttackerPlayerState != VictimPlayerState)
{
AttackerPlayerState->IncreaseScore(1.f);
}
if (VictimPlayerState)
{
VictimPlayerState->IncreaseDefeats(1);
}
if (EliminatedCharacter)
{
EliminatedCharacter->Eliminated();
}
}
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]);
}
}