blaster/Source/Blaster/PlayerState/BlasterPlayerState.cpp

92 lines
2.3 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::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
{
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME(ABlasterPlayerState, Defeats);
DOREPLIFETIME(ABlasterPlayerState, Team);
}
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
{
SetScore(GetScore() + ScoreAmount);
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
if (Character)
{
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
if (Controller)
{
Controller->SetHUDScore(GetScore());
}
}
}
void ABlasterPlayerState::OnRep_Score()
{
Super::OnRep_Score();
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
if (Character)
{
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
if (Controller)
{
Controller->SetHUDScore(GetScore());
}
}
}
void ABlasterPlayerState::IncreaseDefeats(int32 DefeatsAmount)
{
Defeats += DefeatsAmount;
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
if (Character)
{
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
if (Controller)
{
Controller->SetHUDDefeats(Defeats);
}
}
}
void ABlasterPlayerState::OnRep_Defeats()
{
Character = Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
if (Character)
{
Controller = Controller == nullptr ? Cast<ABlasterPlayerController>(Character->Controller) : Controller;
if (Controller)
{
Controller->SetHUDDefeats(Defeats);
}
}
}
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);
}
}