Update Combat Audio Automation for Timing Engine & Track Queue

This commit is contained in:
Philip W 2024-04-18 22:06:38 +01:00
parent 0b9791086e
commit 10938d7b8d
4 changed files with 145 additions and 23 deletions

View File

@ -77,11 +77,16 @@ void AAICharacter::SetupStimuliSourceComponent()
void AAICharacter::OnDeath()
{
AAI_EnemyController* AIController = Cast<AAI_EnemyController>(GetController());
if (UBlackboardComponent* Blackboard = AIController->GetBlackboardComponent(); Blackboard->GetValueAsBool("SeenWithHostilities"))
UBlackboardComponent* Blackboard = AIController->GetBlackboardComponent();
AEndlessVendettaCharacter* PlayerCharacter = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn());
if (Blackboard->GetValueAsBool("SeenWithHostilities"))
{
AEndlessVendettaCharacter* PlayerCharacter = Cast<AEndlessVendettaCharacter>(GetWorld()->GetFirstPlayerController()->GetPawn());
PlayerCharacter->DecrementSeenHostileCount();
}
if (Blackboard->GetValueAsBool("IsInvestigating"))
{
PlayerCharacter->DecrementBeingInvestigatedCount();
}
this->Tags.Add(FName("Dead"));
//Ragdoll

View File

