Implemented AOverloadModule and its Activation Functions

This commit is contained in:
Rafal Swierczek 2023-10-06 18:27:33 +01:00
parent b93e78108e
commit 0f5c983e75
6 changed files with 195 additions and 6 deletions

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7d61bb4d0a3f7c25b8901699a8047059fb83a255d89990a5b366410f51d23792
size 23259

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d2231f4d2a4b46f8a7daa258e14487b5ee0c0d6ed602fa256de0ef9cdd04f188
size 106160
oid sha256:f27623f7de4cd3ffafc332f52d32f9d58031dad0ba48c3954472553188926618
size 106253

Binary file not shown.

View File

@ -0,0 +1,122 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "OverloadModule.h"
#include "BehaviorTree/BTCompositeNode.h"
#include "Components/SphereComponent.h"
#include "GameFramework/Character.h"
void AOverloadModule::BeginPlay()
{
Super::BeginPlay();
this->SetActorTickInterval(0.2);
PlayerChar = GetWorld()->GetFirstPlayerController()->GetCharacter();
PlayerCam = Cast<UCameraComponent>(PlayerChar->GetComponentByClass(UCameraComponent::StaticClass()));
}
void AOverloadModule::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
CheckForPotentialHackTarget();
}
void AOverloadModule::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);
if (!GetWorld()->LineTraceSingleByChannel(OutHit, LT_Start, LT_End, ECC_Camera) || !(OutHit.GetActor()->ActorHasTag(FName("Enemy")) && OutHit.GetActor()->ActorHasTag(FName("Dead"))))
{
PotentialHackTarget = nullptr;
DisplayNeedADeadEnemy();
return;
}
if (HackedEnemies.Contains(OutHit.GetActor()->GetUniqueID()))
{
PotentialHackTarget = nullptr;
DisplayAlreadyHacked();
}
DrawDebugLine(GetWorld(), LT_Start, OutHit.ImpactPoint, FColor::Green, false, 0.2, 0, 1);
PotentialHackTarget = OutHit.GetActor();
DisplayFoundPotentialTarget();
}
void AOverloadModule::Activate()
{
if (GadgetCantBeUsed() || !IsValid(PotentialHackTarget)) return;
Super::Activate();
HackedEnemies.Add(PotentialHackTarget->GetUniqueID());
ExplodeClosestAliveEnemy();
}
void AOverloadModule::FinishedUsing()
{
Super::FinishedUsing();
}
void AOverloadModule::ExplodeClosestAliveEnemy()
{
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AActor* SphereCollisionActor = GetWorld()->SpawnActor<AActor>(USphereComponent::StaticClass(), PlayerChar->GetActorLocation(), PlayerChar->GetActorRotation(), SpawnParams);
USphereComponent* SphereCollision = Cast<USphereComponent>(SphereCollisionActor);
SphereCollision->SetHiddenInGame(false);
SphereCollision->SetSphereRadius(AreaOfEffectInMeters * 100, true);
TArray<AActor*> OverlappingActors;
TArray<AActor*> EnemiesInRadius;
// Find all living enemies within the radius
SphereCollision->GetOverlappingActors(OverlappingActors, ACharacter::StaticClass());
for (AActor* OverlappingActor : OverlappingActors)
{
if (OverlappingActor->ActorHasTag(FName("Enemy")) && !OverlappingActor->ActorHasTag(FName("Dead"))) EnemiesInRadius.Add(OverlappingActor);
}
if (EnemiesInRadius.IsEmpty())
{
DisplayFailedToFindTarget();
return;
}
// Find the closest Enemy in radius
AActor* ClosestEnemy = EnemiesInRadius[0];
float Dist = FVector::Distance(PlayerChar->GetActorLocation(), ClosestEnemy->GetActorLocation());
UE_LOG(LogTemp, Warning, TEXT("Distacne To first Considered Enemy = %f"), Dist);
if (EnemiesInRadius.Num() < 2)
{
SpawnExplosiveOnActor(ClosestEnemy, SpawnParams);
return;
}
for (int i = 1; i < EnemiesInRadius.Num(); i++)
{
float ConsideredDist = FVector::Distance(PlayerChar->GetActorLocation(), EnemiesInRadius[i]->GetActorLocation());
if (ConsideredDist <= Dist)
{
ClosestEnemy = EnemiesInRadius[i];
Dist = ConsideredDist;
}
}
SpawnExplosiveOnActor(ClosestEnemy, SpawnParams);
}
void AOverloadModule::SpawnExplosiveOnActor(AActor* ActortoExplode, FActorSpawnParameters SpawnParams)
{
GetWorld()->SpawnActor<AActor>(Explosive, ActortoExplode->GetActorLocation(), ActortoExplode->GetActorRotation(), SpawnParams);
}

View File

@ -0,0 +1,64 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "EndlessVendetta/GadgetSystem/CombatGadget.h"
#include "EndlessVendetta/GadgetSystem/GadgetClasses/Combat/Explosive.h"
#include "OverloadModule.generated.h"
/**
*
*/
UCLASS()
class ENDLESSVENDETTA_API AOverloadModule : public ACombatGadget
{
GENERATED_BODY()
ACharacter* PlayerChar;
UCameraComponent* PlayerCam;
AActor* PotentialHackTarget;
// An Array of previously hacked enemies, stops player from hacking the same Dead Enemy
TArray<uint32> HackedEnemies;
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
virtual void Activate() override;
virtual void FinishedUsing() override;
void CheckForPotentialHackTarget();
void ExplodeClosestAliveEnemy();
void SpawnExplosiveOnActor(AActor* ActortoExplode, FActorSpawnParameters SpawnParams);
protected:
UPROPERTY(EditDefaultsOnly, Category = "Overload Module")
float AreaOfEffectInMeters = 15;
UPROPERTY(EditDefaultsOnly, Category = "Overload Module")
float DeadBodyCheckDistance = 300;
UPROPERTY(EditDefaultsOnly, Category = "Overload Module")
TSubclassOf<AExplosive> Explosive;
// --------------- 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 DisplayFailedToFindTarget();
};