Add Lightning Ring

This commit is contained in:
baz 2024-07-31 16:04:56 +01:00
parent 66a07e621d
commit bc4dedf177
3 changed files with 100 additions and 0 deletions

BIN
Content/Weapons/LightningRing/BP_LightningRingWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,56 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "LightningRingWeapon.h"
ALightningRingWeapon::ALightningRingWeapon()
{
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
SphereComponent->SetupAttachment(RootComponent);
SphereComponent->SetSphereRadius(1000.0f);
Damage = 51.0f;
}
void ALightningRingWeapon::BeginPlay()
{
Super::BeginPlay();
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &ALightningRingWeapon::OnBeginOverlap);
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &ALightningRingWeapon::OnEndOverlap);
}
void ALightningRingWeapon::FireWeaponAction_Implementation()
{
Super::FireWeaponAction_Implementation();
if (OverlappedEnemies.Num() > 0)
{
AEnemyCharacter* target = OverlappedEnemies[FMath::RandRange(0, OverlappedEnemies.Num() - 1)];
UHealthComponent* EnemyHealthComponent = target->GetHealthComponent();
AController* ownerController = nullptr;
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
{
ownerController = character->GetController();
}
EnemyHealthComponent->TakeDamage(target, Damage, nullptr, ownerController, this);
}
}
void ALightningRingWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Add(Enemy);
}
}
void ALightningRingWeapon::OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Remove(Enemy);
}
}

View File

@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "../Weapon.h"
#include "Components/SphereComponent.h"
#include "vampires/EnemyCharacter.h"
#include "LightningRingWeapon.generated.h"
/**
*
*/
UCLASS()
class VAMPIRES_API ALightningRingWeapon : public AWeapon
{
GENERATED_BODY()
USphereComponent* SphereComponent;
TArray<AEnemyCharacter*> OverlappedEnemies;
public:
ALightningRingWeapon();
protected:
virtual void BeginPlay() override;
public:
virtual void FireWeaponAction_Implementation() override;
protected:
UFUNCTION()
void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult);
UFUNCTION()
void OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
};