// Project Lab - NHTV Igad

#pragma once

#include "Spawners/CreatureSpawn.h"
#include "KOTHSpawnerBase.generated.h"

/**
 * 
 */
UCLASS()
class UNREALPROJECT_API AKOTHSpawnerBase : public ACreatureSpawn
{
	GENERATED_BODY()
public:
	AKOTHSpawnerBase(const FObjectInitializer& init);
	void BeginPlay() override;
	void Tick(float DeltaTime) override;

	// Overrided capture camp behaviour 
	virtual void CaptureCamp(int team) override;

	DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnBeginCapture);
	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEndCapture, int32, targetTeam);

	UFUNCTION(BlueprintImplementableEvent, Category = "KOTH Spawner")
	void OnBeginCaptureCamp();
	UFUNCTION(BlueprintImplementableEvent, Category = "KOTH Spawner")
	void OnEndCaptureCamp(int32 targetTeam);
	UPROPERTY(BlueprintAssignable)
	FOnBeginCapture onBeginCapture;
	UPROPERTY(BlueprintAssignable)
	FOnEndCapture onEndCapture;

	UFUNCTION(BlueprintCallable, Category = "KOTH Spawner")
	bool IsContested(int32 targetTeam) const;

	DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnCampCaptured, int32, targetTeam);
	UPROPERTY(BlueprintAssignable, Category = "Game")
	FOnCampCaptured onCampCaptured;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Capture Particle")
	UParticleSystemComponent* captureParticle;

	UPROPERTY(BlueprintReadOnly, Category = "KOTH Spawner Properties")
	bool beingCaptured;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "KOTH Spawner Properties")
	float captureRadius;
	// The duration the camp is captured for
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "KOTH Spawner Properties")
	float captureTime;
	// The time it takes to capture a camp
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "KOTH Spawner Properties")
	float possesionTime;
	class AKOTHBossSpawner* bossSpawner;

protected:	
	// Handle to start the capture process
	void m_OnCampCleared() override;

	// Called when a camp is no longer contested and should be captured by the target team
	UFUNCTION(NetMulticast, Reliable)
	void m_ExeCaptureCamp(int32 targetTeam);

	float m_captureTimer;
	float m_possesionTimer;
	int m_currentTeam;
	bool m_reset;
};
