// Project Sword & Gun Copyright © 2021 Kevin Poretti

#pragma once

#include "CoreMinimal.h"
#include "Weapons/SNGWeaponBase.h"
#include "SNGRangedWeaponBase.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWeaponFiredSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnWeaponReloadedSignature);

/**
 * 
 */
UCLASS()
class SWORDNGUN_API ASNGRangedWeaponBase : public ASNGWeaponBase
{
	GENERATED_BODY()

public:
	ASNGRangedWeaponBase();

	void StartFire();

	void StopFire();

	void Reload();

	bool CanReload();

	bool CanFire();

protected:
	UPROPERTY(BlueprintAssignable, Category="Events")
	FOnWeaponFiredSignature OnFired;

	UPROPERTY(BlueprintAssignable, Category="Events")
	FOnWeaponReloadedSignature OnReloaded;

	UPROPERTY(VisibleDefaultsOnly, Category="Effects")
	FName MuzzleSocketName;

	UPROPERTY(VisibleDefaultsOnly, Category="Effects")
	FName TracerTargetName;

	UPROPERTY(EditDefaultsOnly, Category="Effects")
	UParticleSystem* MuzzleEffect;

	UPROPERTY(EditDefaultsOnly, Category="Effects")
	UParticleSystem* TracerEffect;

	UPROPERTY(EditDefaultsOnly, Category="Sounds")
	USoundBase* FireSound;

	// In rounds per minute
	UPROPERTY(EditDefaultsOnly, Category="Properties")
	float RateOfFire;

	UPROPERTY(EditDefaultsOnly, Category="Properties")
	int32 MaxAmmoCount;

	int32 CurrentAmmoCount;

	FTimerHandle TimerHandle_TimeBetweenShots;

	float LastFireTime;

	float TimeBetweenShots;

	virtual void BeginPlay() override;

	virtual void PlayImpactEffects(EPhysicalSurface SurfaceType, FVector ImpactPoint) override;
	
	virtual void PlayFireEffect(FVector TraceEnd);

	virtual void Fire();
};
