diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 3966ce80..a993997e 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:d567687e62b21f8c8c96c320928de71d9c2de143c13ae51aa7484f74e0abe0bc -size 25589 +oid sha256:3192f3e53f9cde4484a9e8fd75184a71bf9ea1da5876fee94ceded15c274685a +size 26191 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Combat.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Combat.uasset new file mode 100644 index 00000000..0562b346 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Combat.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00f4ed84367ee429face15faba364bc15ee2d562096d2f845a3a3a6deb69dc3d +size 1360 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Recon.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Recon.uasset new file mode 100644 index 00000000..aa886642 --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Recon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fc86691c4b8b22416ce275bedd78c738d4b9ee2ddcb59ea7c130933c15a290dd +size 1355 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index ea55777d..55abcd6c 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:1006f1f08d6d5428a9c4689b38adff8ae38cb5a4b71ed3d8831ad0ef4da32363 -size 15167 +oid sha256:3af06cb5478091fcf55d1069e28395f32708276bd53cc5dce82faa2a2d1f822b +size 16317 diff --git a/EndlessVendetta/Content/Gadgets/GM_GadgetManager.uasset b/EndlessVendetta/Content/Gadgets/GM_GadgetManager.uasset new file mode 100644 index 00000000..40b371f1 --- /dev/null +++ b/EndlessVendetta/Content/Gadgets/GM_GadgetManager.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e321d507454cc656ecee8ffaa8ce7a439b7bc824731e2932c160289609e6fe14 +size 22647 diff --git a/EndlessVendetta/Content/Gadgets/TestGadgets/CG_ExampleCombat.uasset b/EndlessVendetta/Content/Gadgets/TestGadgets/CG_ExampleCombat.uasset new file mode 100644 index 00000000..154f762a --- /dev/null +++ b/EndlessVendetta/Content/Gadgets/TestGadgets/CG_ExampleCombat.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5647c792435713b3b313153fd4a9985e6f0a69adca680e12c8e309ff35ee89b9 +size 29363 diff --git a/EndlessVendetta/Content/Gadgets/TestGadgets/IA_UseGadget.uasset b/EndlessVendetta/Content/Gadgets/TestGadgets/IA_UseGadget.uasset new file mode 100644 index 00000000..6ff56db6 --- /dev/null +++ b/EndlessVendetta/Content/Gadgets/TestGadgets/IA_UseGadget.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:612640a4303e85695119bd2552ac09775debae2b5f0e4c04317f4b7bcf45680b +size 1363 diff --git a/EndlessVendetta/Content/Gadgets/TestGadgets/IMC_Gadget.uasset b/EndlessVendetta/Content/Gadgets/TestGadgets/IMC_Gadget.uasset new file mode 100644 index 00000000..bab4f88c --- /dev/null +++ b/EndlessVendetta/Content/Gadgets/TestGadgets/IMC_Gadget.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8c0a91a49b1c3887fd037daaa0033990d9f49625e36b765e196d5f5765a8638a +size 2477 diff --git a/EndlessVendetta/Content/Gadgets/TestGadgets/RC_ExampleRecon.uasset b/EndlessVendetta/Content/Gadgets/TestGadgets/RC_ExampleRecon.uasset new file mode 100644 index 00000000..88a1933b --- /dev/null +++ b/EndlessVendetta/Content/Gadgets/TestGadgets/RC_ExampleRecon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83a5888b61a03cd032e12e5ed42b2aa5f13ca709b06b50ed9726e7404419cfea +size 29907 diff --git a/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap b/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap index 29995f18..7ae1bbe3 100644 --- a/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap +++ b/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9c379fa13b284e76785e0bca667577f04256220a612899c64cdfbbbaaf5b7c47 -size 99918 +oid sha256:5187272f65c655c1bbca4f6a814ab42219fcb74a566fb68d72cc23cfa8b92999 +size 101262 diff --git a/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset b/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset index ec55f660..bf2e4391 100644 --- a/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset +++ b/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:44be6c9290787003db24558430758031dda2c5017643f3439757379c9ec93051 -size 53268 +oid sha256:01ef616c7a8bd90cd1b7a13efb18a56f33346efbae51efa31f09804478b7621d +size 43456 diff --git a/EndlessVendetta/Content/StarterContent/Props/MaterialSphere.uasset b/EndlessVendetta/Content/StarterContent/Props/MaterialSphere.uasset index 56bddfc9..b2376d1b 100644 --- a/EndlessVendetta/Content/StarterContent/Props/MaterialSphere.uasset +++ b/EndlessVendetta/Content/StarterContent/Props/MaterialSphere.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3a8777c01491888bba9f40eda9d2bed76a611f0e80f75917501ce69c1a321342 -size 47333 +oid sha256:f5a41a71ca352997a9dba7abac1a00868a31a8942a621cb7d614a00c0d6311de +size 47710 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 62ffd896..53174fdf 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -50,7 +50,11 @@ void AEndlessVendettaCharacter::BeginPlay() Subsystem->AddMappingContext(DefaultMappingContext, 0); } } - + AActor* GadgetManagerActor = GetWorld()->SpawnActor(GadgetManagerClass, GetActorLocation(), GetActorRotation()); + GadgetManager = Cast(GadgetManagerActor); + FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + GadgetManagerActor->AttachToComponent(GetRootComponent(), AttachmentRules); + GadgetManager->SpawnGadgets(GetRootComponent()); } //////////////////////////////////////////////////////////////////////////// Input @@ -70,6 +74,10 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* //Looking EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::Look); + // Gadget Toggling + EnhancedInputComponent->BindAction(ReconAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleRecon); + EnhancedInputComponent->BindAction(CombatAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleCombat); + //Weapon Switching EnhancedInputComponent->BindAction(EquipPrimaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipPrimary); EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary); @@ -79,6 +87,47 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* } } +void AEndlessVendettaCharacter::ToggleRecon() +{ + if (IsValid(PrimaryWeapon)) EquipPrimary(); + if (IsValid(SecondaryWeapon)) EquipSecondary(); + + if (GadgetManager->IsReconEquipped()) + { + GadgetManager->TryToUnequipRecon(); + return; + } + + if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) + { + // Do nothing if combat is equipped and can't be unequipped at this moment + return; + } + + GadgetManager->EquipRecon(); +} + +void AEndlessVendettaCharacter::ToggleCombat() +{ + if (IsValid(PrimaryWeapon)) EquipPrimary(); + if (IsValid(SecondaryWeapon)) EquipSecondary(); + + if (GadgetManager->IsCombatEquipped()) + { + GadgetManager->TryToUnequipCombat(); + return; + } + + if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) + { + // Do nothing if recon is equipped and can't be unequipped at the moment + return; + } + + GadgetManager->EquipCombat(); +} + + //When 1 is pressed it calls EquipPrimary void AEndlessVendettaCharacter::EquipPrimary() { diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index 46f3e4c0..cf41bef6 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -7,6 +7,7 @@ #include "GameFramework/Character.h" #include "InputActionValue.h" #include "Components/ArrowComponent.h" +#include "GadgetSystem/GadgetManager.h" #include "EndlessVendettaCharacter.generated.h" class UWeaponInventory; @@ -42,6 +43,12 @@ class AEndlessVendettaCharacter : public ACharacter UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) class UInputAction* MoveAction; + // Gadget Actions + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) + UInputAction* ReconAction; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) + UInputAction* CombatAction; + /** Weapon Equip Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) class UInputAction* EquipPrimaryWeapon; @@ -61,6 +68,10 @@ public: protected: virtual void BeginPlay(); + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + TSubclassOf GadgetManagerClass; + AGadgetManager* GadgetManager; + public: /** Look Input Action */ @@ -99,6 +110,10 @@ protected: /** Called for looking input */ void Look(const FInputActionValue& Value); + + void ToggleRecon(); + + void ToggleCombat(); void EquipPrimary(); diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.cpp new file mode 100644 index 00000000..55976a01 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "CombatGadget.h" + diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.h new file mode 100644 index 00000000..7175c889 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/CombatGadget.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GadgetBase.h" +#include "CombatGadget.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API ACombatGadget : public AGadgetBase +{ + GENERATED_BODY() + +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.cpp new file mode 100644 index 00000000..107df86f --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.cpp @@ -0,0 +1,92 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "GadgetBase.h" + +#include "EnhancedInputComponent.h" +#include "EnhancedInputSubsystems.h" + +// Sets default values +AGadgetBase::AGadgetBase() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + +} + +// Called when the game starts or when spawned +void AGadgetBase::BeginPlay() +{ + Super::BeginPlay(); + + PlayerController = GetWorld()->GetFirstPlayerController(); +} + +// Called every frame +void AGadgetBase::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +void AGadgetBase::Equip() +{ + SetActorRelativeLocation(EquippedOffset); + Equipped = true; + + + + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer()); + Subsystem->AddMappingContext(GadgetMappingContext, 2); + UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerController->InputComponent); + EnhancedInputComponent->BindAction(ActivateAction, ETriggerEvent::Started, this, &AGadgetBase::Activate); +} + +bool AGadgetBase::Unequip() +{ + if (GadgetInUse) return false; + + SetActorRelativeLocation(UnequippedOffset); + Equipped = false; + + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer()); + Subsystem->RemoveMappingContext(GadgetMappingContext); + UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerController->InputComponent); + EnhancedInputComponent->ClearActionBindings(); + + return true; +} + +void AGadgetBase::Activate() +{ + StartInUseTimer(); +} + +void AGadgetBase::FinishedUsing() +{ + UE_LOG(LogTemp, Warning, TEXT("Gadget is no longer being used")); + + GadgetInUse = false; + InUseHandle.Invalidate(); + + StartGadgetCooldown(); +} + +// -------------- Timers -------------- + +void AGadgetBase::StartGadgetCooldown() +{ + GadgetOnCooldown = true; + GetWorld()->GetTimerManager().SetTimer(CooldownHandle, this, &AGadgetBase::ReadyGadget, CooldownTime, false); +} + +void AGadgetBase::StartInUseTimer() +{ + UE_LOG(LogTemp, Warning, TEXT("Gadget In Use Timer Started")); + + GadgetInUse = true; + GetWorld()->GetTimerManager().SetTimer(InUseHandle, this, &AGadgetBase::FinishedUsing, GadgetMaxUptime, false); +} + + + diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.h new file mode 100644 index 00000000..37f5190e --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetBase.h @@ -0,0 +1,83 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "EnhancedInputSubsystemInterface.h" +#include "GameFramework/Actor.h" +#include "GadgetBase.generated.h" + +UCLASS() +class ENDLESSVENDETTA_API AGadgetBase : public AActor +{ + GENERATED_BODY() + + APlayerController* PlayerController; + + FTimerHandle CooldownHandle; + void StartGadgetCooldown(); + bool GadgetOnCooldown = false; + + FTimerHandle InUseHandle; + void StartInUseTimer(); + bool GadgetInUse = false; + + void ReadyGadget() + { + UE_LOG(LogTemp, Warning, TEXT("Gadget is now ready to be used again")); + GadgetOnCooldown = false; + } + +protected: + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + FVector EquippedOffset = FVector(0, 0, 0); + + UPROPERTY(EditDefaultsOnly, CAtegory = "Gadget") + FVector UnequippedOffset = FVector(0, 0, -1000); + + UPROPERTY(EditDefaultsOnly, cATEGORY = "Gadget") + float GadgetMaxUptime; + + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + float CooldownTime; + + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + UInputMappingContext* GadgetMappingContext; + + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + UInputAction* ActivateAction; + + // Used by child classes to run custom gadget behaviour + virtual void Activate(); + + // Starts Cooldown and automatically unequips gadget, used by child classes to implement custom behaviour + virtual void FinishedUsing(); + + bool GadgetCantBeUsed() + { + return GadgetOnCooldown|| GadgetInUse; + } + + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + bool Equipped = false; + + void Equip(); + + // Return true if unequip succeeds + bool Unequip(); + + FVector GetUnequippedOffset() + { + return UnequippedOffset; + } + + // Sets default values for this actor's properties + AGadgetBase(); + + // Called every frame + virtual void Tick(float DeltaTime) override; + +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.cpp new file mode 100644 index 00000000..4e759791 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.cpp @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ExampleCombatClass.h" + +void AExampleCombatClass::BeginPlay() +{ + Super::BeginPlay(); + + SetActorTickEnabled(false); +} + + +void AExampleCombatClass::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + UE_LOG(LogTemp, Warning, TEXT("Example Combat is being used...")); +} + +void AExampleCombatClass::Activate() +{ + if (GadgetCantBeUsed()) return; + + Super::Activate(); + SetActorTickEnabled(true); +} + +void AExampleCombatClass::FinishedUsing() +{ + SetActorTickEnabled(false); + + Super::FinishedUsing(); +} \ No newline at end of file diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.h new file mode 100644 index 00000000..d53cfefb --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleCombatClass.h @@ -0,0 +1,24 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "EndlessVendetta/GadgetSystem/CombatGadget.h" +#include "ExampleCombatClass.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API AExampleCombatClass : public ACombatGadget +{ + GENERATED_BODY() + + virtual void BeginPlay() override; + + virtual void Tick(float DeltaSeconds) override; + + virtual void Activate() override; + + virtual void FinishedUsing() override; +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.cpp new file mode 100644 index 00000000..cfa574cf --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.cpp @@ -0,0 +1,35 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ExampleReconClass.h" + +void AExampleReconClass::BeginPlay() +{ + Super::BeginPlay(); + SetActorTickEnabled(false); +} + + +void AExampleReconClass::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + UE_LOG(LogTemp, Warning, TEXT("Example Recon is being used...")); +} + +void AExampleReconClass::Activate() +{ + if (GadgetCantBeUsed()) return; + + Super::Activate(); + SetActorTickEnabled(true); +} + +void AExampleReconClass::FinishedUsing() +{ + SetActorTickEnabled(false); + + Super::FinishedUsing(); +} + + diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.h new file mode 100644 index 00000000..7abc52af --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/ExampleReconClass.h @@ -0,0 +1,25 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "EndlessVendetta/GadgetSystem/ReconGadget.h" +#include "ExampleReconClass.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API AExampleReconClass : public AReconGadget +{ + GENERATED_BODY() + + virtual void BeginPlay() override; + + virtual void Tick(float DeltaSeconds) override; + + virtual void Activate() override; + + virtual void FinishedUsing() override; + +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.cpp new file mode 100644 index 00000000..6e5a8ee4 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.cpp @@ -0,0 +1,45 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "GadgetManager.h" + +// Sets default values +AGadgetManager::AGadgetManager() +{ + // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. + PrimaryActorTick.bCanEverTick = true; + +} + +// Called when the game starts or when spawned +void AGadgetManager::BeginPlay() +{ + Super::BeginPlay(); + +} + +// Called every frame +void AGadgetManager::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + +} + +void AGadgetManager::SpawnGadgets(USceneComponent* PlayersRootComponent) +{ + if (!IsValid(ReconClass) || !IsValid(CombatClass)) UE_LOG(LogTemp, Fatal, TEXT("Recon or Combat class hasn't been set")); + + FActorSpawnParameters SpawnParams; + SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + const FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + + AActor* SpawnedActor = GetWorld()->SpawnActor(ReconClass, GetActorLocation(), GetActorRotation(), SpawnParams); + ReconGadget = Cast(SpawnedActor); + SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules); + SpawnedActor->SetActorRelativeLocation(ReconGadget->GetUnequippedOffset()); + + SpawnedActor = GetWorld()->SpawnActor(CombatClass, GetActorLocation(), GetActorRotation(), SpawnParams); + CombatGadget = Cast(SpawnedActor); + SpawnedActor->AttachToComponent(PlayersRootComponent, AttachmentRules); + SpawnedActor->SetActorRelativeLocation(CombatGadget->GetUnequippedOffset()); +} diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.h new file mode 100644 index 00000000..837c1222 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetManager.h @@ -0,0 +1,75 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "CombatGadget.h" +#include "ReconGadget.h" +#include "GameFramework/Actor.h" +#include "GadgetManager.generated.h" + +UCLASS() +class ENDLESSVENDETTA_API AGadgetManager : public AActor +{ + GENERATED_BODY() + + AReconGadget* ReconGadget; + ACombatGadget* CombatGadget; + +protected: + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + TSubclassOf ReconClass; + UPROPERTY(EditDefaultsOnly, Category = "Gadget") + TSubclassOf CombatClass; + + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + void SpawnGadgets(USceneComponent* PlayersRootComponent); + + // Sets default values for this actor's properties + AGadgetManager(); + + // Called every frame + virtual void Tick(float DeltaTime) override; + + void EquipRecon() + { + ReconGadget->Equip(); + } + + void EquipCombat() + { + CombatGadget->Equip(); + } + + bool IsReconEquipped() + { + return ReconGadget->Equipped; + } + + bool IsCombatEquipped() + { + return CombatGadget->Equipped; + } + + bool TryToUnequipRecon() + { + if (ReconGadget->Equipped) + { + return ReconGadget->Unequip(); + } + return false; + } + + bool TryToUnequipCombat() + { + if (CombatGadget->Equipped) + { + return CombatGadget->Unequip(); + } + return false; + } + +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.cpp new file mode 100644 index 00000000..03c10623 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.cpp @@ -0,0 +1,5 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "ReconGadget.h" + diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.h new file mode 100644 index 00000000..7122d3bb --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/ReconGadget.h @@ -0,0 +1,17 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GadgetBase.h" +#include "ReconGadget.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API AReconGadget : public AGadgetBase +{ + GENERATED_BODY() + +};