Implemented NPC Station Functionality
This commit is contained in:
parent
61c564966c
commit
e227edba8d
BIN
EndlessVendetta/Content/Levels/OpenWorldRework.umap
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Levels/OpenWorldRework.umap
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/Levels/TempLevels/NewTutorialMap.umap
(Stored with Git LFS)
BIN
EndlessVendetta/Content/Levels/TempLevels/NewTutorialMap.umap
(Stored with Git LFS)
Binary file not shown.
@ -1,3 +1,3 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:86987c9bdd1a2707a515186793698bc07d938101b1de0b500286cc16629e9359
|
oid sha256:ca12e2004403a8ce0dfec5274e3b0ac13896cd6ad60932db1a1601469ffea0f6
|
||||||
size 22534
|
size 22656
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:9ea4c7725b4114e66152f59eabb0ee14ad9924dfb754bc29c0d81ef8fe676a19
|
||||||
|
size 88907
|
@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:b049e683fe37a8cc646bbb5d5181a5fac5bb1f4be1accf14e2cc42102b32ce58
|
|
||||||
size 33754
|
|
@ -1,3 +0,0 @@
|
|||||||
version https://git-lfs.github.com/spec/v1
|
|
||||||
oid sha256:6181121e680650a713fd6faa5be4bde5b96ed85921fc5bf76c55f7fd7baa8071
|
|
||||||
size 35338
|
|
BIN
EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Materials/M_Concrete_Poured.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Materials/M_Concrete_Poured.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Materials/M_Rock_Sandstone.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Materials/M_Rock_Sandstone.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
EndlessVendetta/Content/StarterContent/Props/SM_GlassWindow.uasset
(Stored with Git LFS)
BIN
EndlessVendetta/Content/StarterContent/Props/SM_GlassWindow.uasset
(Stored with Git LFS)
Binary file not shown.
@ -0,0 +1,6 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "NPC_InfoStruct.h"
|
||||||
|
|
||||||
|
|
22
EndlessVendetta/Source/EndlessVendetta/NPC/NPC_InfoStruct.h
Normal file
22
EndlessVendetta/Source/EndlessVendetta/NPC/NPC_InfoStruct.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "NPC_InfoStruct.generated.h"
|
||||||
|
|
||||||
|
USTRUCT(BlueprintType)
|
||||||
|
struct FNPC_InfoStruct
|
||||||
|
{
|
||||||
|
GENERATED_BODY();
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
FVector NPC_Location;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
TArray<USoundBase*> BarkLines;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
|
||||||
|
UAudioComponent* VoiceComp;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ 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.
|
// 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ANPC_Manager::UpdateNPC_Stations()
|
void ANPC_Manager::UpdateNPC_Stations()
|
||||||
@ -40,11 +40,12 @@ void ANPC_Manager::BeginPlay()
|
|||||||
FRotator DefaultRot = FRotator(0, 0, 0);
|
FRotator DefaultRot = FRotator(0, 0, 0);
|
||||||
for (FVector StationPoint : StationPoints)
|
for (FVector StationPoint : StationPoints)
|
||||||
{
|
{
|
||||||
int RandInt = FMath::RandRange(0, NPC_StationClasses.Num() - 1);// make station points be relative to world
|
int RandInt = FMath::RandRange(0, NPC_StationClasses.Num() - 1);
|
||||||
ANPC_Station* NPC_Station = GetWorld()->SpawnActor<ANPC_Station>(NPC_StationClasses[RandInt], StationPoint, DefaultRot);
|
FVector StationPointWorldLocation = StationPoint + GetActorLocation();
|
||||||
|
ANPC_Station* NPC_Station = GetWorld()->SpawnActor<ANPC_Station>(NPC_StationClasses[RandInt], StationPointWorldLocation, DefaultRot);
|
||||||
if (IsValid(NPC_Station)) NPC_Stations.Add(NPC_Station);
|
if (IsValid(NPC_Station)) NPC_Stations.Add(NPC_Station);
|
||||||
}
|
}
|
||||||
|
SetActorTickInterval(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
|
@ -3,6 +3,44 @@
|
|||||||
|
|
||||||
#include "NPC_Station.h"
|
#include "NPC_Station.h"
|
||||||
|
|
||||||
|
#include "Components/AudioComponent.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
void ANPC_Station::SetupNPCs(TArray<FNPC_InfoStruct> NPC_Info_Array)
|
||||||
|
{
|
||||||
|
NPCs = NPC_Info_Array;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ANPC_Station::Interact()
|
||||||
|
{
|
||||||
|
if (NPCs.IsEmpty() || !IsValid(PlayersPawn)) return;
|
||||||
|
|
||||||
|
// Find closest NPC to the player
|
||||||
|
int ClosestIndex = 0;
|
||||||
|
float Distance = 999999999;
|
||||||
|
for (int i = 0; i < NPCs.Num(); i++)
|
||||||
|
{
|
||||||
|
float CheckDistance = FVector::Distance(PlayersPawn->GetActorLocation(), NPCs[i].NPC_Location);
|
||||||
|
if (CheckDistance <= Distance)
|
||||||
|
{
|
||||||
|
ClosestIndex = i;
|
||||||
|
Distance = CheckDistance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Get a random voice line and play if it's valid
|
||||||
|
if (NPCs[ClosestIndex].BarkLines.IsEmpty() || NPCs[ClosestIndex].VoiceComp == nullptr) return;
|
||||||
|
int RandomVoiceLineIndex = FMath::RandRange(0, NPCs[ClosestIndex].BarkLines.Num() - 1);
|
||||||
|
if (!IsValid(NPCs[ClosestIndex].BarkLines[RandomVoiceLineIndex])) return;
|
||||||
|
NPCs[ClosestIndex].VoiceComp->Sound = NPCs[ClosestIndex].BarkLines[RandomVoiceLineIndex];
|
||||||
|
NPCs[ClosestIndex].VoiceComp->Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ANPC_Station::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
PlayersPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
ANPC_Station::ANPC_Station()
|
ANPC_Station::ANPC_Station()
|
||||||
{
|
{
|
||||||
@ -11,5 +49,21 @@ ANPC_Station::ANPC_Station()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ANPC_Station::EnableStation()
|
||||||
|
{
|
||||||
|
if (bIsEnabled) return;
|
||||||
|
GetRootComponent()->SetVisibility(true, true);
|
||||||
|
GetRootComponent()->SetActive(true);
|
||||||
|
bIsEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ANPC_Station::DisableStation()
|
||||||
|
{
|
||||||
|
if (!bIsEnabled) return;
|
||||||
|
GetRootComponent()->SetVisibility(false, true);
|
||||||
|
GetRootComponent()->SetActive(false);
|
||||||
|
bIsEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,24 +3,39 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "NPC_InfoStruct.h"
|
||||||
|
#include "EndlessVendetta/InteractionInterface.h"
|
||||||
#include "GameFramework/Actor.h"
|
#include "GameFramework/Actor.h"
|
||||||
#include "NPC_Station.generated.h"
|
#include "NPC_Station.generated.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class ENDLESSVENDETTA_API ANPC_Station : public AActor
|
class ENDLESSVENDETTA_API ANPC_Station : public AActor, public IInteractionInterface
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
bool bIsEnabled = false;
|
||||||
|
|
||||||
|
// Contains infor about individual NPC locations and Voices
|
||||||
|
TArray<FNPC_InfoStruct> NPCs;
|
||||||
|
|
||||||
|
AActor* PlayersPawn;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
UFUNCTION(BlueprintCallable)
|
||||||
|
void SetupNPCs(TArray<FNPC_InfoStruct> NPC_Info_Array);
|
||||||
|
|
||||||
|
void Interact() override;
|
||||||
|
|
||||||
|
void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
ANPC_Station();
|
ANPC_Station();
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
|
||||||
void EnableStation();
|
void EnableStation();
|
||||||
|
|
||||||
UFUNCTION(BlueprintImplementableEvent)
|
|
||||||
void DisableStation();
|
void DisableStation();
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user