Add MVP campfire audio hooks

This commit is contained in:
2026-05-19 12:08:16 -07:00
parent 47cd7a5479
commit 280fa76af2
5 changed files with 140 additions and 1 deletions
+53
View File
@@ -7,6 +7,7 @@
#include "AgrarianPersistentActorComponent.h"
#include "AgrarianSurvivalComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include "Components/AudioComponent.h"
#include "Components/PointLightComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
@@ -108,6 +109,16 @@ AAgrarianCampfire::AAgrarianCampfire()
SmokeEffect->SetRelativeLocation(FVector(0.0f, 0.0f, 80.0f));
SmokeEffect->SetVisibility(false);
FireLoopAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("FireLoopAudioComponent"));
FireLoopAudioComponent->SetupAttachment(RootComponent);
FireLoopAudioComponent->bAutoActivate = false;
FireLoopAudioComponent->bAllowSpatialization = true;
FireEventAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("FireEventAudioComponent"));
FireEventAudioComponent->SetupAttachment(RootComponent);
FireEventAudioComponent->bAutoActivate = false;
FireEventAudioComponent->bAllowSpatialization = true;
PersistentActorComponent = CreateDefaultSubobject<UAgrarianPersistentActorComponent>(TEXT("PersistentActorComponent"));
PersistentActorComponent->ActorTypeId = TEXT("campfire");
}
@@ -281,6 +292,23 @@ void AAgrarianCampfire::OnRep_FireState()
UpdateVisualState();
}
void AAgrarianCampfire::MulticastPlayFireEventSound_Implementation(bool bIgnited)
{
if (GetNetMode() == NM_DedicatedServer || !FireEventAudioComponent)
{
return;
}
USoundBase* EventSound = bIgnited ? IgniteSound : ExtinguishSound;
if (!EventSound)
{
return;
}
FireEventAudioComponent->SetSound(EventSound);
FireEventAudioComponent->Play();
}
EAgrarianWeatherType AAgrarianCampfire::GetCurrentWeather() const
{
if (const UWorld* World = GetWorld())
@@ -296,11 +324,17 @@ EAgrarianWeatherType AAgrarianCampfire::GetCurrentWeather() const
void AAgrarianCampfire::SetLit(bool bNewLit)
{
const bool bChanged = bLit != bNewLit;
if (bLit != bNewLit)
{
bLit = bNewLit;
}
if (HasAuthority() && bChanged)
{
MulticastPlayFireEventSound(bLit);
}
UpdateVisualState();
}
@@ -323,6 +357,25 @@ void AAgrarianCampfire::UpdateVisualState()
SmokeEffect->DeactivateSystem();
}
}
if (FireLoopAudioComponent)
{
if (bLit && FireLoopSound)
{
if (FireLoopAudioComponent->Sound != FireLoopSound)
{
FireLoopAudioComponent->SetSound(FireLoopSound);
}
if (!FireLoopAudioComponent->IsPlaying())
{
FireLoopAudioComponent->Play();
}
}
else if (FireLoopAudioComponent->IsPlaying())
{
FireLoopAudioComponent->Stop();
}
}
}
void AAgrarianCampfire::WarmNearbyCharacters(float DeltaSeconds)