From 0e401a6f62531b713ec50bb7eafa4f7856e44c07 Mon Sep 17 00:00:00 2001 From: MH261677 Date: Sun, 8 Oct 2023 15:06:31 +0100 Subject: [PATCH] Added reload functionality for all current and future weapons --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 ++-- .../Input/Actions/IA_Reload.uasset | 3 +++ .../FirstPerson/Input/IMC_Default.uasset | 4 ++-- .../EndlessVendettaCharacter.cpp | 15 ++++++++++++ .../EndlessVendettaCharacter.h | 6 +++++ .../WeaponSystem/BaseWeaponClass.cpp | 23 +++++++++++++++---- .../WeaponSystem/BaseWeaponClass.h | 5 ++++ 7 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Reload.uasset diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 441dabb0..18599c44 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ff90caf01f6ea20dccd612ea5629215ce5c5a4a63e4da2ec242cabf9000bd6c6 -size 42353 +oid sha256:a408fa1c344f5612f1ed59bfeefbd99f2fc986c49f66bf42e849db73e65fdc2e +size 42307 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Reload.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Reload.uasset new file mode 100644 index 00000000..5ed3f2f9 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Reload.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85ff514d76166f7c202ee64b678abe6314dcc24d3d662883b53edb7608ea2bfe +size 1647 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index bb4e7fab..4cea87c6 100644 --- a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset +++ b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6a0af94b654f58c85c8b4453fa211608ecc7bc67b9c82e2e3768814e906babcd -size 16334 +oid sha256:ff3f732c27d0c0064f659482af85f116bc5eb967b29d3ca42bdc2324c3662cd8 +size 16910 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 93a21cd9..fa579aa4 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -91,6 +91,9 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::FireCaller); EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunRightClick); EnhancedInputComponent->BindAction(GunAimInAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::StopGunRightClick); + + //Weapon Reloading + EnhancedInputComponent->BindAction(GunReloadAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::GunReload); } } @@ -256,6 +259,18 @@ void AEndlessVendettaCharacter::StopGunRightClick() } } +void AEndlessVendettaCharacter::GunReload() +{ + if (IsValid(PrimaryWeapon)) + { + PrimaryWeapon->WeaponReload(); + } + if (IsValid(SecondaryWeapon)) + { + SecondaryWeapon->WeaponReload(); + } +} + void AEndlessVendettaCharacter::Move(const FInputActionValue& Value) { diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 8762426a..fdd1718f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -61,6 +61,9 @@ class AEndlessVendettaCharacter : public ACharacter UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) class UInputAction* GunAimInAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) + class UInputAction* GunReloadAction; public: AEndlessVendettaCharacter(); @@ -109,6 +112,9 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void StopGunRightClick(); + UFUNCTION(BlueprintCallable, Category = "Weapons") + void GunReload(); + UArrowComponent* ScopedLocationArrow; UPROPERTY(EditAnywhere, Category = "Dont Touch") diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp index 5a282ae0..65dcbc96 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.cpp @@ -44,6 +44,10 @@ void ABaseWeaponClass::BeginPlay() originalMaxAngleLeft = recoilMaxAngleLeft; originalMaxAngleRight = recoilMaxAngleRight; originalMinMultiplier = recoilMinMultiplier; + + currentAmmoCount = MagazineSize; + + UE_LOG(LogTemp, Display, TEXT("crnnt ammo: %d"), MagazineSize); } // Called every frame @@ -134,7 +138,7 @@ void ABaseWeaponClass::CancelFire() void ABaseWeaponClass::Fire() { - if(MagazineSize > 0) + if(currentAmmoCount > 0) { //do damage fallof based off distance FHitResult outHit; @@ -153,8 +157,8 @@ void ABaseWeaponClass::Fire() //Debug line to see where the trace hit DrawDebugLine(this->GetWorld(), traceStart, traceEnd, FColor::Red, false, 5.0f, 0U, 2.5f); playerControllerRef->PlayerCameraManager->StartCameraShake(CameraShakeClass, 1); - MagazineSize -= 1; - UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), MagazineSize); + currentAmmoCount -= 1; + UE_LOG(LogTemp, Display, TEXT("Ammo Count: %d"), currentAmmoCount); GenerateRecoilVector(); ClickDetectionTimer(); if (outHit.bBlockingHit) @@ -162,9 +166,9 @@ void ABaseWeaponClass::Fire() UE_LOG(LogTemp, Display, TEXT("hit item: %s"), *outHit.GetActor()->GetName()); } } - else if(MagazineSize <= 0) + else if(currentAmmoCount <= 0) { - UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), MagazineSize); + UE_LOG(LogTemp, Display, TEXT("No ammo, Ammo count: %d"), currentAmmoCount); } } @@ -188,4 +192,13 @@ void ABaseWeaponClass::WeaponScopedFire() } } +void ABaseWeaponClass::WeaponReload() +{ + if(MagazineSize > currentAmmoCount) + { + UE_LOG(LogTemp, Display, TEXT("Weapon Reloading: mag size: %d"), MagazineSize); + currentAmmoCount = MagazineSize; + } +} + diff --git a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h index 8eb2d617..1d07fb65 100644 --- a/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h +++ b/EndlessVendetta/Source/EndlessVendetta/WeaponSystem/BaseWeaponClass.h @@ -110,6 +110,9 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void WeaponScopedFire(); + UFUNCTION(BlueprintCallable, Category = "Weapons") + void WeaponReload(); + private: UArrowComponent* GunStartArrow; @@ -121,5 +124,7 @@ private: float originalMaxAngleLeft; float originalMaxAngleRight; float originalMinMultiplier; + + int currentAmmoCount; };