Apply Rider cleanup

This commit is contained in:
Louis Hobbs 2023-06-23 21:06:18 +01:00
parent 9bd298bd6e
commit b5088f3bae
42 changed files with 177 additions and 190 deletions

View File

@ -1,15 +1,14 @@
// Copyright Epic Games, Inc. All Rights Reserved. // Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool; using UnrealBuildTool;
using System.Collections.Generic;
public class NakatomiTarget : TargetRules public class NakatomiTarget : TargetRules
{ {
public NakatomiTarget( TargetInfo Target) : base(Target) public NakatomiTarget(TargetInfo Target) : base(Target)
{ {
Type = TargetType.Game; Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V2; DefaultBuildSettings = BuildSettingsVersion.V2;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
ExtraModuleNames.Add("Nakatomi"); ExtraModuleNames.Add("Nakatomi");
} }
} }

View File

@ -7,31 +7,32 @@
void ADemolitionCharacter::Explode() void ADemolitionCharacter::Explode()
{ {
GetHealthComponent()->TakeDamage(this, this->GetHealthComponent()->GetMaxHealth(), nullptr, nullptr, nullptr); GetHealthComponent()->TakeDamage(this, this->GetHealthComponent()->GetMaxHealth(), nullptr, nullptr, nullptr);
FActorSpawnParameters SpawnParameters; FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
if (ExplosionParticleSystem) if (ExplosionParticleSystem)
{ {
UGameplayStatics::SpawnEmitterAtLocation(this, UGameplayStatics::SpawnEmitterAtLocation(this,
ExplosionParticleSystem, ExplosionParticleSystem,
this->ActorToWorld().GetLocation(), this->ActorToWorld().GetLocation(),
FRotator::ZeroRotator, FRotator::ZeroRotator,
true); true);
} }
TArray<FOverlapResult> outOverlaps; TArray<FOverlapResult> outOverlaps;
GetWorld()->OverlapMultiByObjectType(outOverlaps, GetWorld()->OverlapMultiByObjectType(outOverlaps,
ActorToWorld().GetLocation(), ActorToWorld().GetLocation(),
FQuat::Identity, FQuat::Identity,
FCollisionObjectQueryParams::AllObjects, FCollisionObjectQueryParams::AllObjects,
FCollisionShape::MakeSphere(ExplosionRadius)); FCollisionShape::MakeSphere(ExplosionRadius));
for (FOverlapResult Overlaps : outOverlaps) for (FOverlapResult Overlaps : outOverlaps)
{ {
if (auto healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>()) if (auto healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>())
{ {
float distance = FVector::Distance(ActorToWorld().GetLocation(), Overlaps.GetActor()->ActorToWorld().GetLocation()); float distance = FVector::Distance(ActorToWorld().GetLocation(),
Overlaps.GetActor()->ActorToWorld().GetLocation());
float scale = 1.f - (distance / ExplosionRadius); float scale = 1.f - (distance / ExplosionRadius);
healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this); healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this);
} }

View File

@ -13,7 +13,7 @@ UCLASS()
class NAKATOMI_API ADemolitionCharacter : public AEnemyCharacter class NAKATOMI_API ADemolitionCharacter : public AEnemyCharacter
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
USoundBase* ExplosionSound; USoundBase* ExplosionSound;
@ -31,8 +31,6 @@ protected:
float MaxDamage = 150.f; float MaxDamage = 150.f;
public: public:
UFUNCTION() UFUNCTION()
void Explode(); void Explode();
}; };

View File

@ -10,8 +10,8 @@ UCLASS()
class NAKATOMI_API ADestructable : public AActor class NAKATOMI_API ADestructable : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
class UParticleSystem* ParticleEffect; class UParticleSystem* ParticleEffect;
@ -26,7 +26,5 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
void Destruct(); void Destruct();
}; };

View File

@ -31,7 +31,7 @@ void AEnemyAIController::OnPossess(APawn* InPawn)
enemy->GetCharacterMovement()->MaxWalkSpeed = 500.f; enemy->GetCharacterMovement()->MaxWalkSpeed = 500.f;
enemy->GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged"); enemy->GetHealthComponent()->OnDamaged.BindUFunction(this, "OnDamaged");
enemy->GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath"); enemy->GetHealthComponent()->OnDeath.BindUFunction(this, "OnDeath");
if (auto behaviourTree = enemy->GetBehaviourTree()) if (auto behaviourTree = enemy->GetBehaviourTree())
{ {
Blackboard->InitializeBlackboard(*behaviourTree->BlackboardAsset); Blackboard->InitializeBlackboard(*behaviourTree->BlackboardAsset);
@ -72,8 +72,8 @@ void AEnemyAIController::OnDeath(FDamageInfo info)
enemy->DetachFromControllerPendingDestroy(); enemy->DetachFromControllerPendingDestroy();
enemy->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); enemy->GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision);
enemy->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore); enemy->GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore);
enemy->GetMesh()->SetCollisionProfileName("Ragdoll"); enemy->GetMesh()->SetCollisionProfileName("Ragdoll");
enemy->SetActorEnableCollision(true); enemy->SetActorEnableCollision(true);

View File

@ -21,7 +21,6 @@ class NAKATOMI_API AEnemyAIController : public AAIController
GENERATED_BODY() GENERATED_BODY()
private: private:
UBlackboardComponent* Blackboard; UBlackboardComponent* Blackboard;
UBehaviorTreeComponent* BehaviorTree; UBehaviorTreeComponent* BehaviorTree;

View File

