using Otter;
using System;
using System.Collections.Generic;

namespace SuperRefluxPowergridDefense_
{
    public class SoundManager
    {
        #region Public Static
        public static Dictionary<string, Sound> sounds = new Dictionary<string, Sound>();
        public static bool isSoundEnabled = true;
        #endregion

        #region Private Variables
        private Sound _click = new Sound(Assets.SFX_CLICK);
        private Sound _deathForEverything = new Sound(Assets.SFX_DEATHFOREVERYTHING);
        private Sound _pickup = new Sound(Assets.SFX_PICKUP);
        private Sound _pickupFuel = new Sound(Assets.SFX_PICKUPFUEL);
        private Sound _playerHurt = new Sound(Assets.SFX_PLAYERHURT);
        private Sound _scaryGirlHit = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _realClickyClick = new Sound(Assets.SFX_REALCLICKYCLICK);
        private Sound _teslaBeamReady = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaFireBeam = new Sound(Assets.SFX_TESLAFIREBEAM);
        #region SoundInstances
        private static Sound locatedSound;
        #region TeslaBeamReady
        private Sound _teslaBeamReady1 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady2 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady3 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady4 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady5 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady6 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady7 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady8 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady9 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady10 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady11 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady12 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady13 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady14 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady15 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady16 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady17 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady18 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady19 = new Sound(Assets.SFX_TESLABEAMREADY);
        private Sound _teslaBeamReady20 = new Sound(Assets.SFX_TESLABEAMREADY);
        #endregion
        #region TeslaFireBeam
        private Sound _teslaFireBeam1 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam2 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam3 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam4 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam5 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam6 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam7 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam8 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam9 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam10 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam11 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam12 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam13 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam14 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam15 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam16 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam17 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam18 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam19 = new Sound(Assets.SFX_TESLAFIREBEAM);
        private Sound _teslaFireBeam20 = new Sound(Assets.SFX_TESLAFIREBEAM);
        #endregion
        #region scaryGirlHit
        private Sound _scaryGirlHit1 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit2 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit3 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit4 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit5 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit6 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit7 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit8 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit9 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit10 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit11 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit12 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit13 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit14 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit15 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit16 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit17 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit18 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit19 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit20 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit21 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit22 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit23 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit24 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit25 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit26 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit27 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit28 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit29 = new Sound(Assets.SFX_SCARYGIRLHIT);
        private Sound _scaryGirlHit30 = new Sound(Assets.SFX_SCARYGIRLHIT);
        #endregion
        #endregion
        #endregion

        public SoundManager()
        {
            LoadSounds();
        }
        #region Public Properties
        public bool SoundIsEnabled
        {
            get
            {
                return isSoundEnabled;
            }

            set
            {
                isSoundEnabled = value;
            }
        }
        #endregion

        #region Public Methods and Operators
        public static void PlayRequestedSound(string sound, float volume = 1.0f)
        {
            //get sound.
            //if sound is playing, get the sound again and set it to a new instance,
            //if new sound is playing, get the sound again and set it to a new instance,
            //if new sound is playing, get the sound again and...
            try
            {
                for (var i = 1; i < 20; i++)//max sounds is the biggest number in there
                {
                    sounds.TryGetValue(sound, out locatedSound);
                    if (locatedSound.IsPlaying)
                    {
                        //Console.WriteLine("sound " + i + " is playing.");
                        if (i != 1)
                        {
                            if (i.ToString().Length > 1)
                                sound = sound.TrimEnd(sound[sound.Length - 2]);
                            else
                                sound = sound.TrimEnd(sound[sound.Length - 1]);
                        }
                        sound = sound + i.ToString();
                        //Console.WriteLine("sound?: " + sound);
                        sounds.TryGetValue(sound, out locatedSound);
                    }
                    else if (isSoundEnabled)
                    {
                        if (i > 5)
                            volume = .5f;
                        locatedSound.Volume = volume;
                        locatedSound.Play();
                        break;
                    }
                }
            }
            catch
            {
                Console.WriteLine("playing the sound Failed");
            }
        }

