Add Restricted Zone Actor for Restricted Access Areas

This commit is contained in:
Philip W 2024-02-27 18:36:30 +00:00
parent 52229f8975
commit fcbd125dbd
13 changed files with 209 additions and 17 deletions

BIN
EndlessVendetta/Content/AI/BP_RestrictedZone.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,47 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AI_RestrictedZone.h"
#include "EndlessVendetta/EndlessVendettaCharacter.h"
// Sets default values
AAI_RestrictedZone::AAI_RestrictedZone()
{
// 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;
BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
}
// Called when the game starts or when spawned
void AAI_RestrictedZone::BeginPlay()
{
Super::BeginPlay();
BoxCollision->OnComponentBeginOverlap.AddDynamic(this, &AAI_RestrictedZone::OnBoxOverlapBegin);
BoxCollision->OnComponentEndOverlap.AddDynamic(this, &AAI_RestrictedZone::OnBoxOverlapEnd);
}
void AAI_RestrictedZone::OnBoxOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (Cast<AEndlessVendettaCharacter>(OtherActor))
{
UE_LOG(LogTemp, Display, TEXT("Player entered restricted bounds"));
Cast<AEndlessVendettaCharacter>(OtherActor)->IncrementRestrictedBoundsCount();
}
}
void AAI_RestrictedZone::OnBoxOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if (Cast<AEndlessVendettaCharacter>(OtherActor))
{
UE_LOG(LogTemp, Display, TEXT("Player left restricted bounds"));
Cast<AEndlessVendettaCharacter>(OtherActor)->DecrementRestrictedBoundsCount();
}
}
// Called every frame
void AAI_RestrictedZone::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,34 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "GameFramework/Actor.h"
#include "AI_RestrictedZone.generated.h"
UCLASS()
class ENDLESSVENDETTA_API AAI_RestrictedZone : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AAI_RestrictedZone();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY()
UBoxComponent* BoxCollision;
UFUNCTION()
void OnBoxOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnBoxOverlapEnd(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "AI_RestrictedZoneModifier.h"
// Sets default values
AAI_RestrictedZoneModifier::AAI_RestrictedZoneModifier()
{
// 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;
BoxCollision = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
}
// Called when the game starts or when spawned
void AAI_RestrictedZoneModifier::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AAI_RestrictedZoneModifier::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,28 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/BoxComponent.h"
#include "GameFramework/Actor.h"
#include "AI_RestrictedZoneModifier.generated.h"
UCLASS()
class ENDLESSVENDETTA_API AAI_RestrictedZoneModifier : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AAI_RestrictedZoneModifier();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UBoxComponent* BoxCollision;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -22,6 +22,11 @@ void AEnemyCharacter::BeginPlay()
{
Super::BeginPlay();
CharacterName = "Enemy";
if (AEndlessVendettaCharacter* PlayerCharacter = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn()))
{
PlayerCharacter->RestrictedAreaStatusChanged.AddUniqueDynamic(this, &AEnemyCharacter::SetIfPlayerIsInRestrictedArea);
}
}
void AEnemyCharacter::OnDeath()
@ -51,11 +56,12 @@ void AEnemyCharacter::SetAlertLevel(const int NewAlertLevel) const
Cast<AAIController>(GetController())->GetBlackboardComponent()->SetValueAsInt("AlertLevel", NewAlertLevel);
}
void AEnemyCharacter::SetLocalAlertLevel(int NewAlertLevel) const
void AEnemyCharacter::SetLocalAlertLevel(int NewAlertLevel)
{
if (!IsValid(DelegatedControlHub)) return;
if (!IsValid(GetController())) return;
Cast<AAIController>(GetController())->GetBlackboardComponent()->SetValueAsBool("IsInvestigating", true);
if (NewAlertLevel >= 2) SetHostilityLevel(EHostilityLevel::Hostile);
if (!IsValid(DelegatedControlHub)) return;
DelegatedControlHub->SetAlertLevel(NewAlertLevel);
}
@ -99,3 +105,9 @@ void AEnemyCharacter::HuntPlayer(FVector PlayerLastKnownLocation)
EquipWeapon();
Cast<AAIController>(GetController())->GetBlackboardComponent()->SetValueAsVector("LastKnownLocation", PlayerLastKnownLocation);
}
void AEnemyCharacter::SetIfPlayerIsInRestrictedArea(const bool bIsInRestrictedArea)
{
if (!IsValid(GetController())) return;
Cast<AAIController>(GetController())->GetBlackboardComponent()->SetValueAsBool("PlayerIsInRestrictedBounds", bIsInRestrictedArea);
}

View File

