// Project Sword & Gun Copyright © 2021 Kevin Poretti


#include "Effects/SNGImpactEffect.h"

#include "Kismet/GameplayStatics.h"
#include "SwordNGun/SNGTypes.h"

void ASNGImpactEffect::PostInitializeComponents()
{
	Super::PostInitializeComponents();

	UParticleSystem* ParticleSystem = GetImpactParticle();
	if(ParticleSystem)
	{
		UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ParticleSystem, GetActorLocation(), GetActorRotation());
	}

	USoundCue* Sound = GetImpactSound();
	if(Sound)
	{
		UGameplayStatics::PlaySoundAtLocation(GetWorld(), Sound, GetActorLocation());
	}
}

/**
 *	Gets the particle effect associated with the surface type
 *
 *	@returns the particle system associated with the surface type
 */
UParticleSystem* ASNGImpactEffect::GetImpactParticle() const
{
	UParticleSystem* Result = nullptr;
	switch (ImpactSurface)
	{
		case SNG_SURFACE_Default:			Result = DefaultParticle; break;
		case SNG_SURFACE_Flesh:				Result = FleshParticle; break;
		case SNG_SURFACE_FleshVulnerable:	Result = FleshVulnerableParticle; break;
		case SNG_SURFACE_Stone:				Result = StoneParticle;	break;
		case SNG_SURFACE_Dirt:				Result = DirtParticle; break;
		case SNG_SURFACE_Water:				Result = WaterParticle; break;
		case SNG_SURFACE_Metal:				Result = MetalParticle; break;
		case SNG_SURFACE_Wood:				Result = WoodParticle; break;
		case SNG_SURFACE_Glass:				Result = GlassParticle; break;
		case SNG_SURFACE_Grass:				Result = GrassParticle; break;
	}
	return Result;
}

/**
 *	Gets the sound effect associated with the surface type
 *
 *	@param SurfaceType the type of the surface impacted
 *	@returns the sound effect associated with the surface type
 */
USoundCue* ASNGImpactEffect::GetImpactSound() const
{
	USoundCue* Result = nullptr;
	switch (ImpactSurface)
	{
		case SNG_SURFACE_Default:			Result = DefaultSound; break;
		case SNG_SURFACE_Flesh:				Result = FleshSound; break;
		case SNG_SURFACE_FleshVulnerable:	Result = FleshVulnerableSound; break;
		case SNG_SURFACE_Stone:				Result = StoneSound; break;
		case SNG_SURFACE_Dirt:				Result = DirtSound; break;
		case SNG_SURFACE_Water:				Result = WaterSound; break;
		case SNG_SURFACE_Metal:				Result = MetalSound; break;
		case SNG_SURFACE_Wood:				Result = WoodSound; break;
		case SNG_SURFACE_Glass:				Result = GlassSound; break;
		case SNG_SURFACE_Grass:				Result = GrassSound; break;
	}
	return Result;
}
