// Copyright Pacificao. All Rights Reserved. #pragma once #include "CoreMinimal.h" #include "GameFramework/Actor.h" #include "TimerManager.h" #include "AgrarianInteractable.h" #include "AgrarianSaveGame.h" #include "AgrarianTypes.h" #include "AgrarianResourceNode.generated.h" class UStaticMeshComponent; class UAudioComponent; class USoundBase; class UAgrarianItemDefinitionAsset; UCLASS(Blueprintable) class AAgrarianResourceNode : public AActor, public IAgrarianInteractable { GENERATED_BODY() public: AAgrarianResourceNode(); virtual void BeginPlay() override; virtual void GetLifetimeReplicatedProps(TArray& OutLifetimeProps) const override; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource") TObjectPtr Mesh; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource|Visuals") TObjectPtr ResourceClusterProxy; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource|Visuals") TObjectPtr HarvestableMarkerProxy; UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Agrarian|Resource|Audio") TObjectPtr GatheringAudioComponent; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource") FAgrarianItemStack YieldItem; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource") TObjectPtr YieldItemDefinition; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Persistence") FName PersistenceNodeId = NAME_None; UPROPERTY(EditAnywhere, BlueprintReadWrite, ReplicatedUsing = OnRep_RemainingHarvests, Category = "Agrarian|Resource", meta = (ClampMin = "0")) int32 RemainingHarvests = 5; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource", meta = (ClampMin = "1")) int32 QuantityPerHarvest = 1; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Tools") FName RequiredToolItemId; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Tools") bool bAllowBareHandGathering = true; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Tools", meta = (ClampMin = "0")) int32 ToolQuantityBonus = 0; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Respawn") bool bRespawnsForMvp = false; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Respawn", meta = (ClampMin = "1")) float RespawnDelaySeconds = 900.0f; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Respawn", meta = (ClampMin = "1")) int32 MaxHarvests = 5; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Audio") TObjectPtr GatheringSound; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Resource|Audio") TObjectPtr 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; UFUNCTION(BlueprintCallable, Category = "Agrarian|Resource|Persistence") FName GetResourcePersistenceId() const; UFUNCTION(BlueprintCallable, Category = "Agrarian|Resource|Persistence") FAgrarianSavedResourceNode CaptureResourceSaveState() const; UFUNCTION(BlueprintCallable, Category = "Agrarian|Resource|Persistence") void ApplyResourceSaveState(const FAgrarianSavedResourceNode& SavedNode); 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; void UpdateDepletedState(); void ScheduleRespawnIfNeeded(); void RespawnNode(); FTimerHandle RespawnTimerHandle; };