From efc9a0315e0739b7af505d2a5eed50c7555c7045 Mon Sep 17 00:00:00 2001 From: Rafal Swierczek Date: Sun, 12 May 2024 12:17:06 +0100 Subject: [PATCH] Implemented NPC Manager with NPC Stations --- .../Checkpoints/CP_GrabAssualtRifle.uasset | 4 +- .../Content/NPC/BP_NPC_Manager.uasset | 3 + .../Content/NPC/NPCStation_Test1.uasset | 3 + .../Content/NPC/NPCStation_Test2.uasset | 3 + .../Architecture/Floor_400x400.uasset | 4 +- .../HDRI/HDRI_Epic_Courtyard_Daylight.uasset | 4 +- .../EndlessVendetta/NPC/NPC_Manager.cpp | 56 +++++++++++++++++++ .../Source/EndlessVendetta/NPC/NPC_Manager.h | 45 +++++++++++++++ .../EndlessVendetta/NPC/NPC_Station.cpp | 15 +++++ .../Source/EndlessVendetta/NPC/NPC_Station.h | 27 +++++++++ 10 files changed, 158 insertions(+), 6 deletions(-) create mode 100644 EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset create mode 100644 EndlessVendetta/Content/NPC/NPCStation_Test1.uasset create mode 100644 EndlessVendetta/Content/NPC/NPCStation_Test2.uasset create mode 100644 EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.h create mode 100644 EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.cpp create mode 100644 EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.h diff --git a/EndlessVendetta/Content/BountySystem/Tutorial/Checkpoints/CP_GrabAssualtRifle.uasset b/EndlessVendetta/Content/BountySystem/Tutorial/Checkpoints/CP_GrabAssualtRifle.uasset index 81858680..fb507f76 100644 --- a/EndlessVendetta/Content/BountySystem/Tutorial/Checkpoints/CP_GrabAssualtRifle.uasset +++ b/EndlessVendetta/Content/BountySystem/Tutorial/Checkpoints/CP_GrabAssualtRifle.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7e7173abcb2a402ae23e85a88d981f77974d5d68d0ebb30c07ed8d13f3e6d2cf -size 76202 +oid sha256:9de8616a128b1ba13b311cdcf5bbb90ecce2721eac95dc58d1ada915656fa13d +size 75365 diff --git a/EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset b/EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset new file mode 100644 index 00000000..1b8fdab9 --- /dev/null +++ b/EndlessVendetta/Content/NPC/BP_NPC_Manager.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86987c9bdd1a2707a515186793698bc07d938101b1de0b500286cc16629e9359 +size 22534 diff --git a/EndlessVendetta/Content/NPC/NPCStation_Test1.uasset b/EndlessVendetta/Content/NPC/NPCStation_Test1.uasset new file mode 100644 index 00000000..3e2cc318 --- /dev/null +++ b/EndlessVendetta/Content/NPC/NPCStation_Test1.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b049e683fe37a8cc646bbb5d5181a5fac5bb1f4be1accf14e2cc42102b32ce58 +size 33754 diff --git a/EndlessVendetta/Content/NPC/NPCStation_Test2.uasset b/EndlessVendetta/Content/NPC/NPCStation_Test2.uasset new file mode 100644 index 00000000..84c8b589 --- /dev/null +++ b/EndlessVendetta/Content/NPC/NPCStation_Test2.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6181121e680650a713fd6faa5be4bde5b96ed85921fc5bf76c55f7fd7baa8071 +size 35338 diff --git a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset index e2dbeb1e..c2a34afc 100644 --- a/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset +++ b/EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ba74f78fb3655eaa1f848594e9ab243cfb0c3ae01d87f8d495078e101e72ff16 -size 14831 +oid sha256:4c0ecf0ac0702cc2bd355ec050232a61c49e10f102448efbeb735a51824adef6 +size 14948 diff --git a/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset b/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset index 0f990580..a9df2646 100644 --- a/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset +++ b/EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bc35eb2d43a47427d30aba0196f9eac90d089dd3abca319528c5d25c83510d0d -size 72364642 +oid sha256:8c094c5b655843685164dd0c03980000af4131a8c41cd84e2788b763d8298cd0 +size 66790690 diff --git a/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.cpp b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.cpp new file mode 100644 index 00000000..79f2b0f0 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.cpp @@ -0,0 +1,56 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "NPC_Manager.h" + +#include "Kismet/GameplayStatics.h" + +// Sets default values +ANPC_Manager::ANPC_Manager() +{ + // 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; + +} + +void ANPC_Manager::UpdateNPC_Stations() +{ + for (ANPC_Station* NPC_Station : NPC_Stations) + { + FVector PlayersLoc = PlayersActor->GetActorLocation(); + FVector StationLoc = NPC_Station->GetActorLocation(); + float Distance = FVector::Distance(PlayersLoc, StationLoc); + Distance > NPC_StationRenderDistance ? NPC_Station->DisableStation() : NPC_Station->EnableStation(); + } +} + +// Called when the game starts or when spawned +void ANPC_Manager::BeginPlay() +{ + Super::BeginPlay(); + + PlayersActor = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); + if (!IsValid(PlayersActor)) + { + SetActorTickEnabled(false); + return; + } + + if (NPC_StationClasses.IsEmpty()) return; + FRotator DefaultRot = FRotator(0, 0, 0); + for (FVector StationPoint : StationPoints) + { + int RandInt = FMath::RandRange(0, NPC_StationClasses.Num() - 1);// make station points be relative to world + ANPC_Station* NPC_Station = GetWorld()->SpawnActor(NPC_StationClasses[RandInt], StationPoint, DefaultRot); + if (IsValid(NPC_Station)) NPC_Stations.Add(NPC_Station); + } + +} + +// Called every frame +void ANPC_Manager::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + UpdateNPC_Stations(); +} + diff --git a/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.h b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.h new file mode 100644 index 00000000..aa072e5c --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Manager.h @@ -0,0 +1,45 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "NPC_Station.h" +#include "GameFramework/Actor.h" +#include "NPC_Manager.generated.h" + +UCLASS() +class ENDLESSVENDETTA_API ANPC_Manager : public AActor +{ + GENERATED_BODY() + + AActor* PlayersActor; + + // Used for Selecting Random Stations to Spawn + UPROPERTY(EditDefaultsOnly, Category = "NPC") + TArray> NPC_StationClasses; + + // How far can the station be from the player before it's diabled + UPROPERTY(EditDefaultsOnly, Category = "NPC") + float NPC_StationRenderDistance = 5000; + + // references to All Spawned NPC Stations + TArray NPC_Stations; + + // Dynamically Enables/Disables Stations based on distance to player + void UpdateNPC_Stations(); +protected: + // Spawn points for NPC Stations + UPROPERTY(EditAnywhere, Category = "NPC", meta = (MakeEditWidget = "true")) + TArray StationPoints; + + // Called when the game starts or when spawned + virtual void BeginPlay() override; + +public: + // Sets default values for this actor's properties + ANPC_Manager(); + + // Called every frame + virtual void Tick(float DeltaTime) override; + +}; diff --git a/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.cpp b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.cpp new file mode 100644 index 00000000..25795168 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.cpp @@ -0,0 +1,15 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "NPC_Station.h" + +// Sets default values +ANPC_Station::ANPC_Station() +{ + // 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; + +} + + + diff --git a/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.h b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.h new file mode 100644 index 00000000..68f98d59 --- /dev/null +++ b/EndlessVendetta/Source/EndlessVendetta/NPC/NPC_Station.h @@ -0,0 +1,27 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "NPC_Station.generated.h" + +UCLASS() +class ENDLESSVENDETTA_API ANPC_Station : public AActor +{ + GENERATED_BODY() + +protected: + +public: + // Sets default values for this actor's properties + ANPC_Station(); + + UFUNCTION(BlueprintImplementableEvent) + void EnableStation(); + + UFUNCTION(BlueprintImplementableEvent) + void DisableStation(); + + +};