From ce52c1bf6ca495d98b6b9b031ff0b7a470dc7d8a Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Mon, 13 May 2024 22:51:39 +0100 Subject: [PATCH] Bugfix Gun Pending to be Destroyed --- .../EndlessVendetta/EndlessVendettaCharacter.cpp | 12 ++++++++---- .../EndlessVendetta/EndlessVendettaCharacter.h | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 41aa0ea4..8d02d48f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -493,6 +493,7 @@ void AEndlessVendettaCharacter::EquipPrimary() PrimaryWeapon->HideNeedReloadUI(); this->GetFirstPersonCameraComponent()->SetFieldOfView(90); UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden()); + PreviousPrimaryAmmoCount = PrimaryWeapon->currentAmmoCount; PrimaryWeapon = nullptr; bHasRifle = false; GLog->Log("Primary Weapon Put Away"); @@ -535,9 +536,9 @@ void AEndlessVendettaCharacter::EquipPrimary() if (PrimaryWeaponClass != nullptr) { int PreviousAmmoCount = -1; - if (PrimaryWeaponClass == PrimaryWeaponActor->GetClass()) + if (PrimaryWeaponClass == PreviousPrimaryWeaponClass) { - PreviousAmmoCount = Cast(PrimaryWeaponActor)->currentAmmoCount; + PreviousAmmoCount = PreviousPrimaryAmmoCount; } HeldWeapon->SetChildActorClass(PrimaryWeaponClass); if (PreviousAmmoCount >= 0) @@ -545,6 +546,7 @@ void AEndlessVendettaCharacter::EquipPrimary() Cast(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount; } PrimaryWeaponActor = HeldWeapon->GetChildActor(); + PreviousPrimaryWeaponClass = PrimaryWeaponClass; PrimaryWeapon = Cast(PrimaryWeaponActor); PrimaryWeapon->SetActorHiddenInGame(false); PrimaryWeapon->SetActorEnableCollision(false); @@ -579,6 +581,7 @@ void AEndlessVendettaCharacter::EquipSecondary() SecondaryWeapon->HideNeedReloadUI(); UE_LOG(LogTemp, Warning, TEXT("Secondary Weapon Is Hidden: %hhd"), SecondaryWeapon->IsHidden()); //the nullptr makes it so we can unequip and requip the same weapon + PreviousSecondaryAmmoCount = SecondaryWeapon->currentAmmoCount; SecondaryWeapon = nullptr; bIsCurrentlyHoldingWeapon = false; bHasRifle = false; @@ -613,9 +616,9 @@ void AEndlessVendettaCharacter::EquipSecondary() if (SecondaryWeaponClass != nullptr) { int PreviousAmmoCount = -1; - if (SecondaryWeaponClass == SecondaryWeaponActor->GetClass()) + if (SecondaryWeaponClass == PreviousSecondaryWeaponClass) { - PreviousAmmoCount = Cast(SecondaryWeaponActor)->currentAmmoCount; + PreviousAmmoCount = PreviousSecondaryAmmoCount; } HeldWeapon->SetChildActorClass(SecondaryWeaponClass); if (PreviousAmmoCount >= 0) @@ -623,6 +626,7 @@ void AEndlessVendettaCharacter::EquipSecondary() Cast(HeldWeapon->GetChildActor())->currentAmmoCount = PreviousAmmoCount; } SecondaryWeaponActor = HeldWeapon->GetChildActor(); + PreviousSecondaryWeaponClass = SecondaryWeaponClass; SecondaryWeapon = Cast(SecondaryWeaponActor); SecondaryWeapon->SetActorHiddenInGame(false); if (SecondaryWeapon->currentAmmoCount <= 0) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 7b0ba340..edc7197d 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -235,6 +235,16 @@ protected: FTimerHandle NotInCombatTimerHandle; void NotInCombat(); + UPROPERTY() + int PreviousPrimaryAmmoCount = 0; + UPROPERTY() + int PreviousSecondaryAmmoCount = 0; + UPROPERTY() + TSubclassOf PreviousPrimaryWeaponClass; + UPROPERTY() + TSubclassOf PreviousSecondaryWeaponClass; + + public: AGadgetManager* GadgetManager; bool bIsReloading = false;