using Framework.Entities;
using Project.Actors;
using Project.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Project.Player
{
    [Serializable]
    public class PowerMelody : Melody
    {
        public class SongEffectAction : CoreAction 
        {
            public Vector3 position;
            public float freezeTime;

            public SongEffectAction(Vector3 position, float freezeTime)
            {
                this.position = position;
                this.freezeTime = freezeTime;
            }
        }

        public float freezeTime;

        public PowerMelody(AudioClip clip, float range, float freezeTime)
        {
            this.clip = clip;
            this.range = range;
            this.freezeTime = freezeTime;
        }

        public override void Sing(Transform transform)
        {
            //Debug.Log("Sang freeze");
            SongResponder[] actors = GameObject.FindObjectsOfType<SongResponder>();
            actors = actors
                .Where(i => Vector3.Distance(transform.position, i.transform.position) < this.range).ToArray();
            for (int i = 0; i < actors.Length; i++)
            {
                actors[i].Interact(new SongEffectAction(transform.position, this.freezeTime));
            }
            GameObject songNoteObject = (GameObject)GameObject.Instantiate(Resources.Load("SongNote"), transform.position + (Vector3.up * 1f), new Quaternion()); //+ (Vector3.forward * LayerConstants.VisualSoundLayerDepth)
            songNoteObject.transform.parent = transform;
        }
    }
}
