#pragma once

#include "CoreMinimal.h"
#include "KillerProjectile.h"
#include "DBDTunableRowHandle.h"
#include "TunableStat.h"
#include "Templates/SubclassOf.h"
#include "Engine/HitResult.h"
#include "UObject/NoExportTypes.h"
#include "Chaos/ChaosEngineInterface.h"
#include "K35KillerAreaBlastTravelProjectile.generated.h"

class USphereComponent;
class UKillerProjectileDodgeComponent;
class UStatusEffect;
class UPrimitiveComponent;
class ASurvivor;
class AActor;

UCLASS(Blueprintable)
class AK35KillerAreaBlastTravelProjectile : public AKillerProjectile
{
	GENERATED_BODY()

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced)
	USphereComponent* _environmentCollision;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced)
	USphereComponent* _playerCollision;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Instanced)
	UKillerProjectileDodgeComponent* _killerProjectileDodge;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FDBDTunableRowHandle _projectileTimeoutTime;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FTunableStat _maxAllowedBounces;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FTunableStat _bounciness;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FTunableStat _friction;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FTunableStat _hinderedOnPassThroughLifetime;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	TSubclassOf<UStatusEffect> _hinderedOnPassThroughStatusEffectClass;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	bool _isProjectileActive;

private:
	UFUNCTION()
	void OnSurvivorHitDetected(UPrimitiveComponent* component, const FHitResult& hit);

	UFUNCTION(BlueprintCallable)
	void OnIntroCompleted();

	UFUNCTION(BlueprintCallable, NetMulticast, Reliable)
	void Multicast_OnProjectileReachedEnd(const FVector endLocation);

protected:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, BlueprintCosmetic)
	void Cosmetic_OnProjectileHitSurvivor(ASurvivor* survivor, const float hinderedLifetime);

	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, BlueprintCosmetic)
	void Cosmetic_OnProjectileHitEnvironment(const FVector& impactLocation, const FVector& impactNormal, const TEnumAsByte<EPhysicalSurface>& surfaceType);

	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, BlueprintCosmetic)
	void Cosmetic_OnLaunch();

	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, BlueprintCosmetic)
	void Cosmetic_OnEndReached();

private:
	UFUNCTION(BlueprintCallable)
	void Authority_OnProjectileTimeout();

	UFUNCTION()
	void Authority_OnEnvironmentCollisionComponentOverlapBegin(UPrimitiveComponent* overlappedComponent, AActor* otherActor, UPrimitiveComponent* otherComp, int32 otherBodyIndex, bool isFromSweep, const FHitResult& sweepResult);

	UFUNCTION()
	void Authority_OnEnvironmentCollisionComponentHit(UPrimitiveComponent* hitComponent, AActor* otherActor, UPrimitiveComponent* otherComp, FVector normalImpulse, const FHitResult& hit);

public:
	AK35KillerAreaBlastTravelProjectile();
};

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