2025-02-05 23:12:03 +00:00
|
|
|
// Louis Hobbs | 2024-2025
|
2024-07-31 01:58:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "MagicWandWeapon.h"
|
|
|
|
|
2025-01-13 20:57:08 +00:00
|
|
|
#include "GameFramework/GameModeBase.h"
|
2024-07-31 01:58:09 +01:00
|
|
|
#include "Kismet/GameplayStatics.h"
|
|
|
|
#include "Kismet/KismetMathLibrary.h"
|
2025-01-13 20:57:08 +00:00
|
|
|
#include "vampires/ObjectPoolManager.h"
|
2024-11-13 23:47:47 +00:00
|
|
|
#include "vampires/Projectile.h"
|
2025-04-16 14:34:34 +01:00
|
|
|
#include "vampires/ProjectileDataAsset.h"
|
2025-01-13 20:57:08 +00:00
|
|
|
#include "vampires/Interfaces/Pools.h"
|
2024-07-31 01:58:09 +01:00
|
|
|
|
|
|
|
AMagicWandWeapon::AMagicWandWeapon()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMagicWandWeapon::BeginPlay()
|
|
|
|
{
|
|
|
|
Super::BeginPlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMagicWandWeapon::FireWeaponAction_Implementation()
|
|
|
|
{
|
|
|
|
Super::FireWeaponAction_Implementation();
|
2025-04-16 14:34:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AMagicWandWeapon::UpgradeWeapon_Implementation()
|
|
|
|
{
|
|
|
|
if (!Super::UpgradeWeapon_Implementation()) return false;
|
2024-07-31 01:58:09 +01:00
|
|
|
|
2025-04-16 14:34:34 +01:00
|
|
|
switch (CurrentLevel)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
ProjectilesPerActivation++;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
WeaponCooldown -= 0.2;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ProjectilesPerActivation++;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
Damage += 10;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
ProjectilesPerActivation++;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
ProjectileTemplate->DamagableEnemies++;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
Damage += 10;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ResetWeaponTimer();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AMagicWandWeapon::FireProjectile()
|
|
|
|
{
|
2025-01-13 20:57:08 +00:00
|
|
|
if (ProjectileTemplate && OverlappedEnemies.Num() > 0)
|
2024-07-31 01:58:09 +01:00
|
|
|
{
|
|
|
|
float distance = 0.0f;
|
|
|
|
AActor* nearestActor = UGameplayStatics::FindNearestActor(GetActorLocation(), OverlappedEnemies, distance);
|
|
|
|
|
|
|
|
if (nearestActor)
|
|
|
|
{
|
2025-01-13 20:57:08 +00:00
|
|
|
AGameModeBase* gamemode = UGameplayStatics::GetGameMode(GetWorld());
|
|
|
|
|
|
|
|
if (UKismetSystemLibrary::DoesImplementInterface(gamemode, UPools::StaticClass()))
|
|
|
|
{
|
|
|
|
if (AObjectPoolManager* objectPoolManager = IPools::Execute_GetProjectileObjectPoolManager(gamemode))
|
|
|
|
{
|
|
|
|
AActor* projectile = objectPoolManager->GetObject();
|
|
|
|
|
|
|
|
if (UKismetSystemLibrary::DoesImplementInterface(projectile, UProjectilable::StaticClass()))
|
|
|
|
{
|
|
|
|
IProjectilable::Execute_LoadDataFromDataAsset(projectile, ProjectileTemplate);
|
|
|
|
projectile->SetOwner(this);
|
|
|
|
|
|
|
|
FVector direction = UKismetMathLibrary::GetDirectionUnitVector(
|
|
|
|
GetActorLocation(), nearestActor->GetActorLocation());
|
|
|
|
direction.Z = 0.0;
|
|
|
|
direction.Normalize();
|
|
|
|
|
|
|
|
IProjectilable::Execute_SetTargetDirection(projectile, direction);
|
|
|
|
}
|
2025-04-16 14:34:34 +01:00
|
|
|
|
|
|
|
Super::FireProjectile();
|
2025-01-13 20:57:08 +00:00
|
|
|
}
|
|
|
|
}
|
2024-07-31 01:58:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|