diff --git a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset index 1d7f645..514fc0a 100644 Binary files a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset and b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset differ diff --git a/Source/Blaster/Character/BlasterAnimInstance.h b/Source/Blaster/Character/BlasterAnimInstance.h index 66c88ac..0edd344 100644 --- a/Source/Blaster/Character/BlasterAnimInstance.h +++ b/Source/Blaster/Character/BlasterAnimInstance.h @@ -36,7 +36,8 @@ private: UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) bool bWeaponEquipped; - + + UPROPERTY() class AWeapon* EquippedWeapon; UPROPERTY(BlueprintReadOnly, Category="Movement", meta=(AllowPrivateAccess = "true")) diff --git a/Source/Blaster/Character/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 2011136..c30ceca 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -244,13 +244,14 @@ void ABlasterCharacter::Tick(float DeltaTime) void ABlasterCharacter::PollInit() { - if (PlayerState == nullptr) + if (BlasterPlayerState == nullptr) { - PlayerState = GetPlayerState(); - if (PlayerState) + BlasterPlayerState = GetPlayerState(); + if (BlasterPlayerState) { // Initialize Score now we have the PlayerState - PlayerState->IncreaseScore(0.f); + BlasterPlayerState->IncreaseScore(0.f); + BlasterPlayerState->IncreaseDefeats(0); } } } diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index fdf116b..e4a50d1 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -57,7 +57,9 @@ protected: void PollInit(); private: - class ABlasterPlayerState* PlayerState; + + UPROPERTY() + class ABlasterPlayerState* BlasterPlayerState; UPROPERTY(VisibleAnywhere, Category="Camera") class USpringArmComponent* CameraBoom; @@ -121,6 +123,7 @@ private: UFUNCTION() void OnRep_Health(); + UPROPERTY() class ABlasterPlayerController* BlasterPlayerController; bool bEliminated = false; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index c2387cc..ac74bf0 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -47,8 +47,11 @@ protected: void SetHUDCrosshairs(float DeltaTime); private: + UPROPERTY() class ABlasterCharacter* Character; + UPROPERTY() class ABlasterPlayerController* Controller; + UPROPERTY() class ABlasterHUD* HUD; UPROPERTY(ReplicatedUsing=OnRep_EquippedWeapon) diff --git a/Source/Blaster/GameMode/BlasterGameMode.cpp b/Source/Blaster/GameMode/BlasterGameMode.cpp index 0f719e1..4c8b5d8 100644 --- a/Source/Blaster/GameMode/BlasterGameMode.cpp +++ b/Source/Blaster/GameMode/BlasterGameMode.cpp @@ -19,6 +19,10 @@ void ABlasterGameMode::PlayerEliminated(ABlasterCharacter* EliminatedCharacter, { AttackerPlayerState->IncreaseScore(1.f); } + if (VictimPlayerState) + { + VictimPlayerState->IncreaseDefeats(1); + } if (EliminatedCharacter) { diff --git a/Source/Blaster/HUD/BlasterHUD.h b/Source/Blaster/HUD/BlasterHUD.h index 7ef0b77..d211aae 100644 --- a/Source/Blaster/HUD/BlasterHUD.h +++ b/Source/Blaster/HUD/BlasterHUD.h @@ -34,7 +34,8 @@ public: UPROPERTY(EditAnywhere, Category = "Player Stats") TSubclassOf CharacterOverlayClass; - + + UPROPERTY() class UCharacterOverlay* CharacterOverlay; protected: diff --git a/Source/Blaster/HUD/CharacterOverlay.h b/Source/Blaster/HUD/CharacterOverlay.h index 61544a7..b8094b4 100644 --- a/Source/Blaster/HUD/CharacterOverlay.h +++ b/Source/Blaster/HUD/CharacterOverlay.h @@ -25,4 +25,7 @@ public: UPROPERTY(meta = (BindWidget)) UTextBlock* ScoreValue; + UPROPERTY(meta = (BindWidget)) + UTextBlock* DefeatsValue; + }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index fe7aeab..d75ce2d 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -55,7 +55,22 @@ void ABlasterPlayerController::SetHUDScore(float Score) if (bHUDValid) { - const FString ScoreValue = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score)); - BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreValue)); + const FString ScoreAmount = FString::Printf(TEXT("%d"), FMath::FloorToInt(Score)); + BlasterHUD->CharacterOverlay->ScoreValue->SetText(FText::FromString(ScoreAmount)); + } +} + +void ABlasterPlayerController::SetHUDDefeats(int32 Defeats) +{ + BlasterHUD = BlasterHUD == nullptr ? Cast(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)); } } diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index 0ab21fa..1b95b0b 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -18,6 +18,7 @@ public: void SetHUDHealth(float Health, float MaxHealth); void SetHUDScore(float Score); + void SetHUDDefeats(int32 Defeats); virtual void OnPossess(APawn* InPawn) override; protected: @@ -26,6 +27,7 @@ protected: private: + UPROPERTY() class ABlasterHUD* BlasterHUD; }; diff --git a/Source/Blaster/PlayerState/BlasterPlayerState.cpp b/Source/Blaster/PlayerState/BlasterPlayerState.cpp index 2622399..b09d7f4 100644 --- a/Source/Blaster/PlayerState/BlasterPlayerState.cpp +++ b/Source/Blaster/PlayerState/BlasterPlayerState.cpp @@ -5,6 +5,7 @@ #include "Blaster/Character/BlasterCharacter.h" #include "Blaster/PlayerController/BlasterPlayerController.h" +#include "Net/UnrealNetwork.h" void ABlasterPlayerState::IncreaseScore(float ScoreAmount) { @@ -21,6 +22,13 @@ void ABlasterPlayerState::IncreaseScore(float ScoreAmount) } } +void ABlasterPlayerState::GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const +{ + Super::GetLifetimeReplicatedProps(OutLifetimeProps); + + DOREPLIFETIME(ABlasterPlayerState, Defeats); +} + void ABlasterPlayerState::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 { return Character == nullptr ? Cast(GetPawn()) : Character; diff --git a/Source/Blaster/PlayerState/BlasterPlayerState.h b/Source/Blaster/PlayerState/BlasterPlayerState.h index ae99c8b..20b3fa6 100644 --- a/Source/Blaster/PlayerState/BlasterPlayerState.h +++ b/Source/Blaster/PlayerState/BlasterPlayerState.h @@ -15,12 +15,22 @@ class BLASTER_API ABlasterPlayerState : public APlayerState GENERATED_BODY() public: + virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; virtual void OnRep_Score() override; + UFUNCTION() + virtual void OnRep_Defeats(); + void IncreaseScore(float ScoreAmount); + void IncreaseDefeats(int32 DefeatsAmount); private: + UPROPERTY() class ABlasterCharacter* Character; + UPROPERTY() class ABlasterPlayerController* Controller; ABlasterCharacter* GetCharacter() const; ABlasterPlayerController* GetController() const; + + UPROPERTY(ReplicatedUsing = OnRep_Defeats) + int32 Defeats; }; diff --git a/Source/Blaster/Weapon/Projectile.h b/Source/Blaster/Weapon/Projectile.h index 4e7c5ed..efafd8c 100644 --- a/Source/Blaster/Weapon/Projectile.h +++ b/Source/Blaster/Weapon/Projectile.h @@ -37,6 +37,7 @@ private: UPROPERTY(EditAnywhere) class UParticleSystem* Tracer; + UPROPERTY() class UParticleSystemComponent* TracerComponent; UPROPERTY(EditAnywhere)