From 1432b479b28fff4906026a04b1a01f4be0a7518b Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Thu, 28 Sep 2023 11:42:16 +0100 Subject: [PATCH] Added Simple Gun Swapping and un-equip --- .../FPWeapon/Materials/M_FPGunPistol.uasset | 3 ++ .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +- .../Pistols/BP_BasePistolWeapon.uasset | 4 +- .../Architecture/Floor_400x400.uasset | 4 +- .../1/1E/W6O6OMVMAU1GMH2HVWXH3L.uasset | 3 -- .../7/GA/SIX97XFU4YK3BWI9S71SMF.uasset | 3 -- .../EndlessVendettaCharacter.cpp | 52 ++++++++++++++++--- .../EndlessVendettaCharacter.h | 14 +++-- 8 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 EndlessVendetta/Content/FPWeapon/Materials/M_FPGunPistol.uasset delete mode 100644 EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/1/1E/W6O6OMVMAU1GMH2HVWXH3L.uasset delete mode 100644 EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/GA/SIX97XFU4YK3BWI9S71SMF.uasset diff --git a/EndlessVendetta/Content/FPWeapon/Materials/M_FPGunPistol.uasset b/EndlessVendetta/Content/FPWeapon/Materials/M_FPGunPistol.uasset new file mode 100644 index 00000000..1872dca9 --- /dev/null +++ b/EndlessVendetta/Content/FPWeapon/Materials/M_FPGunPistol.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:abb955fc6a17250b071cde3d7a9c1403826533ff48906851ff00c5205df1607d +size 30077 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 0877150a..00b38c8d 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:92f8bdd8d4e8196894411a8141429f15316d83e076b0163070ee174bd3eb4ac7 -size 32087 +oid sha256:46657eb5de2de0259508b2ff818d484f06f895c13f8bb3d04c6fc34ea61659a1 +size 23694 diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset index fe34a700..3f00099b 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BaseWeapons/Pistols/BP_BasePistolWeapon.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:60c71c86a00bef84374641ca7fed67e2338916dba788e69d643a8477add71d97 -size 29026 +oid sha256:202ab16b4ffa35b8b8140c728744b529514cd98e7cf595a674e0bd13bcfbaff9 +size 29227 diff --git a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset index db9c31d9..1ea19b26 100644 --- a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset +++ b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c4714323c517973cefc36046bc8310e35417fac27e8b323667e4a46c5c09ba5f -size 14803 +oid sha256:e5a9006c075f35f1cab65fb02d8034543f6b54e6087f7352477f45abf6640e43 +size 14831 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/1/1E/W6O6OMVMAU1GMH2HVWXH3L.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/1/1E/W6O6OMVMAU1GMH2HVWXH3L.uasset deleted file mode 100644 index fa367335..00000000 --- a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/1/1E/W6O6OMVMAU1GMH2HVWXH3L.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:abfeb59ea7bea538e1b873a97345a0336c40b7c353d167ddd1a4fac4a16dcad6 -size 5061 diff --git a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/GA/SIX97XFU4YK3BWI9S71SMF.uasset b/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/GA/SIX97XFU4YK3BWI9S71SMF.uasset deleted file mode 100644 index bd2505f8..00000000 --- a/EndlessVendetta/Content/__ExternalActors__/FirstPerson/Maps/GunMechanicTester/7/GA/SIX97XFU4YK3BWI9S71SMF.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:4c7be8ced7b103ba47409aefeea3621d8602fcd366160651c53447a7c2f866e4 -size 5097 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index ef3f3c8e..7195bf46 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -16,10 +16,10 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter() { // Character doesnt have a rifle at start bHasRifle = false; - + // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); - + // Create a CameraComponent FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent()); @@ -78,16 +78,54 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* void AEndlessVendettaCharacter::EquipPrimary() { - UE_LOG(LogTemp, Display, TEXT("Primary equipped")); + if (!IsValid(PrimaryWeapon)) + { + if (IsValid(SecondaryWeapon)) EquipSecondary(); + + UE_LOG(LogTemp, Display, TEXT("Primary equipped")); + bHasRifle = true; + FActorSpawnParameters spawnParams; + spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + AActor* PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); + PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); + PrimaryWeapon = Cast(PrimaryWeaponActor); + + } + else if (IsValid(PrimaryWeapon)) + { + PrimaryWeapon->Destroy(); + bHasRifle = false; + + } } void AEndlessVendettaCharacter::EquipSecondary() { - UE_LOG(LogTemp, Display, TEXT("Secondary equipped")); + if (!IsValid(SecondaryWeapon)) + { + if (IsValid(PrimaryWeapon)) EquipPrimary(); + + UE_LOG(LogTemp, Display, TEXT("Secondary equipped")); + bHasRifle = true; + FActorSpawnParameters spawnParams; + spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); + SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); + SecondaryWeapon = Cast(SecondaryWeaponActor); + } + else if (IsValid(SecondaryWeapon)) + { + SecondaryWeapon->Destroy(); + bHasRifle = false; + } } +//POTENTIAL PICKUP SYSTEM NEEDS CHANGING BUT YES + //Called from Player BluePrints -void AEndlessVendettaCharacter::WeaponPickUpSystem(AActor* PickedUpWeapon) +/*void AEndlessVendettaCharacter::WeaponPickUpSystem(AActor* PickedUpWeapon) { ABaseWeaponClass* WeaponInWorld = Cast(PickedUpWeapon); if(WeaponInWorld->IsA(ABaseWeaponClass::StaticClass())) @@ -116,10 +154,10 @@ void AEndlessVendettaCharacter::WeaponPickUpSystem(AActor* PickedUpWeapon) if(SecondaryWeapon) { UE_LOG(LogTemp, Display, TEXT("Secondary Weapon Picked up")); - + } } -} +}*/ void AEndlessVendettaCharacter::Move(const FInputActionValue& Value) diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index c96f307f..c5c020fc 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -6,6 +6,7 @@ #include "BaseWeaponClass.h" #include "GameFramework/Character.h" #include "InputActionValue.h" +#include "Components/ArrowComponent.h" #include "EndlessVendettaCharacter.generated.h" class UWeaponInventory; @@ -74,10 +75,15 @@ public: bool GetHasRifle(); UPROPERTY(EditAnywhere, Category = "Weapons") - TSubclassOf PrimaryWeapon; + TSubclassOf PrimaryWeaponClass; UPROPERTY(EditAnywhere, Category = "Weapons") - TSubclassOf SecondaryWeapon; + TSubclassOf SecondaryWeaponClass; + + ABaseWeaponClass* PrimaryWeapon; + + ABaseWeaponClass* SecondaryWeapon; + protected: /** Called for movement input */ @@ -91,8 +97,8 @@ protected: void EquipSecondary(); //Called from Player BluePrints - UFUNCTION(BlueprintCallable, Category = "Weapons") - void WeaponPickUpSystem(AActor* PickedUpWeapon); + //UFUNCTION(BlueprintCallable, Category = "Weapons") + //void WeaponPickUpSystem(AActor* PickedUpWeapon); protected: // APawn interface