From 51a96c9fb1881c5d2794c3f68203832be95f1ed3 Mon Sep 17 00:00:00 2001 From: Kingsmedia Date: Thu, 26 May 2022 13:29:49 +0200 Subject: [PATCH] 171 - Local Fire Effects --- Source/Blaster/Components/CombatComponent.cpp | 9 +++++++++ Source/Blaster/Components/CombatComponent.h | 1 + Source/Blaster/Weapon/Weapon.cpp | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 088b0ba..ffd88ae 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -103,6 +103,7 @@ void UCombatComponent::Fire() { bCanFire = false; ServerFire(HitTarget); + LocalFire(HitTarget); if (PrimaryWeapon) { CrosshairShootingFactor = .75f; @@ -139,6 +140,12 @@ void UCombatComponent::ServerFire_Implementation(const FVector_NetQuantize& Trac } void UCombatComponent::MulticastFire_Implementation(const FVector_NetQuantize& TraceHitTarget) +{ + if (Character && Character->IsLocallyControlled() && !Character->HasAuthority()) return; + LocalFire(TraceHitTarget); +} + +void UCombatComponent::LocalFire(const FVector_NetQuantize& TraceHitTarget) { if (PrimaryWeapon == nullptr) return; if (Character && CombatState == ECombatState::ECS_Reloading && PrimaryWeapon->IsShotgun()) @@ -175,6 +182,8 @@ void UCombatComponent::EquipWeapon(AWeapon* WeaponToEquip) void UCombatComponent::SwapWeapons() { + if (CombatState != ECombatState::ECS_Unoccupied) return; + AWeapon* TempWeapon = PrimaryWeapon; PrimaryWeapon = SecondaryWeapon; SecondaryWeapon = TempWeapon; diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index bc973e0..c06db29 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -152,6 +152,7 @@ private: void StartFireTimer(); void FireTimerFinished(); + void LocalFire(const FVector_NetQuantize& TraceHitTarget); bool CanFire(); diff --git a/Source/Blaster/Weapon/Weapon.cpp b/Source/Blaster/Weapon/Weapon.cpp index a7a4b3f..4497957 100644 --- a/Source/Blaster/Weapon/Weapon.cpp +++ b/Source/Blaster/Weapon/Weapon.cpp @@ -270,7 +270,10 @@ void AWeapon::Fire(const FVector& HitTarget) } } } - SpendRound(); + if (HasAuthority()) + { + SpendRound(); + } } void AWeapon::Dropped()