diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index b8058c13..601240df 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -278,7 +278,6 @@ void AEndlessVendettaCharacter::EquipPrimary() spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); FDetachmentTransformRules DetatchRules(EDetachmentRule::KeepWorld, false); - if (bIsReloading) return; if (IsValid(PrimaryWeapon)) { @@ -292,31 +291,28 @@ void AEndlessVendettaCharacter::EquipPrimary() GLog->Log("Primary Weapon Put Away"); return; } + if(bIsWeaponPickedUp) + { + PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); + bIsWeaponPickedUp = false; + } if (IsValid(SecondaryWeapon)) EquipSecondary(); if (GadgetManager->IsValidReconGadget() && GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return; if (GadgetManager->IsValidCombatGadget() && GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return; - - //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass - - //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object - //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor - - if(!IsValid(PrimaryWeapon)) + bHasRifle = true; + if(!bIsPrimaryWeaponCreated) { - bHasRifle = true; - if(!bIsPrimaryWeaponCreated) - { - PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); - PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - PrimaryWeapon = Cast(PrimaryWeaponActor); - PrimaryWeapon->SetActorHiddenInGame(false); - bIsPrimaryWeaponCreated = true; - } - //UE_LOG(LogTemp, Warning, TEXT("Primary Weapon Is Hidden: %hhd"), PrimaryWeapon->IsHidden()); - GLog->Log("Primary Weapon Equipped"); + //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass + //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object + //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor + PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); + PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); + PrimaryWeapon = Cast(PrimaryWeaponActor); + PrimaryWeapon->SetActorHiddenInGame(false); + bIsPrimaryWeaponCreated = true; } PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); PrimaryWeapon = Cast(PrimaryWeaponActor); @@ -344,6 +340,12 @@ void AEndlessVendettaCharacter::EquipSecondary() GLog->Log("Secondary Weapon Put Away"); return; } + + if(bIsWeaponPickedUp) + { + PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); + bIsWeaponPickedUp = false; + } if (IsValid(PrimaryWeapon)) EquipPrimary(); @@ -372,13 +374,28 @@ void AEndlessVendettaCharacter::EquipSecondary() void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit) { - if (IsValid(PrimaryWeapon)) + if(Outhit->ActorHasTag("PrimaryWeapon")) { + if (IsValid(PrimaryWeapon)) + { + EquipPrimary(); + } + bIsWeaponPickedUp = true; + PrimaryWeaponClass = Outhit->GetClass(); + Outhit->Destroy(); EquipPrimary(); } - PrimaryWeaponClass = Outhit->GetClass(); - Outhit->Destroy(); - EquipPrimary(); + if(Outhit->ActorHasTag("SecondaryWeapon")) + { + if (IsValid(SecondaryWeapon)) + { + EquipSecondary(); + } + bIsWeaponPickedUp = true; + SecondaryWeaponClass = Outhit->GetClass(); + Outhit->Destroy(); + EquipSecondary(); + } } //Calls the fire function in the baseWeaponClass diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index c4b70eeb..106416a8 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -85,6 +85,7 @@ public: AActor* SecondaryWeaponActor; bool bIsPrimaryWeaponCreated = false; bool bIsSecondaryWeaponCreated = false; + bool bIsWeaponPickedUp = false; protected: virtual void BeginPlay() override;