@ -18,6 +18,47 @@ UCombatAudioAutomation::UCombatAudioAutomation()
}
void UCombatAudioAutomation::InCombat()
{
bInCombat = true;
AudioTrackQueue.Enqueue(EAudioTrack::CombatStart);
AudioTrackQueue.Enqueue(EAudioTrack::CombatContinuous);
}
void UCombatAudioAutomation::OutOfCombat()
{
bInCombat = false;
AudioTrackQueue.Enqueue(EAudioTrack::StopCombat);
}
void UCombatAudioAutomation::Investigated()
{
if (bInCombat) return;
AudioTrackQueue.Enqueue(EAudioTrack::Investigated);
}
void UCombatAudioAutomation::NotBeingInvestigated()
{
if (bInCombat) return;
AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
}
void UCombatAudioAutomation::InRestrictedArea()
{
if (bInCombat) return;
bInRestrictedArea = true;
AudioTrackQueue.Enqueue(EAudioTrack::Stealth1);
AudioTrackQueue.Enqueue(EAudioTrack::Stealth2);
AudioTrackQueue.Enqueue(EAudioTrack::Stealth3);
}
void UCombatAudioAutomation::NotInRestrictedArea()
{
if (bInCombat) return;
bInRestrictedArea = false;
AudioTrackQueue.Enqueue(EAudioTrack::StopStealth);
}
// Called when the game starts
void UCombatAudioAutomation::BeginPlay()
{
@ -41,33 +82,69 @@ void UCombatAudioAutomation::BeginPlay()
AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), CombatContinuousTrack);
AllAudioComponents.Add(AudioComponent);
CombatContinuousTrackAudioComponent = AudioComponent;
GetWorld()->GetTimerManager().SetTimer(AudioSyncTimer, this, &UCombatAudioAutomation::PlayQueued, 5.33333f, true, 1.0f);
}
void UCombatAudioAutomation::PlayQueued()
{
if (AudioTrackQueue.IsEmpty()) return;
EAudioTrack AudioTrack;
AudioTrackQueue.Dequeue(AudioTrack);
switch (AudioTrack)
{
case EAudioTrack::Stealth1:
StealthTracksAudioComponents[0]->Play();
break;
case EAudioTrack::Stealth2:
StealthTracksAudioComponents[1]->Play();
break;
case EAudioTrack::Stealth3:
StealthTracksAudioComponents[2]->Play();
break;
case EAudioTrack::Investigated:
StealthTracksAudioComponents[0]->Stop();
StealthTracksAudioComponents[1]->Stop();
StealthTracksAudioComponents[2]->Stop();
InvestigatedTrackAudioComponent->Play();
break;
case EAudioTrack::CombatStart:
CombatStartTrackAudioComponent->Play();
break;
case EAudioTrack::CombatContinuous:
CombatStartTrackAudioComponent->Stop();
CombatContinuousTrackAudioComponent->Play();
break;
case EAudioTrack::StopStealth:
for (UAudioComponent* AudioComponent : StealthTracksAudioComponents)
{
AudioComponent->Stop();
}
break;
case EAudioTrack::StopInvestigated:
InvestigatedTrackAudioComponent->Stop();
break;
case EAudioTrack::StopCombat:
CombatStartTrackAudioComponent->Stop();
CombatContinuousTrackAudioComponent->Stop();
break;
default:
break;
}
}
// Called every frame
void UCombatAudioAutomation::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UCombatAudioAutomation::StartStealthTrack()
{
// Play the stealth tracks in order after the previous one has finished
}
void UCombatAudioAutomation::StartCombatTrack()
{
}
void UCombatAudioAutomation::StartInvestigatedTrack()
{
}
void UCombatAudioAutomation::StopTracks()
{
AudioTrackQueue.Empty();
for (UAudioComponent* AudioComponent : AllAudioComponents)
{
AudioComponent->Stop();

View File

@ -6,6 +6,19 @@
#include "Components/ActorComponent.h"
#include "CombatAudioAutomation.generated.h"
UENUM(BlueprintType)
enum class EAudioTrack : uint8
{
Stealth1,
Stealth2,
Stealth3,
Investigated,
CombatStart,
CombatContinuous,
StopStealth,
StopInvestigated,
StopCombat,
};
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class ENDLESSVENDETTA_API UCombatAudioAutomation : public UActorComponent
@ -25,10 +38,27 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Audio")
USoundBase* CombatContinuousTrack;
UFUNCTION(BlueprintCallable)
void InCombat();
UFUNCTION(BlueprintCallable)
void OutOfCombat();
UFUNCTION(BlueprintCallable)
void Investigated();
UFUNCTION(BlueprintCallable)
void NotBeingInvestigated();
UFUNCTION(BlueprintCallable)
void InRestrictedArea();
UFUNCTION(BlueprintCallable)
void NotInRestrictedArea();
protected:
// Called when the game starts
virtual void BeginPlay() override;
TQueue<EAudioTrack> AudioTrackQueue;
UFUNCTION()
void PlayQueued();
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
@ -40,8 +70,11 @@ private:
UAudioComponent* CombatStartTrackAudioComponent;
UAudioComponent* CombatContinuousTrackAudioComponent;
void StartStealthTrack();
void StartCombatTrack();
void StartInvestigatedTrack();
bool bInCombat = false;
bool bInRestrictedArea = false;
void StopTracks();
UPROPERTY()
FTimerHandle AudioSyncTimer;
};

View File

@ -15,6 +15,7 @@
#include "Inventory/InventoryComponent.h"
#include "EndlessVendettaGameMode.h"
#include "EVGameInstance.h"
#include "AI/CombatAudioAutomation.h"
#include "DialogueSystem/AC_Dialogue.h"
@ -39,6 +40,7 @@ void AEndlessVendettaCharacter::IncrementRestrictedBoundsCount()
if (RestrictedBoundsCount > 0)
{
bIsInRestrictedArea = true;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->InRestrictedArea();
RestrictedAreaStatusChanged.Broadcast(true);
}
}
@ -49,6 +51,7 @@ void AEndlessVendettaCharacter::DecrementRestrictedBoundsCount()
if (RestrictedBoundsCount <= 0)
{
bIsInRestrictedArea = false;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotInRestrictedArea();
RestrictedAreaStatusChanged.Broadcast(false);
}
}
@ -63,6 +66,7 @@ void AEndlessVendettaCharacter::IncrementSeenHostileCount()
if (!bIsInCombat)
{
bIsInCombat = true;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->InCombat();
}
}
@ -86,6 +90,7 @@ void AEndlessVendettaCharacter::IncrementBeingInvestigatedCount()
if (!bIsBeingInvestigated)
{
bIsBeingInvestigated = true;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->Investigated();
}
}
@ -95,6 +100,7 @@ void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount()
if (BeingInvestigatedCount <= 0)
{
bIsBeingInvestigated = false;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotBeingInvestigated();
}
}
@ -237,6 +243,7 @@ void AEndlessVendettaCharacter::Heal(const float Amount)
void AEndlessVendettaCharacter::NotInCombat()
{
bIsInCombat = false;
Cast<UCombatAudioAutomation>(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->OutOfCombat();
}
void AEndlessVendettaCharacter::WeaponPickUpSystem()