@ -9,7 +9,7 @@
AEnemyCharacter::AEnemyCharacter() AEnemyCharacter::AEnemyCharacter()
{ {
PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component")); PerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Configuration")); SightConfig = CreateDefaultSubobject<UAISenseConfig_Sight>(TEXT("Sight Configuration"));
SightConfig->SightRadius = 700.0f; SightConfig->SightRadius = 700.0f;
SightConfig->LoseSightRadius = 850.0f; SightConfig->LoseSightRadius = 850.0f;
@ -22,7 +22,7 @@ AEnemyCharacter::AEnemyCharacter()
PerceptionComponent->ConfigureSense(*SightConfig); PerceptionComponent->ConfigureSense(*SightConfig);
RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters")); RandomWeaponParameters = CreateDefaultSubobject<URandomWeaponParameters>(TEXT("Random Weapon Parameters"));
GetHealthComponent()->SetMaxHealth(100.0f); GetHealthComponent()->SetMaxHealth(100.0f);
this->Tags.Add(FName("Enemy")); this->Tags.Add(FName("Enemy"));
@ -40,7 +40,7 @@ UAIPerceptionComponent* AEnemyCharacter::GetPerceptionComponent()
void AEnemyCharacter::OnFire() void AEnemyCharacter::OnFire()
{ {
CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Firing); CurrentWeapon->SetCurrentWeaponStatus(Firing);
TArray<FHitResult> Hits = TArray<FHitResult>(); TArray<FHitResult> Hits = TArray<FHitResult>();
CalculateHits(&Hits); CalculateHits(&Hits);
@ -50,7 +50,7 @@ void AEnemyCharacter::OnFire()
// TODO: Play some animation here // TODO: Play some animation here
CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Cooldown); CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
} }
void AEnemyCharacter::BeginPlay() void AEnemyCharacter::BeginPlay()
@ -84,7 +84,8 @@ void AEnemyCharacter::CalculateHits(TArray<FHitResult>* hits)
for (size_t i = 0; i < CurrentWeapon->GetWeaponProperties()->ProjectilesPerShot; i++) for (size_t i = 0; i < CurrentWeapon->GetWeaponProperties()->ProjectilesPerShot; i++)
{ {
// Calculate the maximum distance the weapon can fire // Calculate the maximum distance the weapon can fire
FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, FMath::DegreesToRadians(Spread), FMath::DegreesToRadians(Spread)); FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, FMath::DegreesToRadians(Spread),
FMath::DegreesToRadians(Spread));
FVector MaxHitLoc = TraceStart + (ShootDir * Range); FVector MaxHitLoc = TraceStart + (ShootDir * Range);
GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, MaxHitLoc, COLLISION_WEAPON, TraceParams); GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, MaxHitLoc, COLLISION_WEAPON, TraceParams);
@ -108,7 +109,8 @@ void AEnemyCharacter::ProcessHits(TArray<FHitResult> hits)
// Spawn field actor // Spawn field actor
FTransform transform; FTransform transform;
transform.SetLocation(Hit.ImpactPoint); transform.SetLocation(Hit.ImpactPoint);
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters); auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform,
SpawnParameters);
if (Hit.GetActor()) if (Hit.GetActor())
{ {
@ -119,7 +121,8 @@ void AEnemyCharacter::ProcessHits(TArray<FHitResult> hits)
if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>()) if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>())
{ {
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this); healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr,
GetController(), this);
} }
} }
} }

View File

@ -20,7 +20,6 @@ class NAKATOMI_API AEnemyCharacter : public ANakatomiCharacter
GENERATED_BODY() GENERATED_BODY()
private: private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
UAIPerceptionComponent* PerceptionComponent; UAIPerceptionComponent* PerceptionComponent;
@ -28,7 +27,7 @@ private:
UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditDefaultsOnly, Meta = (AllowPrivateAccess = "true"))
UBehaviorTree* BehaviourTree; UBehaviorTree* BehaviourTree;
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
URandomWeaponParameters* RandomWeaponParameters; URandomWeaponParameters* RandomWeaponParameters;
@ -45,7 +44,6 @@ protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
private: private:
virtual void CalculateHits(TArray<FHitResult>* hits) override; virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override; virtual void ProcessHits(TArray<FHitResult> hits) override;

View File

@ -8,7 +8,7 @@
// Sets default values // Sets default values
AExplosiveActor::AExplosiveActor() AExplosiveActor::AExplosiveActor()
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bCanEverTick = false;
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component")); HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
@ -22,7 +22,6 @@ AExplosiveActor::AExplosiveActor()
void AExplosiveActor::BeginPlay() void AExplosiveActor::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
void AExplosiveActor::Explode() void AExplosiveActor::Explode()
@ -33,25 +32,26 @@ void AExplosiveActor::Explode()
if (ExplosionParticleSystem) if (ExplosionParticleSystem)
{ {
UGameplayStatics::SpawnEmitterAtLocation(this, UGameplayStatics::SpawnEmitterAtLocation(this,
ExplosionParticleSystem, ExplosionParticleSystem,
this->ActorToWorld().GetLocation(), this->ActorToWorld().GetLocation(),
FRotator::ZeroRotator, FRotator::ZeroRotator,
true); true);
} }
TArray<FOverlapResult> outOverlaps; TArray<FOverlapResult> outOverlaps;
GetWorld()->OverlapMultiByObjectType(outOverlaps, GetWorld()->OverlapMultiByObjectType(outOverlaps,
ActorToWorld().GetLocation(), ActorToWorld().GetLocation(),
FQuat::Identity, FQuat::Identity,
FCollisionObjectQueryParams::AllObjects, FCollisionObjectQueryParams::AllObjects,
FCollisionShape::MakeSphere(ExplosionRadius)); FCollisionShape::MakeSphere(ExplosionRadius));
for (FOverlapResult Overlaps : outOverlaps) for (FOverlapResult Overlaps : outOverlaps)
{ {
if (auto healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>()) if (auto healthComponent = Overlaps.GetActor()->GetComponentByClass<UHealthComponent>())
{ {
float distance = FVector::Distance(ActorToWorld().GetLocation(), Overlaps.GetActor()->ActorToWorld().GetLocation()); float distance = FVector::Distance(ActorToWorld().GetLocation(),
Overlaps.GetActor()->ActorToWorld().GetLocation());
float scale = 1.f - (distance / ExplosionRadius); float scale = 1.f - (distance / ExplosionRadius);
healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this); healthComponent->TakeDamage(Overlaps.GetActor(), scale * MaxDamage, nullptr, nullptr, this);
} }
@ -71,4 +71,3 @@ void AExplosiveActor::Explode()
this->Destroy(); this->Destroy();
} }

