Finalise base implementation of the Lightning Ring weapon

This commit is contained in:
baz 2025-04-15 21:49:05 +01:00
parent f3f4ad0409
commit a05a24dc62
3 changed files with 32 additions and 12 deletions

Binary file not shown.

View File

@ -3,6 +3,8 @@
#include "LightningRingWeapon.h" #include "LightningRingWeapon.h"
#include "Components/SphereComponent.h" #include "Components/SphereComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetSystemLibrary.h"
#include "vampires/EnemyCharacter.h" #include "vampires/EnemyCharacter.h"
#include "vampires/HealthComponent.h" #include "vampires/HealthComponent.h"
@ -27,18 +29,31 @@ void ALightningRingWeapon::FireWeaponAction_Implementation()
{ {
Super::FireWeaponAction_Implementation(); Super::FireWeaponAction_Implementation();
if (OverlappedEnemies.Num() > 0) TArray<AEnemyCharacter*> targetableEnemies = OverlappedEnemies;
{
AEnemyCharacter* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
UHealthComponent* EnemyHealthComponent = target->GetHealthComponent();
AController* ownerController = nullptr; for (int i = 0; i < LightningBolts && targetableEnemies.Num() > 0; i++)
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
{ {
ownerController = character->GetController(); AEnemyCharacter* target = targetableEnemies[FMath::RandRange(0, targetableEnemies.Num() - 1)];
TArray<AActor*> actorsToIgnore = TArray<AActor*>({ GetOwner() });
TArray<FHitResult> hitResults;
UKismetSystemLibrary::SphereTraceMultiByProfile(GetWorld(),
target->GetActorLocation(),
target->GetActorLocation(),
500.0f,
FName(TEXT("Funny")),
false,
actorsToIgnore,
EDrawDebugTrace::ForDuration,
hitResults,
true);
for (FHitResult EnemyHitResult : hitResults)
{
UGameplayStatics::ApplyDamage(EnemyHitResult.GetActor(), Damage, nullptr, this, nullptr);
} }
EnemyHealthComponent->TakeDamage(target, Damage, nullptr, ownerController, this); targetableEnemies.Remove(target);
} }
} }

View File

@ -20,6 +20,11 @@ class VAMPIRES_API ALightningRingWeapon : public AWeapon
TArray<AEnemyCharacter*> OverlappedEnemies; TArray<AEnemyCharacter*> OverlappedEnemies;
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
int LightningBolts = 1;
public: public:
ALightningRingWeapon(); ALightningRingWeapon();