@ -41,7 +41,7 @@ public:
virtual void Tick(float DeltaTime) override;
UFUNCTION(BlueprintCallable)
void SubscribeToGroupAIEvents(class AAIControlHub* ControlHub);
void SetLocalAlertLevel(int NewAlertLevel) const;
void SetLocalAlertLevel(int NewAlertLevel);
UFUNCTION(BlueprintCallable)
void SetHostilityLevel(EHostilityLevel NewHostilityLevel);
virtual float TakeDamage(float DamageAmount, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override;
@ -67,4 +67,6 @@ private:
FDelegateHandle HuntPlayerDelegateHandle;
void SetAlertLevel(int NewAlertLevel) const;
void HuntPlayer(FVector PlayerLastKnowLocation);
UFUNCTION()
void SetIfPlayerIsInRestrictedArea(bool bIsInRestrictedArea);
};

View File

@ -14,7 +14,7 @@ EBTNodeResult::Type UBTTask_SetLocalAlertLevel::ExecuteTask(UBehaviorTreeCompone
{
if (const AAI_EnemyController* const AIEnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
{
if (const AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIEnemyController->GetPawn()))
{
EnemyCharacter->SetLocalAlertLevel(AlertLevel);

View File

@ -47,6 +47,26 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter()
Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f));
}
void AEndlessVendettaCharacter::IncrementRestrictedBoundsCount()
{
RestrictedBoundsCount++;
if (RestrictedBoundsCount > 0)
{
bIsInRestrictedArea = true;
RestrictedAreaStatusChanged.Broadcast(true);
}
}
void AEndlessVendettaCharacter::DecrementRestrictedBoundsCount()
{
RestrictedBoundsCount--;
if (RestrictedBoundsCount <= 0)
{
bIsInRestrictedArea = false;
RestrictedAreaStatusChanged.Broadcast(false);
}
}
void AEndlessVendettaCharacter::BeginPlay()
{
// Call the base class
@ -477,7 +497,7 @@ void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
PrimaryWeaponClass = Outhit->GetClass();
if (IsValid(PrimaryWeapon))
{
if(bIsCurrentlyHoldingWeapon)
if (bIsCurrentlyHoldingWeapon)
{
PrimaryWeaponActor = GetWorld()->SpawnActor<AActor>(PrimaryWeaponClass, spawnParams);
UE_LOG(LogTemp, Warning, TEXT("PRIMARY WEAPON SPAWNING IN"));
@ -515,7 +535,7 @@ void AEndlessVendettaCharacter::WeaponSwitcher(AActor* Outhit)
{
if (IsValid(SecondaryWeapon))
{
if(bIsCurrentlyHoldingWeapon)
if (bIsCurrentlyHoldingWeapon)
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Blue, TEXT("bIsCurrentlyHoldingSecondaryCalled, trying to spawn secondary weapon actor"));
SecondaryWeaponActor = GetWorld()->SpawnActor<AActor>(SecondaryWeaponClass, spawnParams);

View File

@ -127,7 +127,17 @@ public:
void StopSecondaryWeaponADS();
UPROPERTY(BlueprintReadWrite)
bool bIsInDialogue = false;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Stats")
bool bIsInRestrictedArea = false;
UFUNCTION(BlueprintCallable)
void IncrementRestrictedBoundsCount();
UFUNCTION(BlueprintCallable)
void DecrementRestrictedBoundsCount();
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FRestrictedAreaStatusChangedSignature, bool, bIsInRestrictedArea);
UPROPERTY(BlueprintAssignable, Category = "Restricted Area")
FRestrictedAreaStatusChangedSignature RestrictedAreaStatusChanged;
protected:
virtual void BeginPlay() override;
@ -146,6 +156,9 @@ protected:
UFUNCTION(BlueprintImplementableEvent)
void PlayFadeScreen();
UPROPERTY()
int RestrictedBoundsCount = 0;
public:
AGadgetManager* GadgetManager;
bool bIsReloading = false;
@ -234,6 +247,7 @@ protected:
void StartedHoldingInteract(float Duration);
UFUNCTION(BlueprintImplementableEvent)
void StoppedHoldingInteract();
protected:
// Used by vault it plugin to run vaulting animations
USkeletalMeshComponent* FP_SkeletalMesh = nullptr;
@ -282,9 +296,11 @@ private:
UPROPERTY(EditDefaultsOnly, Category = "Hover Bike")
TSubclassOf<ASpaceShip> SpaceShipClass;
ASpaceShip* SpaceShip;
protected:
bool PlayerOnShip = false;
void HoldInteract();
public:
void ExitShip(FTransform ExitLoc);
void EnterShip(FTransform TakeoffLoc);