View File

@ -13,9 +13,8 @@ UCLASS()
class NAKATOMI_API AExplosiveActor : public AActor class NAKATOMI_API AExplosiveActor : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
protected:
protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
UStaticMeshComponent* StaticMeshComponent; UStaticMeshComponent* StaticMeshComponent;
@ -35,12 +34,10 @@ protected:
float MaxDamage = 150.f; float MaxDamage = 150.f;
private: private:
UPROPERTY(VisibleDefaultsOnly) UPROPERTY(VisibleDefaultsOnly)
UHealthComponent* HealthComponent = nullptr; UHealthComponent* HealthComponent = nullptr;
public:
public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AExplosiveActor(); AExplosiveActor();
@ -48,8 +45,7 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
UFUNCTION() UFUNCTION()
void Explode(); void Explode();
}; };

View File

@ -22,11 +22,12 @@ EBTNodeResult::Type UGetDistanceToPlayerTask::ExecuteTask(UBehaviorTreeComponent
auto blackboardComponent = owner.GetBlackboardComponent(); auto blackboardComponent = owner.GetBlackboardComponent();
auto playerCharacter = Cast<ANakatomiCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName)); auto playerCharacter = Cast<ANakatomiCharacter>(blackboardComponent->GetValueAsObject(TargetActor.SelectedKeyName));
auto distance = FVector::Distance(enemyPawn->GetActorLocation(), playerCharacter->GetActorLocation()); auto distance = FVector::Distance(enemyPawn->GetActorLocation(), playerCharacter->GetActorLocation());
if (distance < DistanceThreshold) if (distance < DistanceThreshold)
{ {
enemyPawn->Explode(); enemyPawn->Explode();
enemyPawn->GetHealthComponent()->TakeDamage(enemyPawn, enemyPawn->GetHealthComponent()->GetMaxHealth(), nullptr, nullptr, nullptr); enemyPawn->GetHealthComponent()->TakeDamage(enemyPawn, enemyPawn->GetHealthComponent()->GetMaxHealth(), nullptr,
nullptr, nullptr);
return EBTNodeResult::Succeeded; return EBTNodeResult::Succeeded;
} }

View File

@ -13,8 +13,8 @@ UCLASS()
class NAKATOMI_API UGetDistanceToPlayerTask : public UBTTaskNode class NAKATOMI_API UGetDistanceToPlayerTask : public UBTTaskNode
{ {
GENERATED_BODY() GENERATED_BODY()
private:
private:
UPROPERTY() UPROPERTY()
UBehaviorTreeComponent* behaviourTreeOwner = nullptr; UBehaviorTreeComponent* behaviourTreeOwner = nullptr;
@ -25,12 +25,9 @@ private:
float DistanceThreshold = 5.0f; float DistanceThreshold = 5.0f;
public: public:
UGetDistanceToPlayerTask(); UGetDistanceToPlayerTask();
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override;
virtual EBTNodeResult::Type AbortTask(UBehaviorTreeComponent& owner, uint8* memory) override; virtual EBTNodeResult::Type AbortTask(UBehaviorTreeComponent& owner, uint8* memory) override;
}; };

View File

@ -13,7 +13,8 @@ UHealthComponent::UHealthComponent()
// ... // ...
} }
void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser) void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType,
AController* instigatedBy, AActor* damageCauser)
{ {
if (damagedActor == nullptr || IsDead || !CanDamage) if (damagedActor == nullptr || IsDead || !CanDamage)
{ {
@ -22,12 +23,12 @@ void UHealthComponent::TakeDamage(AActor* damagedActor, float damage, const UDam
CurrentHealth -= damage; CurrentHealth -= damage;
OnDamaged.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser }); OnDamaged.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
if (CurrentHealth <= 0.0f) if (CurrentHealth <= 0.0f)
{ {
IsDead = true; IsDead = true;
OnDeath.ExecuteIfBound({ damagedActor, damage, damageType, instigatedBy, damageCauser }); OnDeath.ExecuteIfBound({damagedActor, damage, damageType, instigatedBy, damageCauser});
} }
} }
@ -104,9 +105,4 @@ void UHealthComponent::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
ResetHealth(); ResetHealth();
} }

View File

@ -16,7 +16,7 @@ struct FDamageInfo
UPROPERTY() UPROPERTY()
float Damage; float Damage;
UPROPERTY() UPROPERTY()
const class UDamageType* DamageType; const class UDamageType* DamageType;
@ -30,18 +30,16 @@ struct FDamageInfo
DECLARE_DELEGATE_OneParam(FOnDamageDelegate, FDamageInfo) DECLARE_DELEGATE_OneParam(FOnDamageDelegate, FDamageInfo)
DECLARE_DELEGATE_OneParam(FOnDeathDelegate, FDamageInfo) DECLARE_DELEGATE_OneParam(FOnDeathDelegate, FDamageInfo)
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class NAKATOMI_API UHealthComponent : public UActorComponent class NAKATOMI_API UHealthComponent : public UActorComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
FOnDamageDelegate OnDamaged; FOnDamageDelegate OnDamaged;
FOnDeathDelegate OnDeath; FOnDeathDelegate OnDeath;
private: private:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float MaxHealth = 100.f; float MaxHealth = 100.f;
@ -53,12 +51,12 @@ private:
bool CanDamage = true; bool CanDamage = true;
public: public:
// Sets default values for this component's properties // Sets default values for this component's properties
UHealthComponent(); UHealthComponent();
UFUNCTION() UFUNCTION()
void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser); void TakeDamage(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy,
AActor* damageCauser);
UFUNCTION() UFUNCTION()
void IncrementHealth(float value); void IncrementHealth(float value);
@ -96,6 +94,4 @@ public:
protected: protected:
// Called when the game starts // Called when the game starts
virtual void BeginPlay() override; virtual void BeginPlay() override;
}; };

View File

