blaster/Source/Blaster/PlayerState/BlasterPlayerState.cpp

90 lines
1.7 KiB
C++

// 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"
#include "Net/UnrealNetwork.h"
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
{
SetScore(GetScore() + ScoreAmount);
Character = GetCharacter();
if (Character)
{
Controller = GetController();
if (Controller)
{
Controller->SetHUDScore(GetScore());
}
}
}
void ABlasterPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ABlasterPlayerState, Defeats);
}
void ABlasterPlayerState::OnRep_Score()
{
Super::OnRep_Score();
Character = GetCharacter();
if (Character)
{
Controller = GetController();
if (Controller)
{
Controller->SetHUDScore(GetScore());
}
}
}
void ABlasterPlayerState::IncreaseDefeats(int32 DefeatsAmount)
{
Defeats += DefeatsAmount;
Character = GetCharacter();
if (Character)
{
Controller = GetController();
if (Controller)
{
Controller->SetHUDDefeats(Defeats);
}
}
}
void ABlasterPlayerState::OnRep_Defeats()
{
Character = GetCharacter();
if (Character)
{
Controller = GetController();
if (Controller)
{
Controller->SetHUDDefeats(Defeats);
}
}
}
ABlasterCharacter* ABlasterPlayerState::GetCharacter() const
{
return Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
}
ABlasterPlayerController* ABlasterPlayerState::GetController() const
{
if (Character)
{
return Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
}
return nullptr;
}