// Project Sword & Gun Copyright © 2021 Kevin Poretti

#pragma once

#include "CoreMinimal.h"
#include "Effects/SNGImpactEffect.h"
#include "GameFramework/Actor.h"
#include "SNGWeaponBase.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWeaponEquippedSignature);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWeaponUnequippedSignature);

/**
 *	Base class for both melee and ranged weapons.
 *
 *	If you are trying to create a weapon, you will most likely want to inherit from SNGMeleeWeaponBase or
 *	SNGRangedWeaponBase.
 */
UCLASS()
class SWORDNGUN_API ASNGWeaponBase : public AActor
{
	GENERATED_BODY()
	
public:	
	/** Sets default values for this actor's properties. */
	ASNGWeaponBase();

	/**
	 *	Calculates the final damage value to be applied to the receiver when this weapon successfully hits something.
	 *
	 *	By default, this just returns 0. This is meant to be overriden on a per class basis for custom damage calculation.
	 *
	 *	@returns The final damage to be applied to the receiver
	 */
	virtual float CalculateDamage();

	/**
	 *	Equips this weapon.
	 */
	virtual void SetEquipped();

	/**
	 *	Unequips this weapon.
	 */
	virtual void SetUnequipped();

	/**
	 *	Plays impacts when this weapon successfully hits something.
	 *
	 *	@param SurfaceType the type of the surface that was hit by this weapon
	 *	@param ImpactTransform the location and rotation of the impact (rotation is usually the impacted normal direction)
	 */
	virtual void PlayImpactEffects(EPhysicalSurface SurfaceType, FTransform ImpactTransform);
	
protected:
	/** Triggered when the owner equips this weapon. */
	UPROPERTY(BlueprintAssignable, Category="Events")
	FWeaponEquippedSignature OnEquipped;

	/** Triggered when the owner unequips this weapon. */
	UPROPERTY(BlueprintAssignable, Category="Events")
	FWeaponUnequippedSignature OnUnequipped;

	/** Mesh for this weapon. */
	UPROPERTY(EditDefaultsOnly, Category="Mesh")
	USkeletalMeshComponent* WeaponMesh;

	/** Impact effect to be spawned when this weapon successfully hits something. */
	UPROPERTY(EditDefaultsOnly, Category="Effects")
	TSubclassOf<ASNGImpactEffect> ImpactTemplate;

	/**
	 *	Sets visibility of the weapon mesh.
	 */
	virtual void SetVisibility(bool IsVisible);
	
	/** Called when the game starts or when spawned. */
	virtual void BeginPlay() override;

public:	
	/** Called every frame */
	virtual void Tick(float DeltaTime) override;

};
