diff --git a/Content/Assets/Sounds/Grenade/ThrowGrenade.uasset b/Content/Assets/Sounds/Grenade/ThrowGrenade.uasset new file mode 100644 index 0000000..90abe66 Binary files /dev/null and b/Content/Assets/Sounds/Grenade/ThrowGrenade.uasset differ diff --git a/Content/Assets/Sounds/Grenade/ThrowGrenade_Cue.uasset b/Content/Assets/Sounds/Grenade/ThrowGrenade_Cue.uasset new file mode 100644 index 0000000..2cffa5b Binary files /dev/null and b/Content/Assets/Sounds/Grenade/ThrowGrenade_Cue.uasset differ diff --git a/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset b/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset new file mode 100644 index 0000000..97e1574 Binary files /dev/null and b/Content/Assets/Textures/Grenades/GrenadeIcon_Transparant.uasset differ diff --git a/Content/Blueprints/Character/Animation/ThrowGrenade.uasset b/Content/Blueprints/Character/Animation/ThrowGrenade.uasset index f43e443..b53a194 100644 Binary files a/Content/Blueprints/Character/Animation/ThrowGrenade.uasset and b/Content/Blueprints/Character/Animation/ThrowGrenade.uasset differ diff --git a/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset b/Content/Blueprints/HUD/WBP_CharacterOverlay.uasset index 287227c..e960b4f 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/BlasterCharacter.cpp b/Source/Blaster/Character/BlasterCharacter.cpp index 63b1b16..27c0249 100644 --- a/Source/Blaster/Character/BlasterCharacter.cpp +++ b/Source/Blaster/Character/BlasterCharacter.cpp @@ -340,6 +340,7 @@ void ABlasterCharacter::PlayHitReactMontage() void ABlasterCharacter::ReceiveDamage(AActor* DamagedActor, float Damage, const UDamageType* DamageType, AController* InstigatorController, AActor* DamageCauser) { + if (bEliminated) return; Health = FMath::Clamp(Health - Damage, 0.f, MaxHealth); UpdateHUDHealth(); if (Health > 0.f) diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index b623253..a64e32a 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -28,6 +28,7 @@ void UCombatComponent::GetLifetimeReplicatedProps(TArray& Out DOREPLIFETIME(UCombatComponent, bAiming); DOREPLIFETIME_CONDITION(UCombatComponent, CarriedAmmo, COND_OwnerOnly); DOREPLIFETIME(UCombatComponent, CombatState); + DOREPLIFETIME(UCombatComponent, Grenades); } void UCombatComponent::BeginPlay() @@ -389,6 +390,7 @@ int32 UCombatComponent::AmountToReload() void UCombatComponent::ThrowGrenade() { + if (Grenades == 0) return; if (CombatState != ECombatState::ECS_Unoccupied || EquippedWeapon == nullptr) return; CombatState = ECombatState::ECS_ThrowingGrenade; if (Character) @@ -401,10 +403,16 @@ void UCombatComponent::ThrowGrenade() { ServerThrowGrenade(); } + if (Character && Character->HasAuthority()) + { + Grenades = FMath::Clamp(Grenades -1, 0, MaxGrenades); + UpdateHUDGrenades(); + } } void UCombatComponent::ServerThrowGrenade_Implementation() { + if (Grenades == 0) return; CombatState = ECombatState::ECS_ThrowingGrenade; if (Character) { @@ -412,6 +420,22 @@ void UCombatComponent::ServerThrowGrenade_Implementation() AttachActorToLeftHand(EquippedWeapon); ShowAttachedGrenade(true); } + Grenades = FMath::Clamp(Grenades -1, 0, MaxGrenades); + UpdateHUDGrenades(); +} + +void UCombatComponent::OnRep_Grenades() +{ + UpdateHUDGrenades(); +} + +void UCombatComponent::UpdateHUDGrenades() +{ + Controller = Controller == nullptr ? Cast(Character->Controller) : Controller;Controller = Controller == nullptr ? Cast(Character->Controller) : Controller; + if (Controller) + { + Controller->SetHUDGrenades(Grenades); + } } void UCombatComponent::ShowAttachedGrenade(bool bShowGrenade) diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index ee85433..dda632e 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -42,6 +42,8 @@ public: UFUNCTION(Server, Reliable) void ServerLaunchGrenade(const FVector_NetQuantize& Target); + + FORCEINLINE int32 GetGrenades() const { return Grenades; } protected: virtual void BeginPlay() override; @@ -180,4 +182,15 @@ private: void UpdateAmmoValues(); void UpdateShotgunAmmoValues(); + + UPROPERTY(ReplicatedUsing = OnRep_Grenades) + int32 Grenades = 4; + + UFUNCTION() + void OnRep_Grenades(); + + UPROPERTY(EditAnywhere) + int32 MaxGrenades = 4; + + void UpdateHUDGrenades(); }; diff --git a/Source/Blaster/HUD/CharacterOverlay.h b/Source/Blaster/HUD/CharacterOverlay.h index 874a491..09e1e85 100644 --- a/Source/Blaster/HUD/CharacterOverlay.h +++ b/Source/Blaster/HUD/CharacterOverlay.h @@ -37,4 +37,7 @@ public: UPROPERTY(meta = (BindWidget)) UTextBlock* MatchCountdownText; + UPROPERTY(meta = (BindWidget)) + UTextBlock* GrenadesAmount; + }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 287d442..0c2d1de 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -227,6 +227,22 @@ void ABlasterPlayerController::SetHUDCarriedAmmo(int32 Ammo) } } +void ABlasterPlayerController::SetHUDGrenades(int32 Grenades) +{ + BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; + bool bHUDValid = BlasterHUD && + BlasterHUD->CharacterOverlay && + BlasterHUD->CharacterOverlay->GrenadesAmount; + if (bHUDValid) + { + FString GrenadesText = FString::Printf(TEXT("%d"), Grenades); + BlasterHUD->CharacterOverlay->GrenadesAmount->SetText(FText::FromString(GrenadesText)); + } else + { + HUDGrenades = Grenades; + } +} + void ABlasterPlayerController::SetHUDMatchCountdown(float CountdownTime) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; @@ -327,6 +343,12 @@ void ABlasterPlayerController::PollInit() SetHUDHealth(HUDHealth, HUDMaxHealth); SetHUDScore(HUDScore); SetHUDDefeats(HUDDefeats); + ABlasterCharacter* BlasterCharacter = Cast(GetPawn()); + if (BlasterCharacter && BlasterCharacter->GetCombat()) + { + SetHUDGrenades(BlasterCharacter->GetCombat()->GetGrenades()); + } + } } } diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index daa9e22..2928dc8 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -28,11 +28,13 @@ public: void SetDebugMsg5(FString Key, FString Value); void SetDebugMsg6(FString Key, FString Value); void SetDebugMsg7(FString Key, FString Value); + void SetHUDHealth(float Health, float MaxHealth); void SetHUDScore(float Score); void SetHUDDefeats(int32 Defeats); void SetHUDWeaponAmmo(int32 Ammo); void SetHUDCarriedAmmo(int32 Ammo); + void SetHUDGrenades(int32 Grenades); void SetHUDMatchCountdown(float CountdownTime); void SetHUDAnnouncementCountdown(float CountdownTime); @@ -104,5 +106,6 @@ private: float HUDMaxHealth; float HUDScore; int32 HUDDefeats; + int32 HUDGrenades; };