@ -24,6 +24,7 @@ void UInteractableComponent::Interact()
{ {
} }
void UInteractableComponent::Interact(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser) void UInteractableComponent::Interact(AActor* damagedActor, float damage, const UDamageType* damageType,
AController* instigatedBy, AActor* damageCauser)
{ {
} }

View File

@ -7,23 +7,22 @@
#include "InteractableComponent.generated.h" #include "InteractableComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class NAKATOMI_API UInteractableComponent : public UActorComponent class NAKATOMI_API UInteractableComponent : public UActorComponent
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
// Sets default values for this component's properties // Sets default values for this component's properties
UInteractableComponent(); UInteractableComponent();
protected: protected:
// Called when the game starts // Called when the game starts
virtual void BeginPlay() override; virtual void BeginPlay() override;
public:
void Interact();
void Interact(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy, AActor* damageCauser);
public:
void Interact();
void Interact(AActor* damagedActor, float damage, const UDamageType* damageType, AController* instigatedBy,
AActor* damageCauser);
}; };

View File

@ -7,17 +7,21 @@ public class Nakatomi : ModuleRules
public Nakatomi(ReadOnlyTargetRules Target) : base(Target) public Nakatomi(ReadOnlyTargetRules Target) : base(Target)
{ {
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine", "GeometryCollectionEngine", "UMG", "AIModule", "GameplayTasks", "NavigationSystem" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PublicDependencyModuleNames.AddRange(new[]
{
"Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine",
"GeometryCollectionEngine", "UMG", "AIModule", "GameplayTasks", "NavigationSystem"
});
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI // Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features // Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem"); // PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
} }
} }

View File

@ -3,4 +3,4 @@
#include "Nakatomi.h" #include "Nakatomi.h"
#include "Modules/ModuleManager.h" #include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, Nakatomi, "Nakatomi" ); IMPLEMENT_PRIMARY_GAME_MODULE(FDefaultGameModuleImpl, Nakatomi, "Nakatomi");

View File

@ -3,4 +3,3 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"

View File

@ -6,7 +6,7 @@
// Sets default values // Sets default values
ANakatomiCharacter::ANakatomiCharacter() ANakatomiCharacter::ANakatomiCharacter()
{ {
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component")); HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
@ -16,7 +16,7 @@ ANakatomiCharacter::ANakatomiCharacter()
void ANakatomiCharacter::BeginPlay() void ANakatomiCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
SetInventoryToDefault(); SetInventoryToDefault();
} }
@ -24,7 +24,6 @@ void ANakatomiCharacter::BeginPlay()
void ANakatomiCharacter::Tick(float DeltaTime) void ANakatomiCharacter::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
} }
// Called to bind functionality to input // Called to bind functionality to input

View File

@ -17,7 +17,6 @@ class NAKATOMI_API ANakatomiCharacter : public ACharacter
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TArray<TSubclassOf<class AWeapon>> DefaultWeaponInventory; TArray<TSubclassOf<class AWeapon>> DefaultWeaponInventory;
@ -28,7 +27,6 @@ public:
AWeapon* CurrentWeapon = nullptr; AWeapon* CurrentWeapon = nullptr;
private: private:
UPROPERTY(VisibleDefaultsOnly) UPROPERTY(VisibleDefaultsOnly)
UHealthComponent* HealthComponent = nullptr; UHealthComponent* HealthComponent = nullptr;
@ -42,7 +40,7 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
@ -82,7 +80,6 @@ public:
virtual void OnFire(); virtual void OnFire();
protected: protected:
virtual void CalculateHits(TArray<FHitResult>* hits); virtual void CalculateHits(TArray<FHitResult>* hits);
virtual void ProcessHits(TArray<FHitResult> hits); virtual void ProcessHits(TArray<FHitResult> hits);

View File

@ -14,17 +14,18 @@ ANakatomiFieldSystemActor::ANakatomiFieldSystemActor()
RadialVector = CreateDefaultSubobject<URadialVector>(TEXT("Radial Vector")); RadialVector = CreateDefaultSubobject<URadialVector>(TEXT("Radial Vector"));
CullingField = CreateDefaultSubobject<UCullingField>(TEXT("Culling Field")); CullingField = CreateDefaultSubobject<UCullingField>(TEXT("Culling Field"));
SphereComponent->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap); SphereComponent->SetCollisionResponseToAllChannels(ECR_Overlap);
} }
void ANakatomiFieldSystemActor::BeginPlay() void ANakatomiFieldSystemActor::BeginPlay()
{ {
Radius = SphereComponent->GetScaledSphereRadius(); Radius = SphereComponent->GetScaledSphereRadius();
Position = GetActorLocation(); Position = GetActorLocation();
RadialFalloff = RadialFalloff->SetRadialFalloff(StrainMagnitude, MinRange, MaxRange, Default, Radius, Position, EFieldFalloffType::Field_FallOff_None); RadialFalloff = RadialFalloff->SetRadialFalloff(StrainMagnitude, MinRange, MaxRange, Default, Radius, Position,
Field_FallOff_None);
GetFieldSystemComponent()->ApplyPhysicsField(true, Field_ExternalClusterStrain, nullptr, RadialFalloff); GetFieldSystemComponent()->ApplyPhysicsField(true, Field_ExternalClusterStrain, nullptr, RadialFalloff);
RadialVector = RadialVector->SetRadialVector(ForceMagnitude, Position); RadialVector = RadialVector->SetRadialVector(ForceMagnitude, Position);
CullingField = CullingField->SetCullingField(RadialFalloff, RadialVector, Field_Culling_Outside); CullingField = CullingField->SetCullingField(RadialFalloff, RadialVector, Field_Culling_Outside);
GetFieldSystemComponent()->ApplyPhysicsField(true, Field_LinearVelocity, nullptr, CullingField); GetFieldSystemComponent()->ApplyPhysicsField(true, Field_LinearVelocity, nullptr, CullingField);
} }

View File

