#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Triggered.h"
#include "TriggerReset.h"
#include "DBDTunableRowHandle.h"
#include "UObject/NoExportTypes.h"
#include "Engine/HitResult.h"
#include "TriggerableWorldObjectComponent.generated.h"

class UPrimitiveComponent;
class ACharacter;
class AActor;

UCLASS(Blueprintable, meta=(BlueprintSpawnableComponent))
class DEADBYDAYLIGHT_API UTriggerableWorldObjectComponent : public UActorComponent
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintAssignable)
	FTriggered OnTriggered;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintAssignable)
	FTriggerReset OnTriggerReset;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _triggerResetTime;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _randomChance;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _rollFrequency;

private:
	UPROPERTY(EditAnywhere, Export)
	TWeakObjectPtr<UPrimitiveComponent> _conditionalTriggerVolume;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Transient, meta=(AllowPrivateAccess=true))
	TSet<ACharacter*> _conditionalVolumeOverlappingCharacters;

	UPROPERTY(EditAnywhere, Export)
	TWeakObjectPtr<UPrimitiveComponent> _guaranteedTriggerVolume;

public:
	UFUNCTION(BlueprintCallable)
	void SetGuaranteedTriggerVolume(UPrimitiveComponent* volume);

	UFUNCTION(BlueprintCallable)
	void SetConditionalTriggerVolume(UPrimitiveComponent* volume);

protected:
	UFUNCTION(BlueprintCallable, NetMulticast, Reliable)
	void Multicast_OnTriggerReset();

	UFUNCTION(BlueprintCallable, NetMulticast, Reliable)
	void Multicast_OnTriggered(ACharacter* instigator, FVector triggerLocation);

	UFUNCTION()
	void Authority_GuaranteedVolumeOverlap(UPrimitiveComponent* OverlappedComponent, AActor* other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& HitResult);

	UFUNCTION(BlueprintCallable)
	void Authority_ConditionalVolumeEndOverlap(UPrimitiveComponent* OverlappedComponent, AActor* other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

	UFUNCTION()
	void Authority_ConditionalVolumeBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* other, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& HitResult);

public:
	UTriggerableWorldObjectComponent();
};

FORCEINLINE uint32 GetTypeHash(const UTriggerableWorldObjectComponent) { return 0; }
