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

namespace LOoSE_sLOTS.Utilities
{
    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 static float _volume = 0;
        private Sound _introCreepy = new Sound(Assets.SFX_INTROCREEPY);
        private Sound _hey = new Sound(Assets.SFX_HEY);
        private Sound _hey2 = new Sound(Assets.SFX_HEY2);
        private Sound _hey3 = new Sound(Assets.SFX_HEY3);
        private Sound _hey4 = new Sound(Assets.SFX_HEY4);
        private Sound _hi = new Sound(Assets.SFX_HI);
        private Sound _longerCreepyVibe = new Sound(Assets.SFX_LONGERCREEPYVIBE);
        private Sound _oh = new Sound(Assets.SFX_OH);
        private Sound _wheresTheGame = new Sound(Assets.SFX_WHERESTHEGAME);
        private Sound _andAndDoYouKnowWhatIWant = new Sound(Assets.SFX_ANDANDDOYOUKNOWWHATIWANT);
        private Sound _giveMeMoney = new Sound(Assets.SFX_GIVEMEMONEY);
        private Sound _now = new Sound(Assets.SFX_NOW);
        private Sound _toGetPaid = new Sound(Assets.SFX_TOGETPAID);
        private Sound _wellIDidThis = new Sound(Assets.SFX_WELLIDIDTHIS);
        private Sound _click = new Sound(Assets.SFX_CLICK);
        private Sound _coinBounce = new Sound(Assets.SFX_COINBOUNCE);
        private Sound _coinBounce2 = new Sound(Assets.SFX_COINBOUNCE2);
        private Sound _coinBounce3 = new Sound(Assets.SFX_COINBOUNCE3);
        private Sound _coinBounce4 = new Sound(Assets.SFX_COINBOUNCE4);
        private Sound _coinBounce5 = new Sound(Assets.SFX_COINBOUNCE5);
        private Sound _coinBounce6 = new Sound(Assets.SFX_COINBOUNCE6);
        private Sound _coinBounce7 = new Sound(Assets.SFX_COINBOUNCE7);
        private Sound _coinBounce8 = new Sound(Assets.SFX_COINBOUNCE8);
        private Sound _coinBounce9 = new Sound(Assets.SFX_COINBOUNCE9);
        private Sound _coinBounce10 = new Sound(Assets.SFX_COINBOUNCE10);
        private Sound _coinBounce11 = new Sound(Assets.SFX_COINBOUNCE11);
        private Sound _coinBounce12 = new Sound(Assets.SFX_COINBOUNCE12);
        private Sound _coinBounce13 = new Sound(Assets.SFX_COINBOUNCE13);
        private Sound _coinBounce14 = new Sound(Assets.SFX_COINBOUNCE14);
        private Sound _coinBounce15 = new Sound(Assets.SFX_COINBOUNCE15);
        private Sound _coinBounce16 = new Sound(Assets.SFX_COINBOUNCE16);
        private Sound _coinBounce17 = new Sound(Assets.SFX_COINBOUNCE17);
        private Sound _coinBounce18 = new Sound(Assets.SFX_COINBOUNCE18);
        private Sound _coinBounce19 = new Sound(Assets.SFX_COINBOUNCE19);
        private Sound _coinBounce20 = new Sound(Assets.SFX_COINBOUNCE20);
        private Sound _getMeOutOfThisThing = new Sound(Assets.SFX_GETMEOUTOFTHISTHING);
        private Sound _noo = new Sound(Assets.SFX_NOO);
        private Sound _ohNoWhatsThat = new Sound(Assets.SFX_OHNOWHATSTHAT);
        private Sound _thereSheIsLetsTakeHerAway = new Sound(Assets.SFX_THERESHEISLETSTAKEHERAWAY);
        private Sound _truckSound = new Sound(Assets.SFX_TRUCKSOUND);
        private Sound _iDontWantToDie = new Sound(Assets.SFX_IDONTWANTTODIE);
        private Sound _dead = new Sound(Assets.SFX_DEAD);
        private Sound _dead2 = new Sound(Assets.SFX_DEAD2);
        private Sound _dead3 = new Sound(Assets.SFX_DEAD3);
        private Sound _dead4 = new Sound(Assets.SFX_DEAD4);
        private Sound _dead5 = new Sound(Assets.SFX_DEAD5);
        private Sound _dead6 = new Sound(Assets.SFX_DEAD6);
        private Sound _dead7 = new Sound(Assets.SFX_DEAD7);
        private Sound _dead8 = new Sound(Assets.SFX_DEAD8);
        private Sound _dead9 = new Sound(Assets.SFX_DEAD9);
        private Sound _dead10 = new Sound(Assets.SFX_DEAD10);
        private Sound _dead11 = new Sound(Assets.SFX_DEAD11);
        private Sound _dead12 = new Sound(Assets.SFX_DEAD12);
        private Sound _dead13 = new Sound(Assets.SFX_DEAD13);
        private Sound _dead14 = new Sound(Assets.SFX_DEAD14);
        private Sound _dead15 = new Sound(Assets.SFX_DEAD15);
        private Sound _shot = new Sound(Assets.SFX_SHOT);
        private Sound _getThatMoney = new Sound(Assets.SFX_GETTHATMONEY);
        private Sound _lost = new Sound(Assets.SFX_LOST);
        private Sound _bossHurt = new Sound(Assets.SFX_BOSSHURT);
        private Sound _sniperHurt = new Sound(Assets.SFX_SNIPERHURT);
        private Sound _win = new Sound(Assets.SFX_WIN);
        #region bleep
        private Sound _bleep = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep1 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep2 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep3 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep4 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep5 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep6 = new Sound(Assets.SFX_BLEEP);
        private Sound _bleep7 = new Sound(Assets.SFX_BLEEP);
        #endregion
        #region bleep2
        private Sound _bleepTwo = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo1 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo2 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo3 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo4 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo5 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo6 = new Sound(Assets.SFX_BLEEP2);
        private Sound _bleepTwo7 = new Sound(Assets.SFX_BLEEP2);
        #endregion        
        #region smash
        private Sound _smash = new Sound(Assets.SFX_SMASH);
        private Sound _smash1 = new Sound(Assets.SFX_SMASH);
        private Sound _smash2 = new Sound(Assets.SFX_SMASH);
        private Sound _smash3 = new Sound(Assets.SFX_SMASH);
        private Sound _smash4 = new Sound(Assets.SFX_SMASH);
        private Sound _smash5 = new Sound(Assets.SFX_SMASH);
        private Sound _smash6 = new Sound(Assets.SFX_SMASH);
        private Sound _smash7 = new Sound(Assets.SFX_SMASH);
        #endregion
        #region SoundInstances
        private static Sound locatedSound;
        #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)
        {
            _volume = volume;
            //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)
                    {
                        //i need the volume of the sound to decrease the more you have playing at the same time.
                        //so if 1 full sound. 2 a little less, 3 etc.
                        #region SetSoundVolumeBasedOnNumberOfSoundsPlayingAtOnce
                        if (_volume == 1)//this represents the Default volume settings if you don't try to set the volume level manually
                        {
                            if (i == 1)
                                volume = 1f;
                            else if (i == 2)
                                volume = .9f;
                            else if (i == 3)
                                volume = .8f;
                            else if (i == 4)
                                volume = .7f;
                            else if (i == 5)
                                volume = .6f;
                            else if (i == 6)
                                volume = .5f;
                            else if (i == 7)
                                volume = .4f;
                            else if (i == 8)
                                volume = .3f;
                            else if (i == 9)
                                volume = .2f;
                            else if (i == 10)
                                volume = .1f;
                            else if (i == 11)
                                volume = .09f;
                            else if (i >= 12)
                                volume = .08f;
                        }
                        else //if i do set the volume, just reduce the level of sound as we go.
                        {
                            if (i == 1)
                                volume = _volume;//reset the volume to initial settings.
                            else if (i >= 2 && i < 12 && volume > .01f)//reduce the volume by a slower rate
                            {
                                volume -= .02f;
                            }
                            else if (i >= 12 && volume > .01f)
                                volume -= .1f;//now we really reduce it.
                        }
                        #endregion
                        locatedSound.Volume = volume;
                        locatedSound.Play();
                        break;
                    }
                }
            }
            catch
            {
                //Console.WriteLine("playing the sound: {0} Failed", sound);//testing REMOVE THIS WHEN GOING LIVE (well not that it matters since console is deactiveated...)
            }
        }

        public void LoadSounds()
        {
            sounds.Add("_introCreepy", _introCreepy);
            sounds.Add("_hey", _hey);
            sounds.Add("_hey2", _hey2);
            sounds.Add("_hey3", _hey3);
            sounds.Add("_hey4", _hey4);
            sounds.Add("_hi", _hi);
            sounds.Add("_longerCreepyVibe", _longerCreepyVibe);
            sounds.Add("_oh", _oh);
            sounds.Add("_wheresTheGame", _wheresTheGame);
            sounds.Add("_andAndDoYouKnowWhatIWant", _andAndDoYouKnowWhatIWant);
            sounds.Add("_giveMeMoney", _giveMeMoney);
            sounds.Add("_now", _now);
            sounds.Add("_toGetPaid", _toGetPaid);
            sounds.Add("_wellIDidThis", _wellIDidThis);
            sounds.Add("_click", _click);
            sounds.Add("_coinBounce", _coinBounce);
            sounds.Add("_coinBounce2", _coinBounce2);
            sounds.Add("_coinBounce3", _coinBounce3);
            sounds.Add("_coinBounce4", _coinBounce4);
            sounds.Add("_coinBounce5", _coinBounce5);
            sounds.Add("_coinBounce6", _coinBounce6);
            sounds.Add("_coinBounce7", _coinBounce7);
            sounds.Add("_coinBounce8", _coinBounce8);
            sounds.Add("_coinBounce9", _coinBounce9);
            sounds.Add("_coinBounce10", _coinBounce10);
            sounds.Add("_coinBounce11", _coinBounce11);
            sounds.Add("_coinBounce12", _coinBounce12);
            sounds.Add("_coinBounce13", _coinBounce13);
            sounds.Add("_coinBounce14", _coinBounce14);
            sounds.Add("_coinBounce15", _coinBounce15);
            sounds.Add("_coinBounce16", _coinBounce16);
            sounds.Add("_coinBounce17", _coinBounce17);
            sounds.Add("_coinBounce18", _coinBounce18);
            sounds.Add("_coinBounce19", _coinBounce19);
            sounds.Add("_coinBounce20", _coinBounce20);
            sounds.Add("_getMeOutOfThisThing", _getMeOutOfThisThing);
            sounds.Add("_noo", _noo);
            sounds.Add("_ohNoWhatsThat", _ohNoWhatsThat);
            sounds.Add("_thereSheIsLetsTakeHerAway", _thereSheIsLetsTakeHerAway);
            sounds.Add("_truckSound", _truckSound);
            sounds.Add("_iDontWantToDie", _iDontWantToDie);
            sounds.Add("_dead", _dead);
            sounds.Add("_dead2", _dead2);
            sounds.Add("_dead3", _dead3);
            sounds.Add("_dead4", _dead4);
            sounds.Add("_dead5", _dead5);
            sounds.Add("_dead6", _dead6);
            sounds.Add("_dead7", _dead7);
            sounds.Add("_dead8", _dead8);
            sounds.Add("_dead9", _dead9);
            sounds.Add("_dead10", _dead10);
            sounds.Add("_dead11", _dead11);
            sounds.Add("_dead12", _dead12);
            sounds.Add("_dead13", _dead13);
            sounds.Add("_dead14", _dead14);
            sounds.Add("_dead15", _dead15);
            sounds.Add("_getThatMoney", _getThatMoney);
            sounds.Add("_shot", _shot);
            sounds.Add("_lost", _lost);
            sounds.Add("_bossHurt", _bossHurt);
            sounds.Add("_sniperHurt", _sniperHurt);
            sounds.Add("_win", _win);

            #region bleep
            sounds.Add("_bleep", _bleep);
            sounds.Add("_bleep1", _bleep1);
            sounds.Add("_bleep2", _bleep2);
            sounds.Add("_bleep3", _bleep3);
            sounds.Add("_bleep4", _bleep4);
            sounds.Add("_bleep5", _bleep5);
            sounds.Add("_bleep6", _bleep6);
            sounds.Add("_bleep7", _bleep7);
            #endregion
            #region bleepTwo
            sounds.Add("_bleepTwo", _bleepTwo);
            sounds.Add("_bleepTwo1", _bleepTwo1);
            sounds.Add("_bleepTwo2", _bleepTwo2);
            sounds.Add("_bleepTwo3", _bleepTwo3);
            sounds.Add("_bleepTwo4", _bleepTwo4);
            sounds.Add("_bleepTwo5", _bleepTwo5);
            sounds.Add("_bleepTwo6", _bleepTwo6);
            sounds.Add("_bleepTwo7", _bleepTwo7);
            #endregion  
            #region smash
            sounds.Add("_smash", _smash);
            sounds.Add("_smash1", _smash1);
            sounds.Add("_smash2", _smash2);
            sounds.Add("_smash3", _smash3);
            sounds.Add("_smash4", _smash4);
            sounds.Add("_smash5", _smash5);
            sounds.Add("_smash6", _smash6);
            sounds.Add("_smash7", _smash7);
            #endregion            
        }
        #endregion
    }

}



