Compare commits
4 Commits
26edffa233
...
14d675d929
Author | SHA1 | Date |
---|---|---|
baz | 14d675d929 | |
baz | 0e81f48630 | |
baz | 6ef61f94b5 | |
baz | 7102040635 |
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Weapons/BP_GarlicWeapon.uasset (Stored with Git LFS)
BIN
Content/Weapons/BP_GarlicWeapon.uasset (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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));
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
|
@ -16,6 +16,8 @@ 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>();
|
||||||
|
|
||||||
|
@ -25,8 +27,9 @@ void AWeapon::BeginPlay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWeapon::FireWeaponAction()
|
void AWeapon::FireWeaponAction_Implementation()
|
||||||
{
|
{
|
||||||
|
// Do stuff
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWeapon::UpgradeWeapon(int newLevel)
|
void AWeapon::UpgradeWeapon(int newLevel)
|
||||||
|
|
|
@ -12,10 +12,10 @@ class VAMPIRES_API AWeapon : public AActor
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPROPERTY()
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
|
||||||
float WeaponCooldown = 1.0f;
|
float WeaponCooldown = 1.0f;
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
|
||||||
float Damage;
|
float Damage;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -30,8 +30,10 @@ protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION(BlueprintCallable)
|
|
||||||
virtual void FireWeaponAction();
|
UFUNCTION(BlueprintNativeEvent)
|
||||||
|
void FireWeaponAction();
|
||||||
|
virtual void FireWeaponAction_Implementation();
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
virtual void UpgradeWeapon(int newLevel);
|
virtual void UpgradeWeapon(int newLevel);
|
||||||
|
|
|
@ -18,7 +18,7 @@ void AGarlicWeapon::BeginPlay()
|
||||||
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AGarlicWeapon::OnEndOverlap);
|
SphereComponent->OnComponentEndOverlap.AddDynamic(this, &AGarlicWeapon::OnEndOverlap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGarlicWeapon::FireWeaponAction()
|
void AGarlicWeapon::FireWeaponAction_Implementation()
|
||||||
{
|
{
|
||||||
TArray<AEnemyCharacter*> OverlappedEnemiesCache = OverlappedEnemies;
|
TArray<AEnemyCharacter*> OverlappedEnemiesCache = OverlappedEnemies;
|
||||||
|
|
||||||
|
@ -54,8 +54,6 @@ void AGarlicWeapon::FireWeaponAction()
|
||||||
i -= 1;
|
i -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Super::FireWeaponAction();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AGarlicWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void AGarlicWeapon::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
|
|
@ -27,7 +27,7 @@ protected:
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual void FireWeaponAction() override;
|
virtual void FireWeaponAction_Implementation() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
};
|
Loading…
Reference in New Issue