From 2a9e30108dac66687cd408a8f54907500abddb4c Mon Sep 17 00:00:00 2001 From: Rafal Swierczek <34179rs@gmail.com> Date: Sun, 8 Oct 2023 19:35:08 +0100 Subject: [PATCH] Implemented Ring Module Class Functionality --- .../OverloadModule/CG_OverloadModule.uasset | 4 +- .../Content/Levels/GadgetSystemTestLevel.umap | 2 +- .../Architecture/Floor_400x400.uasset | 4 +- .../Particles/P_Ambient_Dust.uasset | 4 +- .../Combat/OverloadModule/OverloadModule.cpp | 4 +- .../Recon/RingModule/RingModule.cpp | 99 +++++++++++++++++++ .../Recon/RingModule/RingModule.h | 68 +++++++++++++ 7 files changed, 175 insertions(+), 10 deletions(-) create mode 100644 EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.h diff --git a/EndlessVendetta/Content/Gadgets/CombatGadgets/OverloadModule/CG_OverloadModule.uasset b/EndlessVendetta/Content/Gadgets/CombatGadgets/OverloadModule/CG_OverloadModule.uasset index 92c1b889..918f8800 100644 --- a/EndlessVendetta/Content/Gadgets/CombatGadgets/OverloadModule/CG_OverloadModule.uasset +++ b/EndlessVendetta/Content/Gadgets/CombatGadgets/OverloadModule/CG_OverloadModule.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7deabddf98ca24dc431c4e0f2c25ba9b0d9edf03e2637c6a3dc37a1ccf7e8068 -size 109849 +oid sha256:54c29d51176ad4d6f3709487c680854c3f65197fd77c3fdf909aacebf0012925 +size 109955 diff --git a/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap b/EndlessVendetta/Content/Levels/GadgetSystemTestLevel.umap index f0cfe02e..91a8ae16 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:2bc44125551b89f13cdffde72a42c09685d26b6bbaa3ce8d28858ab14d83c0dc +oid sha256:77cadba64fcbb3018eab09695343339696bd1a1fbcfb39ee13aca7d57c7b4bab size 108254 diff --git a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset index 5f70301d..c2a34afc 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:4f19f519f4b4bc1050bc5b9bf94607306785bb5773b00ddafc385746c3885373 -size 14831 +oid sha256:4c0ecf0ac0702cc2bd355ec050232a61c49e10f102448efbeb735a51824adef6 +size 14948 diff --git a/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset b/EndlessVendetta/Content/StarterContent/Particles/P_Ambient_Dust.uasset index bf2e4391..fd1980eb 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:01ef616c7a8bd90cd1b7a13efb18a56f33346efbae51efa31f09804478b7621d -size 43456 +oid sha256:6606ee0e9ddf200d7b115f4bece31c3d00626e6eca88de44c836d32074510c65 +size 53268 diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Combat/OverloadModule/OverloadModule.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Combat/OverloadModule/OverloadModule.cpp index acadde39..c89568ee 100644 --- a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Combat/OverloadModule/OverloadModule.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Combat/OverloadModule/OverloadModule.cpp @@ -43,7 +43,6 @@ void AOverloadModule::CheckForPotentialHackTarget() if (HackedEnemies.Contains(OutHit.GetActor()->GetUniqueID())) { - UE_LOG(LogTemp, Warning, TEXT("Enemy has already been hacked!")); PotentialHackTarget = nullptr; DisplayAlreadyHacked(); return; @@ -77,8 +76,7 @@ void AOverloadModule::ExplodeClosestAliveEnemy() { FTransform EmptyTransform; USphereComponent* SphereCollision = Cast(AddComponentByClass(USphereComponent::StaticClass(), false, EmptyTransform, false)); - - SphereCollision->SetHiddenInGame(false); + SphereCollision->SetSphereRadius(AreaOfEffectInMeters * 100, true); TArray OverlappingActors; diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.cpp b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.cpp new file mode 100644 index 00000000..941a7be1 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.cpp @@ -0,0 +1,99 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "RingModule.h" + +#include "Components/SphereComponent.h" +#include "GameFramework/Character.h" + +void ARingModule::BeginPlay() +{ + Super::BeginPlay(); + + this->SetActorTickInterval(0.2); + PlayerChar = GetWorld()->GetFirstPlayerController()->GetCharacter(); + PlayerCam = Cast(PlayerChar->GetComponentByClass(UCameraComponent::StaticClass())); +} + +void ARingModule::Tick(float DeltaSeconds) +{ + Super::Tick(DeltaSeconds); + + if (GadgetCantBeUsed()) return; + CheckForPotentialHackTarget(); +} + +void ARingModule::CheckForPotentialHackTarget() +{ + FHitResult OutHit; + FVector LT_Start = PlayerCam->GetComponentLocation(); + FVector LT_End = PlayerCam->GetComponentLocation() + (PlayerCam->GetForwardVector() * DeadBodyCheckDistance); + + //DrawDebugLine(GetWorld(), LT_Start, LT_End, FColor::Red, false, 0.2, 0, 1); + + FCollisionQueryParams QueryParams = FCollisionQueryParams::DefaultQueryParam; + QueryParams.AddIgnoredActor(PlayerChar); + if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera, QueryParams) || !(OutHit.GetActor()->ActorHasTag(FName("Enemy")) && OutHit.GetActor()->ActorHasTag(FName("Dead")))) + { + PotentialHackTarget = nullptr; + DisplayNeedADeadEnemy(); + return; + } + + if (HackedEnemies.Contains(OutHit.GetActor()->GetUniqueID())) + { + PotentialHackTarget = nullptr; + DisplayAlreadyHacked(); + return; + } + + //DrawDebugLine(GetWorld(), LT_Start, OutHit.ImpactPoint, FColor::Green, false, 0.2, 0, 1); + PotentialHackTarget = OutHit.GetActor(); + DisplayFoundPotentialTarget(); +} + + +void ARingModule::Activate() +{ + if (GadgetCantBeUsed() || !IsValid(PotentialHackTarget)) return; + + Super::Activate(); + HackedEnemies.Add(PotentialHackTarget->GetUniqueID()); + PlayHackingAnim(GadgetMaxUptime); +} + +void ARingModule::FinishedUsing() +{ + SpawnRingingPhoneForAllNearbyEnemies() ? DisplayHackingSuccess() : DisplayHackingFailure(); + Super::FinishedUsing(); + PlayRechargingAnim(CooldownTime); +} + +bool ARingModule::SpawnRingingPhoneForAllNearbyEnemies() +{ + FTransform EmptyTransform; + USphereComponent* SphereCollision = Cast(AddComponentByClass(USphereComponent::StaticClass(), false, EmptyTransform, false)); + SphereCollision->SetSphereRadius(AreaOfEffectInMeters * 100, true); + + TArray OverlappingActors; + TArray EnemiesInRadius; + + SphereCollision->GetOverlappingActors(OverlappingActors, ACharacter::StaticClass()); + for (AActor* OverlappingActor : OverlappingActors) + { + if (OverlappingActor->ActorHasTag(FName("Enemy")) && !OverlappingActor->ActorHasTag(FName("Dead"))) EnemiesInRadius.Add(OverlappingActor); + } + + if (EnemiesInRadius.IsEmpty()) + { + SphereCollision->DestroyComponent(); + return false; + } + + for (AActor* Enemy : EnemiesInRadius) + { + //Dont Forget to spawn in phone ringing + UE_LOG(LogTemp, Warning, TEXT("%s's phone is ringing!!!"), *Enemy->GetName()); + } + return true; +} diff --git a/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.h b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.h new file mode 100644 index 00000000..70b53f1d --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/GadgetSystem/GadgetClasses/Recon/RingModule/RingModule.h @@ -0,0 +1,68 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "EndlessVendetta/GadgetSystem/ReconGadget.h" +#include "Camera/CameraComponent.h" +#include "RingModule.generated.h" + +/** + * + */ +UCLASS() +class ENDLESSVENDETTA_API ARingModule : public AReconGadget +{ + GENERATED_BODY() + + ACharacter* PlayerChar; + + UCameraComponent* PlayerCam; + + AActor* PotentialHackTarget; + + // An Array of previously hacked enemies, stops player from hacking the same Dead Enemy + TArray HackedEnemies; + + virtual void BeginPlay() override; + + virtual void Tick(float DeltaSeconds) override; + + virtual void Activate() override; + + virtual void FinishedUsing() override; + + void CheckForPotentialHackTarget(); + + // Returns false if there are no nearby enemies + bool SpawnRingingPhoneForAllNearbyEnemies(); + +protected: + UPROPERTY(EditDefaultsOnly, Category = "Overload Module") + float AreaOfEffectInMeters = 20; + + UPROPERTY(EditDefaultsOnly, Category = "Overload Module") + float DeadBodyCheckDistance = 250; + + // --------------- Display Functions --------------- + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void DisplayAlreadyHacked(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void DisplayNeedADeadEnemy(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void DisplayFoundPotentialTarget(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void PlayHackingAnim(float Loadingtime); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void DisplayHackingFailure(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void DisplayHackingSuccess(); + + UFUNCTION(BlueprintImplementableEvent, Category = "Overload Module") + void PlayRechargingAnim(float RechargingTime); +};