Connect campfires to weather
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "AgrarianCampfire.h"
|
||||
#include "AgrarianGameCharacter.h"
|
||||
#include "AgrarianGameState.h"
|
||||
#include "AgrarianInventoryComponent.h"
|
||||
#include "AgrarianPersistentActorComponent.h"
|
||||
#include "AgrarianSurvivalComponent.h"
|
||||
@@ -41,10 +42,10 @@ void AAgrarianCampfire::Tick(float DeltaSeconds)
|
||||
|
||||
if (HasAuthority() && bLit)
|
||||
{
|
||||
FuelSeconds = FMath::Max(0.0f, FuelSeconds - DeltaSeconds);
|
||||
if (FuelSeconds <= 0.0f)
|
||||
FuelSeconds = FMath::Max(0.0f, FuelSeconds - (DeltaSeconds * GetWeatherFuelDrainMultiplier()));
|
||||
if (FuelSeconds <= 0.0f || (bWetWeatherCanExtinguish && IsWetWeatherActive() && FuelSeconds <= WetWeatherExtinguishFuelThresholdSeconds))
|
||||
{
|
||||
SetLit(false);
|
||||
Extinguish();
|
||||
}
|
||||
|
||||
if (CanCook())
|
||||
@@ -180,11 +181,43 @@ float AAgrarianCampfire::GetCookingProgressRatio() const
|
||||
return FMath::Clamp(CookingProgressSeconds / CookingSecondsRequired, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
float AAgrarianCampfire::GetWeatherFuelDrainMultiplier() const
|
||||
{
|
||||
switch (GetCurrentWeather())
|
||||
{
|
||||
case EAgrarianWeatherType::Rain:
|
||||
return FMath::Max(1.0f, RainFuelDrainMultiplier);
|
||||
case EAgrarianWeatherType::Storm:
|
||||
return FMath::Max(1.0f, StormFuelDrainMultiplier);
|
||||
default:
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
bool AAgrarianCampfire::IsWetWeatherActive() const
|
||||
{
|
||||
const EAgrarianWeatherType CurrentWeather = GetCurrentWeather();
|
||||
return CurrentWeather == EAgrarianWeatherType::Rain || CurrentWeather == EAgrarianWeatherType::Storm;
|
||||
}
|
||||
|
||||
void AAgrarianCampfire::OnRep_FireState()
|
||||
{
|
||||
UpdateVisualState();
|
||||
}
|
||||
|
||||
EAgrarianWeatherType AAgrarianCampfire::GetCurrentWeather() const
|
||||
{
|
||||
if (const UWorld* World = GetWorld())
|
||||
{
|
||||
if (const AAgrarianGameState* GameState = World->GetGameState<AAgrarianGameState>())
|
||||
{
|
||||
return GameState->Weather;
|
||||
}
|
||||
}
|
||||
|
||||
return EAgrarianWeatherType::Clear;
|
||||
}
|
||||
|
||||
void AAgrarianCampfire::SetLit(bool bNewLit)
|
||||
{
|
||||
if (bLit != bNewLit)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "AgrarianInteractable.h"
|
||||
#include "AgrarianPersistentStateProvider.h"
|
||||
#include "AgrarianTypes.h"
|
||||
#include "AgrarianCampfire.generated.h"
|
||||
|
||||
class UPointLightComponent;
|
||||
@@ -57,6 +58,18 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Replicated, Category = "Agrarian|Fire|Cooking", meta = (ClampMin = "0"))
|
||||
float CookingProgressSeconds = 0.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Weather", meta = (ClampMin = "1"))
|
||||
float RainFuelDrainMultiplier = 1.5f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Weather", meta = (ClampMin = "1"))
|
||||
float StormFuelDrainMultiplier = 2.5f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Weather", meta = (ClampMin = "0"))
|
||||
float WetWeatherExtinguishFuelThresholdSeconds = 6.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Agrarian|Fire|Weather")
|
||||
bool bWetWeatherCanExtinguish = true;
|
||||
|
||||
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;
|
||||
@@ -75,10 +88,17 @@ public:
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Agrarian|Fire|Cooking")
|
||||
float GetCookingProgressRatio() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Agrarian|Fire|Weather")
|
||||
float GetWeatherFuelDrainMultiplier() const;
|
||||
|
||||
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Agrarian|Fire|Weather")
|
||||
bool IsWetWeatherActive() const;
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void OnRep_FireState();
|
||||
|
||||
EAgrarianWeatherType GetCurrentWeather() const;
|
||||
void SetLit(bool bNewLit);
|
||||
void UpdateVisualState();
|
||||
void WarmNearbyCharacters(float DeltaSeconds);
|
||||
|
||||
Reference in New Issue
Block a user