diff --git a/Source/Blaster/Components/CombatComponent.cpp b/Source/Blaster/Components/CombatComponent.cpp index 608c848..7e3468e 100644 --- a/Source/Blaster/Components/CombatComponent.cpp +++ b/Source/Blaster/Components/CombatComponent.cpp @@ -166,7 +166,7 @@ void UCombatComponent::ServerSetAiming_Implementation(bool bIsAiming) void UCombatComponent::Fire() { - if (bCanFire) + if (CanFire()) { bCanFire = false; ServerFire(HitTarget); @@ -209,6 +209,13 @@ void UCombatComponent::FireTimerFinished() } } +bool UCombatComponent::CanFire() +{ + if (EquippedWeapon == nullptr) return false; + + return !EquippedWeapon->IsEmpty() || !bCanFire; +} + void UCombatComponent::ServerFire_Implementation(const FVector_NetQuantize& TraceHitTarget) { MulticastFire(TraceHitTarget); diff --git a/Source/Blaster/Components/CombatComponent.h b/Source/Blaster/Components/CombatComponent.h index ac74bf0..ce1fc43 100644 --- a/Source/Blaster/Components/CombatComponent.h +++ b/Source/Blaster/Components/CombatComponent.h @@ -98,4 +98,6 @@ private: void StartFireTimer(); void FireTimerFinished(); + + bool CanFire(); }; diff --git a/Source/Blaster/Weapon/Weapon.cpp b/Source/Blaster/Weapon/Weapon.cpp index 97d0364..2a8b863 100644 --- a/Source/Blaster/Weapon/Weapon.cpp +++ b/Source/Blaster/Weapon/Weapon.cpp @@ -112,8 +112,7 @@ void AWeapon::SetHUDAmmo() void AWeapon::SpendRound() { - --Ammo; - + Ammo = FMath::Clamp(Ammo - 1, 0, MagCapacity); SetHUDAmmo(); } @@ -146,6 +145,11 @@ void AWeapon::SetWeaponState(EWeaponState State) } } +bool AWeapon::IsEmpty() +{ + return Ammo <= 0; +} + void AWeapon::OnRep_WeaponState() { switch (WeaponState) diff --git a/Source/Blaster/Weapon/Weapon.h b/Source/Blaster/Weapon/Weapon.h index 4f22af5..7a21a79 100644 --- a/Source/Blaster/Weapon/Weapon.h +++ b/Source/Blaster/Weapon/Weapon.h @@ -128,5 +128,5 @@ public: FORCEINLINE USkeletalMeshComponent* GetWeaponMesh() const { return WeaponMesh; }; FORCEINLINE float GetZoomedFOV() const { return ZoomedFOV; }; FORCEINLINE float GetZoomInterpSpeed() const { return ZoomInterpSpeed; }; - + bool IsEmpty(); };