From bc4dedf177277841c2d1df77bb982cd025886978 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 31 Jul 2024 16:04:56 +0100 Subject: [PATCH] Add Lightning Ring --- .../BP_LightningRingWeapon.uasset | 3 + .../vampires/Weapons/LightningRingWeapon.cpp | 56 +++++++++++++++++++ Source/vampires/Weapons/LightningRingWeapon.h | 41 ++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 Content/Weapons/LightningRing/BP_LightningRingWeapon.uasset create mode 100644 Source/vampires/Weapons/LightningRingWeapon.cpp create mode 100644 Source/vampires/Weapons/LightningRingWeapon.h diff --git a/Content/Weapons/LightningRing/BP_LightningRingWeapon.uasset b/Content/Weapons/LightningRing/BP_LightningRingWeapon.uasset new file mode 100644 index 0000000..f18bd2d --- /dev/null +++ b/Content/Weapons/LightningRing/BP_LightningRingWeapon.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff463908ff055be62ac54d48ebcbd4996dec791f19e8d814b64c64e419106b3e +size 23557 diff --git a/Source/vampires/Weapons/LightningRingWeapon.cpp b/Source/vampires/Weapons/LightningRingWeapon.cpp new file mode 100644 index 0000000..22f5662 --- /dev/null +++ b/Source/vampires/Weapons/LightningRingWeapon.cpp @@ -0,0 +1,56 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "LightningRingWeapon.h" + +ALightningRingWeapon::ALightningRingWeapon() +{ + SphereComponent = CreateDefaultSubobject(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(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(OtherActor)) + { + OverlappedEnemies.Add(Enemy); + } +} + +void ALightningRingWeapon::OnEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) +{ + if (AEnemyCharacter* Enemy = Cast(OtherActor)) + { + OverlappedEnemies.Remove(Enemy); + } +} diff --git a/Source/vampires/Weapons/LightningRingWeapon.h b/Source/vampires/Weapons/LightningRingWeapon.h new file mode 100644 index 0000000..6560020 --- /dev/null +++ b/Source/vampires/Weapons/LightningRingWeapon.h @@ -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 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); +};