@ -15,10 +15,8 @@ UCLASS()
class NAKATOMI_API ANakatomiFieldSystemActor : public AFieldSystemActor class NAKATOMI_API ANakatomiFieldSystemActor : public AFieldSystemActor
{ {
GENERATED_BODY() GENERATED_BODY()
private: private:
UPROPERTY() UPROPERTY()
USphereComponent* SphereComponent; USphereComponent* SphereComponent;
@ -50,11 +48,9 @@ private:
FVector Position = FVector::ZeroVector; FVector Position = FVector::ZeroVector;
public: public:
ANakatomiFieldSystemActor(); ANakatomiFieldSystemActor();
protected: protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
}; };

View File

@ -2,4 +2,3 @@
#include "NakatomiGameModeBase.h" #include "NakatomiGameModeBase.h"

View File

@ -13,5 +13,4 @@ UCLASS()
class NAKATOMI_API ANakatomiGameModeBase : public AGameModeBase class NAKATOMI_API ANakatomiGameModeBase : public AGameModeBase
{ {
GENERATED_BODY() GENERATED_BODY()
}; };

View File

@ -15,5 +15,4 @@ class NAKATOMI_API ANakatomiPlayerController : public APlayerController
GENERATED_BODY() GENERATED_BODY()
public: public:
}; };

View File

@ -33,13 +33,13 @@ APlayerCharacter::APlayerCharacter()
CameraBoom->TargetArmLength = 350.0f; CameraBoom->TargetArmLength = 350.0f;
CameraBoom->bEnableCameraLag = true; CameraBoom->bEnableCameraLag = true;
CameraBoom->CameraLagSpeed = 10.0f; CameraBoom->CameraLagSpeed = 10.0f;
CameraBoom->SocketOffset = { 0.0f, 75.0f, 110.0f }; CameraBoom->SocketOffset = {0.0f, 75.0f, 110.0f};
// Setup the camera component // Setup the camera component
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent")); CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); CameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
CameraComponent->bUsePawnControlRotation = false; CameraComponent->bUsePawnControlRotation = false;
CameraComponent->SetRelativeRotation({ -5.0f,0.0f,0.0f }); CameraComponent->SetRelativeRotation({-5.0f, 0.0f, 0.0f});
// Setup the character movement // Setup the character movement
UCharacterMovementComponent* CharacterMovementComponent = GetCharacterMovement(); UCharacterMovementComponent* CharacterMovementComponent = GetCharacterMovement();
@ -89,7 +89,8 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
if (APlayerController* PC = Cast<APlayerController>(GetController())) if (APlayerController* PC = Cast<APlayerController>(GetController()))
{ {
if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer())) if (UEnhancedInputLocalPlayerSubsystem* InputSystem = ULocalPlayer::GetSubsystem<
UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
{ {
if (!InputMappingContext.IsNull()) if (!InputMappingContext.IsNull())
{ {
@ -134,7 +135,8 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
if (WeaponSwitchingAction) if (WeaponSwitchingAction)
{ {
Input->BindAction(WeaponSwitchingAction, ETriggerEvent::Triggered, this, &APlayerCharacter::WeaponSwitchingCallback); Input->BindAction(WeaponSwitchingAction, ETriggerEvent::Triggered, this,
&APlayerCharacter::WeaponSwitchingCallback);
} }
} }
} }
@ -168,7 +170,7 @@ void APlayerCharacter::JumpCallback(const FInputActionInstance& Instance)
void APlayerCharacter::BeginFireCallback(const FInputActionInstance& Instance) void APlayerCharacter::BeginFireCallback(const FInputActionInstance& Instance)
{ {
if (CurrentWeapon == nullptr || CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != WeaponState::Idle) if (CurrentWeapon == nullptr || CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != Idle)
{ {
return; return;
} }
@ -184,12 +186,15 @@ void APlayerCharacter::BeginFireCallback(const FInputActionInstance& Instance)
if (CurrentWeapon->GetWeaponProperties()->IsAutomatic) if (CurrentWeapon->GetWeaponProperties()->IsAutomatic)
{ {
GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &APlayerCharacter::WeaponCooldownHandler, CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true); GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &APlayerCharacter::WeaponCooldownHandler,
GetWorldTimerManager().SetTimer(FireTimerHandle, this, &APlayerCharacter::OnFire, CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true); CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
GetWorldTimerManager().SetTimer(FireTimerHandle, this, &APlayerCharacter::OnFire,
CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
} }
else else
{ {
GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &APlayerCharacter::WeaponCooldownHandler, CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true); GetWorldTimerManager().SetTimer(CooldownTimerHandle, this, &APlayerCharacter::WeaponCooldownHandler,
CurrentWeapon->GetWeaponProperties()->WeaponCooldown, true);
} }
} }
@ -243,7 +248,8 @@ void APlayerCharacter::CalculateHits(TArray<FHitResult>* hits)
for (size_t i = 0; i < CurrentWeapon->GetWeaponProperties()->ProjectilesPerShot; i++) for (size_t i = 0; i < CurrentWeapon->GetWeaponProperties()->ProjectilesPerShot; i++)
{ {
// Calculate the maximum distance the weapon can fire // Calculate the maximum distance the weapon can fire
FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, FMath::DegreesToRadians(Spread), FMath::DegreesToRadians(Spread)); FVector ShootDir = WeaponRandomStream.VRandCone(AimDir, FMath::DegreesToRadians(Spread),
FMath::DegreesToRadians(Spread));
FVector MaxHitLoc = TraceStart + (ShootDir * Range); FVector MaxHitLoc = TraceStart + (ShootDir * Range);
GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, MaxHitLoc, COLLISION_WEAPON, TraceParams); GetWorld()->LineTraceMultiByChannel(HitResults, TraceStart, MaxHitLoc, COLLISION_WEAPON, TraceParams);
@ -269,12 +275,13 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
{ {
FTransform transform; FTransform transform;
transform.SetLocation(Hit.ImpactPoint); transform.SetLocation(Hit.ImpactPoint);
auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform, SpawnParameters); auto field = GetWorld()->SpawnActor<AFieldSystemActor>(CurrentWeapon->GetFieldSystemActor(), transform,
SpawnParameters);
if (field) if (field)
{ {
field->Destroy(); field->Destroy();
} }
} }
if (Hit.GetActor()) if (Hit.GetActor())
@ -286,7 +293,8 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>()) if (auto healthComponent = Hit.GetActor()->GetComponentByClass<UHealthComponent>())
{ {
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this); healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr,
GetController(), this);
} }
} }
} }
@ -313,7 +321,7 @@ void APlayerCharacter::OnFire()
return; return;
} }
CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Firing); CurrentWeapon->SetCurrentWeaponStatus(Firing);
TArray<FHitResult> Hits = TArray<FHitResult>(); TArray<FHitResult> Hits = TArray<FHitResult>();
CalculateHits(&Hits); CalculateHits(&Hits);
@ -325,7 +333,7 @@ void APlayerCharacter::OnFire()
// TODO: Play some animation here // TODO: Play some animation here
CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Cooldown); CurrentWeapon->SetCurrentWeaponStatus(Cooldown);
if (CurrentWeapon->GetAmmoCount() == 0) if (CurrentWeapon->GetAmmoCount() == 0)
{ {
@ -335,9 +343,9 @@ void APlayerCharacter::OnFire()
void APlayerCharacter::WeaponCooldownHandler() void APlayerCharacter::WeaponCooldownHandler()
{ {
if (CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != WeaponState::Idle) if (CurrentWeapon->GetCurrentWeaponStatus()->GetValue() != Idle)
{ {
CurrentWeapon->SetCurrentWeaponStatus(WeaponState::Idle); CurrentWeapon->SetCurrentWeaponStatus(Idle);
} }
if (!IsFiring) if (!IsFiring)

View File

@ -28,7 +28,6 @@ class NAKATOMI_API APlayerCharacter : public ANakatomiCharacter
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* MovementAction; UInputAction* MovementAction;
@ -60,12 +59,10 @@ public:
TSubclassOf<class UUserWidget> PlayerHUD; TSubclassOf<class UUserWidget> PlayerHUD;
protected: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float SprintSpeedMultiplier = 2.0f; float SprintSpeedMultiplier = 2.0f;
private: private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true")) UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true"))
USpringArmComponent* CameraBoom = nullptr; USpringArmComponent* CameraBoom = nullptr;
@ -117,7 +114,7 @@ public:
void SetWalkingCallback(const FInputActionInstance& Instance); void SetWalkingCallback(const FInputActionInstance& Instance);
void WeaponSwitchingCallback(const FInputActionInstance& Instance); void WeaponSwitchingCallback(const FInputActionInstance& Instance);
virtual void OnFire() override; virtual void OnFire() override;
void WeaponCooldownHandler(); void WeaponCooldownHandler();
@ -131,7 +128,6 @@ public:
float GetCurrentHealthCount(); float GetCurrentHealthCount();
protected: protected:
virtual void CalculateHits(TArray<FHitResult>* hits) override; virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override; virtual void ProcessHits(TArray<FHitResult> hits) override;

View File

@ -13,8 +13,7 @@ UCLASS()
class NAKATOMI_API UPlayerHealthComponent : public UHealthComponent class NAKATOMI_API UPlayerHealthComponent : public UHealthComponent
{ {
GENERATED_BODY() GENERATED_BODY()
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
}; };

View File

@ -14,6 +14,6 @@ void ARandomWeapon::BeginPlay()
WeaponSkeletalMesh = RandomWeaponParameters->PickRandomMesh(); WeaponSkeletalMesh = RandomWeaponParameters->PickRandomMesh();
FireSound = RandomWeaponParameters->PickRandomSoundBase(); FireSound = RandomWeaponParameters->PickRandomSoundBase();
FieldSystemActor = RandomWeaponParameters->PickRandomFieldSystem(); FieldSystemActor = RandomWeaponParameters->PickRandomFieldSystem();
Super::BeginPlay(); Super::BeginPlay();
} }

