Compare commits

...

4 Commits

Author SHA1 Message Date
baz 14d675d929 Add Magic Wand Weapon to player inventory 2024-07-31 01:58:18 +01:00
baz 0e81f48630 Add Magic Wand Weapon 2024-07-31 01:58:09 +01:00
baz 6ef61f94b5 Move garlic weapon to subfolderr 2024-07-31 01:57:52 +01:00
baz 7102040635 Make FireWeaponAction a BlueprintNativeEvent 2024-07-22 00:51:27 +01:00
13 changed files with 233 additions and 14 deletions

BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Weapons/BP_GarlicWeapon.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Weapons/Garlic/BP_GarlicWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Weapons/MagicWand/BP_MagicWandProjectile.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Weapons/MagicWand/BP_MagicWandWeapon.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Projectile.h"
#include "EnemyCharacter.h"
#include "Weapons/MagicWandWeapon.h"
// Sets default values
AProjectile::AProjectile()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
SphereComponent->SetupAttachment(RootComponent);
SphereComponent->SetSphereRadius(50.0f);
}
// Called when the game starts or when spawned
void AProjectile::BeginPlay()
{
Super::BeginPlay();
AMagicWandWeapon* OwnerWeapon = Cast<AMagicWandWeapon>(GetOwner());
SphereComponent->OnComponentBeginOverlap.AddDynamic(OwnerWeapon, &AMagicWandWeapon::OnProjectileBeginOverlap);
}
// Called every frame
void AProjectile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
SetActorLocation(GetActorLocation() + (TargetDirection * ProjectileSpeed));
}

View File

@ -0,0 +1,35 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/SphereComponent.h"
#include "GameFramework/Actor.h"
#include "Projectile.generated.h"
UCLASS()
class VAMPIRES_API AProjectile : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USphereComponent* SphereComponent = nullptr;
FVector TargetDirection = FVector::ZeroVector;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float ProjectileSpeed = 1.0f;
public:
// Sets default values for this actor's properties
AProjectile();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -16,6 +16,8 @@ AWeapon::AWeapon()
void AWeapon::BeginPlay()
{
Super::BeginPlay();
TArray<AWeapon*> example;
GetWorldTimerManager().SetTimer(WeaponTimerHandle, this, &AWeapon::FireWeaponAction, WeaponCooldown, true);
UEXPComponent* expcomponent = GetOwner()->GetComponentByClass<UEXPComponent>();
@ -25,8 +27,9 @@ void AWeapon::BeginPlay()
}
}
void AWeapon::FireWeaponAction()
void AWeapon::FireWeaponAction_Implementation()
{
// Do stuff
}
void AWeapon::UpgradeWeapon(int newLevel)

View File

@ -12,10 +12,10 @@ class VAMPIRES_API AWeapon : public AActor
GENERATED_BODY()
public:
UPROPERTY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float WeaponCooldown = 1.0f;
UPROPERTY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
float Damage;
private:
@ -30,8 +30,10 @@ protected:
virtual void BeginPlay() override;
public:
UFUNCTION(BlueprintCallable)
virtual void FireWeaponAction();
UFUNCTION(BlueprintNativeEvent)
void FireWeaponAction();
virtual void FireWeaponAction_Implementation();
UFUNCTION()
virtual void UpgradeWeapon(int newLevel);

View File

@ -18,7 +18,7 @@ void AGarlicWeapon::BeginPlay()
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AGarlicWeapon::OnEndOverlap);
}
void AGarlicWeapon::FireWeaponAction()
void AGarlicWeapon::FireWeaponAction_Implementation()
{
TArray<AEnemyCharacter*> OverlappedEnemiesCache = OverlappedEnemies;
@ -54,8 +54,6 @@ void AGarlicWeapon::FireWeaponAction()
i -= 1;
}
}
Super::FireWeaponAction();
}
void AGarlicWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,

View File

@ -27,7 +27,7 @@ protected:
virtual void BeginPlay() override;
public:
virtual void FireWeaponAction() override;
virtual void FireWeaponAction_Implementation() override;
protected:
UFUNCTION()

View File

@ -0,0 +1,91 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MagicWandWeapon.h"
#include "Kismet/GameplayStatics.h"
#include "Kismet/KismetMathLibrary.h"
#include "vampires/EnemyCharacter.h"
AMagicWandWeapon::AMagicWandWeapon()
{
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Component"));
SphereComponent->SetupAttachment(RootComponent);
SphereComponent->SetSphereRadius(1000.0f);
}
void AMagicWandWeapon::BeginPlay()
{
Super::BeginPlay();
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponBeginOverlap);
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AMagicWandWeapon::OnWeaponEndOverlap);
}
void AMagicWandWeapon::FireWeaponAction_Implementation()
{
Super::FireWeaponAction_Implementation();
if (IsValid(ProjectileTemplate))
{
float distance = 0.0f;
AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, distance);
if (nearestActor)
{
FActorSpawnParameters actorSpawnParameters;
actorSpawnParameters.Owner = this;
actorSpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
actorSpawnParameters.TransformScaleMethod = ESpawnActorScaleMethod::MultiplyWithRoot;
AProjectile* projectile = GetWorld()->SpawnActor<AProjectile>(ProjectileTemplate, GetTransform(),
actorSpawnParameters);
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
GetActorLocation(), nearestActor->GetActorLocation());
direction.Z = 0.0;
direction.Normalize();
projectile->TargetDirection = direction;
}
}
}
void AMagicWandWeapon::OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Add(Enemy);
}
}
void AMagicWandWeapon::OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
OverlappedEnemies.Remove(Enemy);
}
}
void AMagicWandWeapon::OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
if (AEnemyCharacter* Enemy = Cast<AEnemyCharacter>(OtherActor))
{
UHealthComponent* EnemyHealthComponent = Enemy->GetHealthComponent();
if (!EnemyHealthComponent->GetIsDead())
{
AController* ownerController = nullptr;
if (AVampireCharacter* character = Cast<AVampireCharacter>(GetOwner()))
{
ownerController = character->GetController();
}
EnemyHealthComponent->TakeDamage(Enemy, Damage, nullptr, ownerController, this);
OverlappedComponent->GetAttachmentRootActor()->Destroy();
}
}
}

View File

@ -0,0 +1,50 @@
// 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/Projectile.h"
#include "MagicWandWeapon.generated.h"
/**
*
*/
UCLASS()
class VAMPIRES_API AMagicWandWeapon : public AWeapon
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USphereComponent* SphereComponent = nullptr;
UPROPERTY(EditAnywhere, Category = "Weapon Properties")
TSubclassOf<AProjectile> ProjectileTemplate = nullptr;
private:
TArray<AActor*> OverlappedEnemies = TArray<AActor*>();
public:
AMagicWandWeapon();
protected:
virtual void BeginPlay() override;
public:
virtual void FireWeaponAction_Implementation() override;
UFUNCTION()
void OnWeaponBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult);
UFUNCTION()
void OnWeaponEndOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex);
UFUNCTION()
void OnProjectileBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
};