Add Lightning Ring
This commit is contained in:
parent
66a07e621d
commit
bc4dedf177
Binary file not shown.
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
};
|
Loading…
Reference in New Issue