View File

@ -14,14 +14,12 @@ UCLASS()
class NAKATOMI_API ARandomWeapon : public AWeapon class NAKATOMI_API ARandomWeapon : public AWeapon
{ {
GENERATED_BODY() GENERATED_BODY()
private:
private:
UPROPERTY(VisibleAnywhere, Category = "Random Weapon Parameters") UPROPERTY(VisibleAnywhere, Category = "Random Weapon Parameters")
URandomWeaponParameters* RandomWeaponParameters; URandomWeaponParameters* RandomWeaponParameters;
public: public:
ARandomWeapon(); ARandomWeapon();
protected: protected:

View File

@ -17,14 +17,14 @@ FWeaponProperties URandomWeaponParameters::GenerateRandomWeaponProperties()
weaponProperties.ProjectilesPerShot = FMath::RandRange(ProjectilePerShotMin, ProjectilePerShotMax); weaponProperties.ProjectilesPerShot = FMath::RandRange(ProjectilePerShotMin, ProjectilePerShotMax);
weaponProperties.ProjectileRange = FMath::FRandRange(ProjectileRangeMin, ProjectileRangeMax); weaponProperties.ProjectileRange = FMath::FRandRange(ProjectileRangeMin, ProjectileRangeMax);
weaponProperties.WeaponSpread = FMath::FRandRange(WeaponSpreadMin, WeaponSpreadMax); weaponProperties.WeaponSpread = FMath::FRandRange(WeaponSpreadMin, WeaponSpreadMax);
if (IsAutomaticOverride) if (IsAutomaticOverride)
{ {
weaponProperties.IsAutomatic = IsAutomaticOverride; weaponProperties.IsAutomatic = IsAutomaticOverride;
} }
else else
{ {
weaponProperties.IsAutomatic = bool(FMath::Rand() % 2); weaponProperties.IsAutomatic = static_cast<bool>(FMath::Rand() % 2);
} }
return weaponProperties; return weaponProperties;

View File

@ -18,54 +18,69 @@ class NAKATOMI_API URandomWeaponParameters : public UActorComponent
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Cooldown", DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "5" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Cooldown", DisplayName = "Min",
meta = ( ClampMin = "0", ClampMax = "5" ))
float CooldownMin = 0.1f; float CooldownMin = 0.1f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Cooldown", DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "5")) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Cooldown", DisplayName = "Max",
meta = ( ClampMin = "0", ClampMax = "5"))
float CooldownMax = 2.0f; float CooldownMax = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Damage", DisplayName = "Min", meta = ( ClampMin = "0" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Damage", DisplayName = "Min",
meta = ( ClampMin = "0" ))
float DamageMin = 10.f; float DamageMin = 10.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Damage", DisplayName = "Max", meta = ( ClampMin = "0")) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Damage", DisplayName = "Max",
meta = ( ClampMin = "0"))
float DamageMax = 10.f; float DamageMax = 10.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Change Time", DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "5" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Change Time", DisplayName = "Min",
meta = ( ClampMin = "0", ClampMax = "5" ))
float ChangeTimeMin = 0.1f; float ChangeTimeMin = 0.1f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Change Time", DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "5" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Change Time", DisplayName = "Max",
meta = ( ClampMin = "0", ClampMax = "5" ))
float ChangeTimeMax = 2.0f; float ChangeTimeMax = 2.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Max Ammo", DisplayName = "Min", meta = ( ClampMin = "0" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Max Ammo", DisplayName = "Min",
meta = ( ClampMin = "0" ))
int MaxAmmoMin = 4; int MaxAmmoMin = 4;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Max Ammo", DisplayName = "Max", meta = ( ClampMin = "0" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Max Ammo", DisplayName = "Max",
meta = ( ClampMin = "0" ))
int MaxAmmoMax = 200; int MaxAmmoMax = 200;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Default Ammo", DisplayName = "Min", meta = ( ClampMin = "0" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Default Ammo", DisplayName = "Min",
meta = ( ClampMin = "0" ))
int DefaultAmmoMin = 4; int DefaultAmmoMin = 4;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Default Ammo", DisplayName = "Max") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Default Ammo", DisplayName = "Max")
int DefaultAmmoMax = 200; int DefaultAmmoMax = 200;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Per Shot", DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "50" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Per Shot",
DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "50" ))
int ProjectilePerShotMin = 1; int ProjectilePerShotMin = 1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Per Shot", DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "50" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Per Shot",
DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "50" ))
int ProjectilePerShotMax = 20; int ProjectilePerShotMax = 20;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Range", DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "1000000" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Range",
DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "1000000" ))
float ProjectileRangeMin = 100.f; float ProjectileRangeMin = 100.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Range", DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "1000000" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Projectile Range",
DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "1000000" ))
float ProjectileRangeMax = 25000.0f; float ProjectileRangeMax = 25000.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Weapon Spread", DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "360" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Weapon Spread",
DisplayName = "Min", meta = ( ClampMin = "0", ClampMax = "360" ))
float WeaponSpreadMin = 0.f; float WeaponSpreadMin = 0.f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Weapon Spread", DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "360" )) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Weapon Spread",
DisplayName = "Max", meta = ( ClampMin = "0", ClampMax = "360" ))
float WeaponSpreadMax = 15.0f; float WeaponSpreadMax = 15.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Is Automatic") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Random Weapon Parameters|Is Automatic")
bool IsAutomaticOverride = false; bool IsAutomaticOverride = false;

