Compare commits

..

No commits in common. "14d675d9292526acf667c0dac6142803684928f7" and "26edffa233d0315b5e3a27c78ab49ffd7bc022ad" have entirely different histories.

13 changed files with 14 additions and 233 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) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,34 +0,0 @@
// 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

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

View File

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

View File

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

View File

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

View File

@ -1,91 +0,0 @@
// 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

@ -1,50 +0,0 @@
// 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);
};