// Project Lab - NHTV Igad

#pragma once

#include "DealDamageProxy.h"
#include "AbilityFilter.h"
#include "AbilityTriggerBase.generated.h"


UCLASS()
class UNREALPROJECT_API AAbilityTriggerBase : public ADealDamageProxy
{
	GENERATED_BODY()
	
public:	
	AAbilityTriggerBase();

	virtual void BeginPlay() override;
	virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
	virtual void Tick( float DeltaSeconds ) override;
	virtual bool CollisionCheck(ANetworkCharacter* otheractor);

	UFUNCTION()
	void OnOverlapBegin(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
	UFUNCTION()
	void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

	virtual void HitEvent(class ANetworkCharacter* otherActor);
	virtual void LeaveEvent(class ANetworkCharacter* otherActor);

	UFUNCTION(BlueprintCallable, Category="Ability")
	float GetLifeTime() const;
	UFUNCTION(BlueprintCallable, Category="Ability")
	float GetLifeTimeRate() const;

	UPROPERTY(BlueprintReadWrite, Replicated, Category = "Ability", meta = (ExposeOnSpawn))
	float duration;
	UPROPERTY(BlueprintReadWrite, Category = "Ability", meta = (ExposeOnSpawn))
	bool hitOnce;

	UPROPERTY(BlueprintReadWrite, meta = (ExposeOnSpawn))
	EAbilityFilter filter;

	UFUNCTION(BlueprintNativeEvent)
	void OnTriggerHit(ANetworkCharacter* actor);
	UFUNCTION(BlueprintNativeEvent)
		void OnTriggerTick(ANetworkCharacter* actor);
	UFUNCTION(BlueprintCallable, NetMulticast, Reliable, Category = "trigger")
		void NativeOnLocalTriggerTick(ANetworkCharacter* actor);

	UFUNCTION(BlueprintNativeEvent)
		void OnLocalTriggerTick(ANetworkCharacter* actor);
	UFUNCTION(BlueprintNativeEvent)
	void OnTriggerLeave(ANetworkCharacter* actor);

	UPROPERTY(BlueprintReadWrite, VisibleAnywhere, Category = "Ability", meta = (ExposeOnSpawn))
	bool autoDestroy;
	UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Ability", meta = (ExposeOnSpawn))
	float ticksPerSecond;
	bool m_CheckActorsHit(class ANetworkCharacter* otherUnit);

	

protected:
	TArray<AActor*> m_actorsInside;
	TArray<ANetworkCharacter*> m_actorsHit;
	float m_tickTime;
	float m_lifeTime;
	float m_tickTimer;
	bool delegatesSet = false;
};
