Add MVP gathering audio hooks

This commit is contained in:
2026-05-19 12:06:14 -07:00
parent bb5ed3883b
commit 47cd7a5479
5 changed files with 100 additions and 1 deletions
@@ -5,6 +5,7 @@
#include "AgrarianInventoryComponent.h"
#include "AgrarianItemDefinitionAsset.h"
#include "AgrarianSaveGame.h"
#include "Components/AudioComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/StaticMesh.h"
#include "Materials/MaterialInterface.h"
@@ -67,6 +68,11 @@ AAgrarianResourceNode::AAgrarianResourceNode()
HarvestableMarkerProxy->SetRelativeLocation(FVector(0.0f, 22.0f, 36.0f));
HarvestableMarkerProxy->SetRelativeScale3D(FVector(0.28f, 0.18f, 0.22f));
GatheringAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("GatheringAudioComponent"));
GatheringAudioComponent->SetupAttachment(RootComponent);
GatheringAudioComponent->bAutoActivate = false;
GatheringAudioComponent->bAllowSpatialization = true;
YieldItem.ItemId = TEXT("wood");
YieldItem.DisplayName = FText::FromString(TEXT("Wood"));
YieldItem.Quantity = 1;
@@ -134,6 +140,7 @@ void AAgrarianResourceNode::Interact_Implementation(AAgrarianGameCharacter* Inte
if (Inventory->AddItem(Granted))
{
RemainingHarvests--;
MulticastPlayGatheringSound(RemainingHarvests <= 0);
UpdateDepletedState();
ScheduleRespawnIfNeeded();
}
@@ -145,6 +152,23 @@ void AAgrarianResourceNode::OnRep_RemainingHarvests()
UpdateDepletedState();
}
void AAgrarianResourceNode::MulticastPlayGatheringSound_Implementation(bool bDepletedAfterGather)
{
if (GetNetMode() == NM_DedicatedServer || !GatheringAudioComponent)
{
return;
}
USoundBase* SoundToPlay = (bDepletedAfterGather && DepletedGatheringSound) ? DepletedGatheringSound : GatheringSound;
if (!SoundToPlay)
{
return;
}
GatheringAudioComponent->SetSound(SoundToPlay);
GatheringAudioComponent->Play();
}
FName AAgrarianResourceNode::GetResourcePersistenceId() const
{
return PersistenceNodeId != NAME_None ? PersistenceNodeId : GetFName();
@@ -11,6 +11,8 @@
#include "AgrarianResourceNode.generated.h"
class UStaticMeshComponent;
class UAudioComponent;
class USoundBase;
class UAgrarianItemDefinitionAsset;
UCLASS(Blueprintable)
@@ -33,6 +35,9 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource|Visuals")
TObjectPtr<UStaticMeshComponent> HarvestableMarkerProxy;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource|Audio")
TObjectPtr<UAudioComponent> GatheringAudioComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource")
FAgrarianItemStack YieldItem;
@@ -66,6 +71,12 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Respawn", meta = (ClampMin = "1"))
int32 MaxHarvests = 5;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Audio")
TObjectPtr<USoundBase> GatheringSound;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Audio")
TObjectPtr<USoundBase> DepletedGatheringSound;
virtual FText GetInteractionText_Implementation(const AAgrarianGameCharacter* Interactor) const override;
virtual bool CanInteract_Implementation(const AAgrarianGameCharacter* Interactor) const override;
virtual void Interact_Implementation(AAgrarianGameCharacter* Interactor) override;
@@ -83,6 +94,9 @@ protected:
UFUNCTION()
void OnRep_RemainingHarvests();
UFUNCTION(NetMulticast, Unreliable)
void MulticastPlayGatheringSound(bool bDepletedAfterGather);
bool HasRequiredTool(const AAgrarianGameCharacter* Interactor) const;
int32 GetHarvestQuantityFor(const AAgrarianGameCharacter* Interactor) const;
FAgrarianItemStack MakeYieldStack(const AAgrarianGameCharacter* Interactor) const;