        public void LoadSounds()
        {
            sounds.Add("_click", _click);
            sounds.Add("_deathForEverything", _deathForEverything);
            sounds.Add("_pickup", _pickup);
            sounds.Add("_pickupFuel", _pickupFuel);
            sounds.Add("_playerHurt", _playerHurt);
            sounds.Add("_realClickyClick", _realClickyClick);
            sounds.Add("_scaryGirlHit", _scaryGirlHit);
            sounds.Add("_teslaBeamReady", _teslaBeamReady);
            sounds.Add("_teslaFireBeam", _teslaFireBeam);
            #region TeslaBeamReady
            sounds.Add("_teslaBeamReady1", _teslaBeamReady1);
            sounds.Add("_teslaBeamReady2", _teslaBeamReady2);
            sounds.Add("_teslaBeamReady3", _teslaBeamReady3);
            sounds.Add("_teslaBeamReady4", _teslaBeamReady4);
            sounds.Add("_teslaBeamReady5", _teslaBeamReady5);
            sounds.Add("_teslaBeamReady6", _teslaBeamReady6);
            sounds.Add("_teslaBeamReady7", _teslaBeamReady7);
            sounds.Add("_teslaBeamReady8", _teslaBeamReady8);
            sounds.Add("_teslaBeamReady9", _teslaBeamReady9);
            sounds.Add("_teslaBeamReady10", _teslaBeamReady10);
            sounds.Add("_teslaBeamReady11", _teslaBeamReady11);
            sounds.Add("_teslaBeamReady12", _teslaBeamReady12);
            sounds.Add("_teslaBeamReady13", _teslaBeamReady13);
            sounds.Add("_teslaBeamReady14", _teslaBeamReady14);
            sounds.Add("_teslaBeamReady15", _teslaBeamReady15);
            sounds.Add("_teslaBeamReady16", _teslaBeamReady16);
            sounds.Add("_teslaBeamReady17", _teslaBeamReady17);
            sounds.Add("_teslaBeamReady18", _teslaBeamReady18);
            sounds.Add("_teslaBeamReady19", _teslaBeamReady19);
            sounds.Add("_teslaBeamReady20", _teslaBeamReady20);

            #endregion
            #region TeslaFireBeam
            sounds.Add("_teslaFireBeam1", _teslaFireBeam1);
            sounds.Add("_teslaFireBeam2", _teslaFireBeam2);
            sounds.Add("_teslaFireBeam3", _teslaFireBeam3);
            sounds.Add("_teslaFireBeam4", _teslaFireBeam4);
            sounds.Add("_teslaFireBeam5", _teslaFireBeam5);
            sounds.Add("_teslaFireBeam6", _teslaFireBeam6);
            sounds.Add("_teslaFireBeam7", _teslaFireBeam7);
            sounds.Add("_teslaFireBeam8", _teslaFireBeam8);
            sounds.Add("_teslaFireBeam9", _teslaFireBeam9);
            sounds.Add("_teslaFireBeam10", _teslaFireBeam10);
            sounds.Add("_teslaFireBeam11", _teslaFireBeam11);
            sounds.Add("_teslaFireBeam12", _teslaFireBeam12);
            sounds.Add("_teslaFireBeam13", _teslaFireBeam13);
            sounds.Add("_teslaFireBeam14", _teslaFireBeam14);
            sounds.Add("_teslaFireBeam15", _teslaFireBeam15);
            sounds.Add("_teslaFireBeam16", _teslaFireBeam16);
            sounds.Add("_teslaFireBeam17", _teslaFireBeam17);
            sounds.Add("_teslaFireBeam18", _teslaFireBeam18);
            sounds.Add("_teslaFireBeam19", _teslaFireBeam19);
            sounds.Add("_teslaFireBeam20", _teslaFireBeam20);
            #endregion
            #region scaryGirlHit
            sounds.Add("_scaryGirlHit1", _scaryGirlHit1);
            sounds.Add("_scaryGirlHit2", _scaryGirlHit2);
            sounds.Add("_scaryGirlHit3", _scaryGirlHit3);
            sounds.Add("_scaryGirlHit4", _scaryGirlHit4);
            sounds.Add("_scaryGirlHit5", _scaryGirlHit5);
            sounds.Add("_scaryGirlHit6", _scaryGirlHit6);
            sounds.Add("_scaryGirlHit7", _scaryGirlHit7);
            sounds.Add("_scaryGirlHit8", _scaryGirlHit8);
            sounds.Add("_scaryGirlHit9", _scaryGirlHit9);
            sounds.Add("_scaryGirlHit10", _scaryGirlHit10);
            sounds.Add("_scaryGirlHit11", _scaryGirlHit11);
            sounds.Add("_scaryGirlHit12", _scaryGirlHit12);
            sounds.Add("_scaryGirlHit13", _scaryGirlHit13);
            sounds.Add("_scaryGirlHit14", _scaryGirlHit14);
            sounds.Add("_scaryGirlHit15", _scaryGirlHit15);
            sounds.Add("_scaryGirlHit16", _scaryGirlHit16);
            sounds.Add("_scaryGirlHit17", _scaryGirlHit17);
            sounds.Add("_scaryGirlHit18", _scaryGirlHit18);
            sounds.Add("_scaryGirlHit19", _scaryGirlHit19);
            sounds.Add("_scaryGirlHit20", _scaryGirlHit20);
            sounds.Add("_scaryGirlHit21", _scaryGirlHit21);
            sounds.Add("_scaryGirlHit22", _scaryGirlHit22);
            sounds.Add("_scaryGirlHit23", _scaryGirlHit23);
            sounds.Add("_scaryGirlHit24", _scaryGirlHit24);
            sounds.Add("_scaryGirlHit25", _scaryGirlHit25);
            sounds.Add("_scaryGirlHit26", _scaryGirlHit26);
            sounds.Add("_scaryGirlHit27", _scaryGirlHit27);
            sounds.Add("_scaryGirlHit28", _scaryGirlHit28);
            sounds.Add("_scaryGirlHit29", _scaryGirlHit29);
            sounds.Add("_scaryGirlHit30", _scaryGirlHit30);
            #endregion
        }
        #endregion
    }

}