View File

@ -15,9 +15,9 @@ class NAKATOMI_API UTaskFireWeapon : public UBTTaskNode
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditAnywhere, Category = "Options", Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key")) UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Target Actor Key"))
FBlackboardKeySelector TargetActor; FBlackboardKeySelector TargetActor;
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override;
}; };

View File

@ -15,7 +15,7 @@ EBTNodeResult::Type UTaskGetRandomLocation::ExecuteTask(UBehaviorTreeComponent&
{ {
FNavLocation navLocation; FNavLocation navLocation;
navigationSystem->GetRandomReachablePointInRadius(enemyPawn->GetActorLocation(), MaximumDistance, navLocation); navigationSystem->GetRandomReachablePointInRadius(enemyPawn->GetActorLocation(), MaximumDistance, navLocation);
blackboardComponent->SetValueAsVector(PatrolLocationKey.SelectedKeyName, navLocation.Location); blackboardComponent->SetValueAsVector(PatrolLocationKey.SelectedKeyName, navLocation.Location);
return EBTNodeResult::Succeeded; return EBTNodeResult::Succeeded;
} }

View File

@ -13,15 +13,16 @@ UCLASS()
class NAKATOMI_API UTaskGetRandomLocation : public UBTTaskNode class NAKATOMI_API UTaskGetRandomLocation : public UBTTaskNode
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Options", Meta = (AllowPrivateAccess = "true", DisplayName = "Patrol Location Key")) public:
UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Patrol Location Key"))
FBlackboardKeySelector PatrolLocationKey; FBlackboardKeySelector PatrolLocationKey;
UPROPERTY(EditAnywhere, Category = "Options", Meta = (AllowPrivateAccess = "true", DisplayName = "Maximum Distance")) UPROPERTY(EditAnywhere, Category = "Options",
Meta = (AllowPrivateAccess = "true", DisplayName = "Maximum Distance"))
float MaximumDistance = 500.0f; float MaximumDistance = 500.0f;
public: public:
virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override; virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& owner, uint8* memory) override;
}; };

View File

@ -7,7 +7,6 @@
// Sets default values // Sets default values
AWeapon::AWeapon() AWeapon::AWeapon()
{ {
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -16,7 +15,6 @@ void AWeapon::BeginPlay()
Super::BeginPlay(); Super::BeginPlay();
SetAmmoCountToDefault(); SetAmmoCountToDefault();
} }
USkeletalMesh* AWeapon::GetSkeletalMesh() USkeletalMesh* AWeapon::GetSkeletalMesh()

View File

@ -24,9 +24,8 @@ UCLASS(Abstract, Blueprintable)
class NAKATOMI_API AWeapon : public AActor class NAKATOMI_API AWeapon : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
protected:
protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
USkeletalMesh* WeaponSkeletalMesh = nullptr; USkeletalMesh* WeaponSkeletalMesh = nullptr;
@ -48,7 +47,7 @@ protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
TSubclassOf<class ANakatomiFieldSystemActor> FieldSystemActor; TSubclassOf<class ANakatomiFieldSystemActor> FieldSystemActor;
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AWeapon(); AWeapon();

