108 - Defeats
This commit is contained in:
parent
4261cd8f0d
commit
1eaa5ffca5
Binary file not shown.
|
@ -36,7 +36,8 @@ private:
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
||||||
bool bWeaponEquipped;
|
bool bWeaponEquipped;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
class AWeapon* EquippedWeapon;
|
class AWeapon* EquippedWeapon;
|
||||||
|
|
||||||
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true"))
|
||||||
|
|
|
@ -244,13 +244,14 @@ void ABlasterCharacter::Tick(float DeltaTime)
|
||||||
|
|
||||||
void ABlasterCharacter::PollInit()
|
void ABlasterCharacter::PollInit()
|
||||||
{
|
{
|
||||||
if (PlayerState == nullptr)
|
if (BlasterPlayerState == nullptr)
|
||||||
{
|
{
|
||||||
PlayerState = GetPlayerState<ABlasterPlayerState>();
|
BlasterPlayerState = GetPlayerState<ABlasterPlayerState>();
|
||||||
if (PlayerState)
|
if (BlasterPlayerState)
|
||||||
{
|
{
|
||||||
// Initialize Score now we have the PlayerState
|
// Initialize Score now we have the PlayerState
|
||||||
PlayerState->IncreaseScore(0.f);
|
BlasterPlayerState->IncreaseScore(0.f);
|
||||||
|
BlasterPlayerState->IncreaseDefeats(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,9 @@ protected:
|
||||||
void PollInit();
|
void PollInit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class ABlasterPlayerState* PlayerState;
|
|
||||||
|
UPROPERTY()
|
||||||
|
class ABlasterPlayerState* BlasterPlayerState;
|
||||||
|
|
||||||
UPROPERTY(VisibleAnywhere, Category="Camera")
|
UPROPERTY(VisibleAnywhere, Category="Camera")
|
||||||
class USpringArmComponent* CameraBoom;
|
class USpringArmComponent* CameraBoom;
|
||||||
|
@ -121,6 +123,7 @@ private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnRep_Health();
|
void OnRep_Health();
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterPlayerController* BlasterPlayerController;
|
class ABlasterPlayerController* BlasterPlayerController;
|
||||||
|
|
||||||
bool bEliminated = false;
|
bool bEliminated = false;
|
||||||
|
|
|
@ -47,8 +47,11 @@ protected:
|
||||||
void SetHUDCrosshairs(float DeltaTime);
|
void SetHUDCrosshairs(float DeltaTime);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterCharacter* Character;
|
class ABlasterCharacter* Character;
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterPlayerController* Controller;
|
class ABlasterPlayerController* Controller;
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterHUD* HUD;
|
class ABlasterHUD* HUD;
|
||||||
|
|
||||||
UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon)
|
UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon)
|
||||||
|
|
|
@ -19,6 +19,10 @@ void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter,
|
||||||
{
|
{
|
||||||
AttackerPlayerState->IncreaseScore(1.f);
|
AttackerPlayerState->IncreaseScore(1.f);
|
||||||
}
|
}
|
||||||
|
if (VictimPlayerState)
|
||||||
|
{
|
||||||
|
VictimPlayerState->IncreaseDefeats(1);
|
||||||
|
}
|
||||||
|
|
||||||
if (EliminatedCharacter)
|
if (EliminatedCharacter)
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,7 +34,8 @@ public:
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, Category = "Player Stats")
|
UPROPERTY(EditAnywhere, Category = "Player Stats")
|
||||||
TSubclassOf<class UUserWidget> CharacterOverlayClass;
|
TSubclassOf<class UUserWidget> CharacterOverlayClass;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
class UCharacterOverlay* CharacterOverlay;
|
class UCharacterOverlay* CharacterOverlay;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -25,4 +25,7 @@ public:
|
||||||
UPROPERTY(meta = (BindWidget))
|
UPROPERTY(meta = (BindWidget))
|
||||||
UTextBlock* ScoreValue;
|
UTextBlock* ScoreValue;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
UTextBlock* DefeatsValue;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -55,7 +55,22 @@ void ABlasterPlayerController::SetHUDScore(float Score)
|
||||||
|
|
||||||
if (bHUDValid)
|
if (bHUDValid)
|
||||||
{
|
{
|
||||||
const FString ScoreValue = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score));
|
const FString ScoreAmount = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score));
|
||||||
BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreValue));
|
BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreAmount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ABlasterPlayerController::SetHUDDefeats(int32 Defeats)
|
||||||
|
{
|
||||||
|
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||||
|
bool bHUDValid =
|
||||||
|
BlasterHUD &&
|
||||||
|
BlasterHUD->CharacterOverlay &&
|
||||||
|
BlasterHUD->CharacterOverlay->DefeatsValue;
|
||||||
|
|
||||||
|
if (bHUDValid)
|
||||||
|
{
|
||||||
|
const FString DefeatsAmount = FString::Printf(TEXT("%d"), Defeats);
|
||||||
|
BlasterHUD->CharacterOverlay->DefeatsValue->SetText(FText::FromString(DefeatsAmount));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
|
|
||||||
void SetHUDHealth(float Health, float MaxHealth);
|
void SetHUDHealth(float Health, float MaxHealth);
|
||||||
void SetHUDScore(float Score);
|
void SetHUDScore(float Score);
|
||||||
|
void SetHUDDefeats(int32 Defeats);
|
||||||
virtual void OnPossess(APawn* InPawn) override;
|
virtual void OnPossess(APawn* InPawn) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -26,6 +27,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterHUD* BlasterHUD;
|
class ABlasterHUD* BlasterHUD;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "Blaster/Character/BlasterCharacter.h"
|
#include "Blaster/Character/BlasterCharacter.h"
|
||||||
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
#include "Blaster/PlayerController/BlasterPlayerController.h"
|
||||||
|
#include "Net/UnrealNetwork.h"
|
||||||
|
|
||||||
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
|
void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
|
||||||
{
|
{
|
||||||
|
@ -21,6 +22,13 @@ void ABlasterPlayerState::IncreaseScore(float ScoreAmount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABlasterPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||||
|
{
|
||||||
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||||
|
|
||||||
|
DOREPLIFETIME(ABlasterPlayerState, Defeats);
|
||||||
|
}
|
||||||
|
|
||||||
void ABlasterPlayerState::OnRep_Score()
|
void ABlasterPlayerState::OnRep_Score()
|
||||||
{
|
{
|
||||||
Super::OnRep_Score();
|
Super::OnRep_Score();
|
||||||
|
@ -36,6 +44,34 @@ void ABlasterPlayerState::OnRep_Score()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
ABlasterCharacter* ABlasterPlayerState::GetCharacter() const
|
||||||
{
|
{
|
||||||
return Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
return Character == nullptr ? Cast<ABlasterCharacter>(GetPawn()) : Character;
|
||||||
|
|
|
@ -15,12 +15,22 @@ class BLASTER_API ABlasterPlayerState : public APlayerState
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
virtual void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
|
||||||
virtual void OnRep_Score() override;
|
virtual void OnRep_Score() override;
|
||||||
|
UFUNCTION()
|
||||||
|
virtual void OnRep_Defeats();
|
||||||
|
|
||||||
void IncreaseScore(float ScoreAmount);
|
void IncreaseScore(float ScoreAmount);
|
||||||
|
void IncreaseDefeats(int32 DefeatsAmount);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterCharacter* Character;
|
class ABlasterCharacter* Character;
|
||||||
|
UPROPERTY()
|
||||||
class ABlasterPlayerController* Controller;
|
class ABlasterPlayerController* Controller;
|
||||||
ABlasterCharacter* GetCharacter() const;
|
ABlasterCharacter* GetCharacter() const;
|
||||||
ABlasterPlayerController* GetController() const;
|
ABlasterPlayerController* GetController() const;
|
||||||
|
|
||||||
|
UPROPERTY(ReplicatedUsing = OnRep_Defeats)
|
||||||
|
int32 Defeats;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,6 +37,7 @@ private:
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
class UParticleSystem* Tracer;
|
class UParticleSystem* Tracer;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
class UParticleSystemComponent* TracerComponent;
|
class UParticleSystemComponent* TracerComponent;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere)
|
UPROPERTY(EditAnywhere)
|
||||||
|
|
Loading…
Reference in New Issue