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-12 13:37:49 +00:00
|
|
|
void ABlasterPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
|
|
|
{
|
|
|
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
|
|
|
|
|
|
|
DOREPLIFETIME(ABlasterPlayerState, Defeats);
|
2022-05-30 13:48:46 +00:00
|
|
|
DOREPLIFETIME(ABlasterPlayerState, Team);
|
2022-05-12 13:37:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-09 14:33:48 +00:00
|
|
|
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
|
|
|
|
{
|
|
|
|
SetScore(GetScore() + ScoreAmount);
|
2022-05-12 13:37:49 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-12 13:37:49 +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-12 13:37:49 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 14:33:48 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-12 13:37:49 +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-09 15:16:41 +00:00
|
|
|
void ABlasterPlayerState::IncreaseDefeats(int32 DefeatsAmount)
|
|
|
|
{
|
|
|
|
Defeats += DefeatsAmount;
|
2022-05-12 13:37:49 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-12 13:37:49 +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-12 13:37:49 +00:00
|
|
|
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Character)
|
|
|
|
{
|
2022-05-12 13:37:49 +00:00
|
|
|
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
|
2022-05-09 15:16:41 +00:00
|
|
|
if (Controller)
|
|
|
|
{
|
|
|
|
Controller->SetHUDDefeats(Defeats);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-30 17:04:30 +00:00
|
|
|
|
|
|
|
void ABlasterPlayerState::SetTeam(ETeam TeamToSet)
|
|
|
|
{
|
|
|
|
Team = TeamToSet;
|
|
|
|
ABlasterCharacter* BCharacter = Cast<ABlasterCharacter>(GetPawn());
|
|
|
|
if (BCharacter)
|
|
|
|
{
|
|
|
|
BCharacter->SetTeamColor(Team);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ABlasterPlayerState::OnRep_Team()
|
|
|
|
{
|
|
|
|
ABlasterCharacter* BCharacter = Cast<ABlasterCharacter>(GetPawn());
|
|
|
|
if (BCharacter)
|
|
|
|
{
|
|
|
|
BCharacter->SetTeamColor(Team);
|
|
|
|
}
|
|
|
|
}
|