View File

@ -6,7 +6,7 @@
// Sets default values // Sets default values
AWeaponPickup::AWeaponPickup() AWeaponPickup::AWeaponPickup()
{ {
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. // 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; PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.SetTickFunctionEnable(true); PrimaryActorTick.SetTickFunctionEnable(true);
PrimaryActorTick.bStartWithTickEnabled = true; PrimaryActorTick.bStartWithTickEnabled = true;
@ -52,17 +52,19 @@ void AWeaponPickup::Tick(float DeltaTime)
WeaponComponent->SetActorLocation(WeaponStartingLocation + ((MovementDirection * Sine) * MovementDistance)); WeaponComponent->SetActorLocation(WeaponStartingLocation + ((MovementDirection * Sine) * MovementDistance));
} }
PointLightComponent->MarkRenderStateDirty(); // We have to do this because Unreal doesn't like it when you create lights in c++ apparently ::pain:: PointLightComponent->MarkRenderStateDirty();
// We have to do this because Unreal doesn't like it when you create lights in c++ apparently ::pain::
float sin = FMath::Abs(FMath::Sin(GetWorld()->GetRealTimeSeconds() * (MovementSpeed / 2))); float sin = FMath::Abs(FMath::Sin(GetWorld()->GetRealTimeSeconds() * (MovementSpeed / 2)));
PointLightComponent->SetLightBrightness(sin * MaxLightBrightness); PointLightComponent->SetLightBrightness(sin * MaxLightBrightness);
} }
void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{ {
// TODO: Add extra checking here // TODO: Add extra checking here
auto player = Cast<APlayerCharacter>(OtherActor); auto player = Cast<APlayerCharacter>(OtherActor);
if (player && Weapon) if (player && Weapon)
{ {
player->AddWeaponToInventory(Weapon); player->AddWeaponToInventory(Weapon);
@ -76,7 +78,7 @@ void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AAc
void AWeaponPickup::SetWeapon(TSubclassOf<class AWeapon> weapon) void AWeaponPickup::SetWeapon(TSubclassOf<class AWeapon> weapon)
{ {
Weapon = weapon; Weapon = weapon;
if (WeaponComponent) if (WeaponComponent)
{ {
WeaponComponent->Destroy(); WeaponComponent->Destroy();
@ -100,7 +102,8 @@ void AWeaponPickup::SpawnWeapon()
FActorSpawnParameters SpawnParameters; FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
WeaponComponent = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters); WeaponComponent = GetWorld()->SpawnActor<AWeapon>(Weapon, SpawnParameters);
FAttachmentTransformRules TransformRules = FAttachmentTransformRules(EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true); FAttachmentTransformRules TransformRules = FAttachmentTransformRules(
EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, EAttachmentRule::SnapToTarget, true);
WeaponComponent->AttachToComponent(RootComponent, TransformRules); WeaponComponent->AttachToComponent(RootComponent, TransformRules);
WeaponComponent->SetActorRelativeLocation(FVector(0.0f, 0.0f, 5.0f)); WeaponComponent->SetActorRelativeLocation(FVector(0.0f, 0.0f, 5.0f));
WeaponComponent->SetActorEnableCollision(false); WeaponComponent->SetActorEnableCollision(false);
@ -108,4 +111,3 @@ void AWeaponPickup::SpawnWeapon()
WeaponStartingLocation = WeaponComponent->GetActorLocation(); WeaponStartingLocation = WeaponComponent->GetActorLocation();
WeaponStartingLocation += ((MovementDirection * MovementDistance) / 2); WeaponStartingLocation += ((MovementDirection * MovementDistance) / 2);
} }

View File

@ -16,7 +16,6 @@ class NAKATOMI_API AWeaponPickup : public AActor
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class AWeapon> Weapon; TSubclassOf<class AWeapon> Weapon;
@ -28,7 +27,7 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float MovementSpeed = 1.0f; float MovementSpeed = 1.0f;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FRotator SpinRotation = FRotator(0.0, 1.0f, 0.0f); FRotator SpinRotation = FRotator(0.0, 1.0f, 0.0f);
@ -42,7 +41,6 @@ public:
FColor LightColor = FColor::White; FColor LightColor = FColor::White;
private: private:
UPROPERTY() UPROPERTY()
USphereComponent* SphereComponent; USphereComponent* SphereComponent;
@ -57,7 +55,7 @@ private:
UPROPERTY() UPROPERTY()
UPointLightComponent* PointLightComponent; UPointLightComponent* PointLightComponent;
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AWeaponPickup(); AWeaponPickup();
@ -65,12 +63,13 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
UFUNCTION() UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
void SetWeapon(TSubclassOf<class AWeapon> weapon); void SetWeapon(TSubclassOf<class AWeapon> weapon);
@ -79,6 +78,5 @@ public:
void SetWeaponProperties(FWeaponProperties FWeaponProperties); void SetWeaponProperties(FWeaponProperties FWeaponProperties);
private: private:
void SpawnWeapon(); void SpawnWeapon();
}; };

View File

@ -40,4 +40,4 @@ struct FWeaponProperties
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties") UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Weapon Properties")
bool IsAutomatic = true; bool IsAutomatic = true;
}; };

View File

@ -1,15 +1,14 @@
// Copyright Epic Games, Inc. All Rights Reserved. // Copyright Epic Games, Inc. All Rights Reserved.
using UnrealBuildTool; using UnrealBuildTool;
using System.Collections.Generic;
public class NakatomiEditorTarget : TargetRules public class NakatomiEditorTarget : TargetRules
{ {
public NakatomiEditorTarget( TargetInfo Target) : base(Target) public NakatomiEditorTarget(TargetInfo Target) : base(Target)
{ {
Type = TargetType.Editor; Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2; DefaultBuildSettings = BuildSettingsVersion.V2;
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1; IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_1;
ExtraModuleNames.Add("Nakatomi"); ExtraModuleNames.Add("Nakatomi");
} }
} }