﻿using UnityEngine;

namespace AC.CombatExample
{

	public abstract class Weapon : MonoBehaviour
	{

		// A base class for any weapon that can be held by the Player


		#region Variables

		[SerializeField] protected int damage = 10;
		[SerializeField] protected AudioClip attackSound = null;
		[SerializeField] protected AudioClip reloadSound = null;
		[SerializeField] protected float range = 20f;
		[SerializeField] protected float reloadTime = 0.3f;

		#endregion


		#region PublicFunctions

		public abstract void OnAttack (Char character);


		public virtual void OnReload (Char character, bool isInScene)
		{
			if (reloadSound)
			{
				if (isInScene)
				{
					AudioSource.PlayClipAtPoint (reloadSound, character.transform.position);
				}
				else
				{
					AudioSource.PlayClipAtPoint (reloadSound, transform.position);
				}
			}
		}

		#endregion


		#region ProtectedFunctions

		protected void ProcessHit (RaycastHit raycastHit)
		{
			// Reacts to hitting a collider upon firing.

			Enemy enemy = raycastHit.collider.GetComponent<Enemy> ();
			if (enemy)
			{
				enemy.TakeDamage (damage);
			}
		}

		#endregion


		#region GetSet

		public float ReloadTime => reloadTime;

		#endregion

	}

}