diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp index 828aed18..4057def9 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/AICharacter.cpp @@ -77,11 +77,16 @@ void AAICharacter::SetupStimuliSourceComponent() void AAICharacter::OnDeath() { AAI_EnemyController* AIController = Cast(GetController()); - if (UBlackboardComponent* Blackboard = AIController->GetBlackboardComponent(); Blackboard->GetValueAsBool("SeenWithHostilities")) + UBlackboardComponent* Blackboard = AIController->GetBlackboardComponent(); + AEndlessVendettaCharacter* PlayerCharacter = Cast(GetWorld()->GetFirstPlayerController()->GetPawn()); + if (Blackboard->GetValueAsBool("SeenWithHostilities")) { - AEndlessVendettaCharacter* PlayerCharacter = Cast(GetWorld()->GetFirstPlayerController()->GetPawn()); PlayerCharacter->DecrementSeenHostileCount(); } + if (Blackboard->GetValueAsBool("IsInvestigating")) + { + PlayerCharacter->DecrementBeingInvestigatedCount(); + } this->Tags.Add(FName("Dead")); //Ragdoll diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.cpp b/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.cpp index 077664eb..53468c9f 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.cpp @@ -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() { @@ -29,7 +70,7 @@ void UCombatAudioAutomation::BeginPlay() AllAudioComponents.Add(AudioComponent); StealthTracksAudioComponents.Add(AudioComponent); } - + UAudioComponent* AudioComponent = UGameplayStatics::SpawnSound2D(GetWorld(), InvestigatedTrack); AllAudioComponents.Add(AudioComponent); InvestigatedTrackAudioComponent = AudioComponent; @@ -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(); diff --git a/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.h b/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.h index 3296f05f..937fc18b 100644 --- a/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.h +++ b/EndlessVendetta/Source/EndlessVendetta/AI/CombatAudioAutomation.h @@ -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 AudioTrackQueue; + UFUNCTION() + void PlayQueued(); + public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; @@ -39,9 +69,12 @@ private: UAudioComponent* InvestigatedTrackAudioComponent; UAudioComponent* CombatStartTrackAudioComponent; UAudioComponent* CombatContinuousTrackAudioComponent; - - void StartStealthTrack(); - void StartCombatTrack(); - void StartInvestigatedTrack(); + + bool bInCombat = false; + bool bInRestrictedArea = false; + void StopTracks(); + + UPROPERTY() + FTimerHandle AudioSyncTimer; }; diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 988f771e..5ec1e027 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -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(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->InRestrictedArea(); RestrictedAreaStatusChanged.Broadcast(true); } } @@ -49,6 +51,7 @@ void AEndlessVendettaCharacter::DecrementRestrictedBoundsCount() if (RestrictedBoundsCount <= 0) { bIsInRestrictedArea = false; + Cast(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotInRestrictedArea(); RestrictedAreaStatusChanged.Broadcast(false); } } @@ -63,6 +66,7 @@ void AEndlessVendettaCharacter::IncrementSeenHostileCount() if (!bIsInCombat) { bIsInCombat = true; + Cast(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->InCombat(); } } @@ -86,6 +90,7 @@ void AEndlessVendettaCharacter::IncrementBeingInvestigatedCount() if (!bIsBeingInvestigated) { bIsBeingInvestigated = true; + Cast(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->Investigated(); } } @@ -95,6 +100,7 @@ void AEndlessVendettaCharacter::DecrementBeingInvestigatedCount() if (BeingInvestigatedCount <= 0) { bIsBeingInvestigated = false; + Cast(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->NotBeingInvestigated(); } } @@ -237,6 +243,7 @@ void AEndlessVendettaCharacter::Heal(const float Amount) void AEndlessVendettaCharacter::NotInCombat() { bIsInCombat = false; + Cast(GetComponentByClass(UCombatAudioAutomation::StaticClass()))->OutOfCombat(); } void AEndlessVendettaCharacter::WeaponPickUpSystem()