2022-05-09 14:33:48 +00:00
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "BlasterPlayerState.h"
|
|
|
|
|
|
|
|
#include "Blaster/Character/BlasterCharacter.h"
|
|
|
|
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
2022-05-09 15:16:41 +00:00
|
|
|
#include "Net/UnrealNetwork.h"
|
2022-05-09 14:33:48 +00:00
|
|
|
|
2022-05-10 20:34:28 +00:00
|
|
|
void ABlasterPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
2022-05-09 14:33:48 +00:00
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
2022-05-09 14:33:48 +00:00
|
|
|
|
2022-05-10 20:34:28 +00:00
|
|
|
DOREPLIFETIME(ABlasterPlayerState, Defeats);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ABlasterPlayerState::AddToScore(float ScoreAmount)
|
|
|
|
{
|
|
|
|
SetScore(GetScore() + ScoreAmount);
|
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Controller)
|
|
|
|
{
|
|
|
|
Controller->SetHUDScore(GetScore());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ABlasterPlayerState::OnRep_Score()
|
|
|
|
{
|
|
|
|
Super::OnRep_Score();
|
|
|
|
|
2022-05-10 20:34:28 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Controller)
|
|
|
|
{
|
|
|
|
Controller->SetHUDScore(GetScore());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 20:34:28 +00:00
|
|
|
void ABlasterPlayerState::AddToDefeats(int32 DefeatsAmount)
|
2022-05-09 15:16:41 +00:00
|
|
|
{
|
|
|
|
Defeats += DefeatsAmount;
|
2022-05-10 20:34:28 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Controller)
|
|
|
|
{
|
|
|
|
Controller->SetHUDDefeats(Defeats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ABlasterPlayerState::OnRep_Defeats()
|
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-10 20:34:28 +00:00
|
|
|
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Controller)
|
|
|
|
{
|
|
|
|
Controller->SetHUDDefeats(Defeats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|