using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Caper {
    public enum WindDirection {
        NORTH,
        NORTHEAST,
        EAST,
        SOUTHEAST,
        SOUTH,
        SOUTHWEST,
        WEST,
        NORTHWEST
    }

    public class Wind : MonoBehaviour {
        [Tooltip("The area of effect of this wind.")]
        public float areaSize;
        public WindDirection direction;
        [Tooltip("The intensity of the wind.")]
        public float intensity;
        // Use this for initialization

        /// <summary>
        /// Gets the direction.
        /// </summary>
        /// <returns></returns>
        public Vector3 GetDirection() {
            switch (direction) {
                case WindDirection.NORTH:
                    return new Vector3(0f, 0f, 1f);
                case WindDirection.NORTHEAST:
                    return new Vector3(0.7f, 0f, 0.7f);
                case WindDirection.EAST:
                    return new Vector3(1f, 0f, 0f);
                case WindDirection.SOUTHEAST:
                    return new Vector3(0.7f, 0f, -0.7f);
                case WindDirection.SOUTH:
                    return new Vector3(0f, 0f, -1f);
                case WindDirection.SOUTHWEST:
                    return new Vector3(-0.7f, 0f, -0.7f);
                case WindDirection.WEST:
                    return new Vector3(-1f, 0f, 0f);
                default:
                    return new Vector3(-0.7f, 0f, 0.7f);
            }
        }

        /// <summary>
        /// Gets the intensity at position.
        /// </summary>
        /// <param name="worldPosition">The world position.</param>
        /// <returns></returns>
        public float GetIntensityAtPosition(Vector3 worldPosition) {
            Vector3 vec = transform.position - worldPosition;
            return intensity * (1f - Mathf.Clamp01(vec.magnitude / areaSize));
        }
    }
}
