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

namespace Puppyups.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 _paattention = new Sound(Assets.SFX_PAATTENTION);
        private Sound _pabeep = new Sound(Assets.SFX_PABEEP);
        private Sound _pasmog = new Sound(Assets.SFX_PASMOGMONSTER);
        private Sound _patake = new Sound(Assets.SFX_PATAKEWHAT);
        private Sound _pawarning = new Sound(Assets.SFX_PAWARNING);
        private Sound _paheyisee = new Sound(Assets.SFX_PAHEYISEE);
        private Sound _paguns = new Sound(Assets.SFX_PAGUNS);
        private Sound _aaaa = new Sound(Assets.SFX_AAAA);
        private Sound _aaaa2 = new Sound(Assets.SFX_AAAA2);
        private Sound _manhahahaha = new Sound(Assets.SFX_MAN_HAHAHA);
        private Sound _manigotit = new Sound(Assets.SFX_MAN_IGOTIT);
        private Sound _manwhatwas = new Sound(Assets.SFX_MAN_WHATWAS);
        private Sound _girlohok = new Sound(Assets.SFX_GIRL_OHOK);
        private Sound _grapple = new Sound(Assets.SFX_GRAPPLE);
        private Sound _grapple2 = new Sound(Assets.SFX_GRAPPLE2);
        private Sound _p1aimer = new Sound(Assets.SFX_P1AIMER);
        private Sound _p2aimer = new Sound(Assets.SFX_P2AIMER);
        private Sound _ringcollect = new Sound(Assets.SFX_RINGCOLLECT);
        private Sound _pull = new Sound(Assets.SFX_PULL);
        private Sound _pull2 = new Sound(Assets.SFX_PULL2);
        private Sound _dogstun = new Sound(Assets.SFX_DOGSTUN);
        private Sound _dogstun1= new Sound(Assets.SFX_DOGSTUN1);
        private Sound _dogstun2 = new Sound(Assets.SFX_DOGSTUN2);
        private Sound _pickup = new Sound(Assets.SFX_PICKUP);
        private Sound _death = new Sound(Assets.SFX_DEATH);
        #region goldcoin
        private Sound _goldcoin = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin1 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin2 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin3 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin4 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin5 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin6 = new Sound(Assets.SFX_GOLDCOIN);
        private Sound _goldcoin7 = new Sound(Assets.SFX_GOLDCOIN);
        #endregion
        #region
        private Sound _silvercoin = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin1 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin2 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin3 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin4 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin5 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin6 = new Sound(Assets.SFX_SILVERCOIN);
        private Sound _silvercoin7 = new Sound(Assets.SFX_SILVERCOIN);
        #endregion
        #region
        private Sound _platcoin = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin1 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin2 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin3 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin4 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin5 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin6 = new Sound(Assets.SFX_PLATCOIN);
        private Sound _platcoin7 = new Sound(Assets.SFX_PLATCOIN);
        #endregion
        #region Yips
        #region yipOne
        private Sound _yipOne1 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne2 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne3 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne4 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne5 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne6 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne7 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne8 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne9 = new Sound(Assets.SFX_YIP1);
        private Sound _yipOne10 = new Sound(Assets.SFX_YIP1);
        #endregion
        #region yipTwo
        private Sound _yipTwo1 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo2 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo3 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo4 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo5 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo6 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo7 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo8 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo9 = new Sound(Assets.SFX_YIP2);
        private Sound _yipTwo10 = new Sound(Assets.SFX_YIP2);
        #endregion
        #region yipThree
        private Sound _yipThree1 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree2 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree3 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree4 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree5 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree6 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree7 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree8 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree9 = new Sound(Assets.SFX_YIP3);
        private Sound _yipThree10 = new Sound(Assets.SFX_YIP3);
        #endregion
        #region yipFour
        private Sound _yipFour1 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour2 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour3 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour4 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour5 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour6 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour7 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour8 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour9 = new Sound(Assets.SFX_YIP4);
        private Sound _yipFour10 = new Sound(Assets.SFX_YIP4);
        #endregion
        #region yipFive
        private Sound _yipFive1 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive2 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive3 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive4 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive5 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive6 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive7 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive8 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive9 = new Sound(Assets.SFX_YIP5);
        private Sound _yipFive10 = new Sound(Assets.SFX_YIP5);
        #endregion
        #region yipSix
        private Sound _yipSix1 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix2 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix3 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix4 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix5 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix6 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix7 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix8 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix9 = new Sound(Assets.SFX_YIP6);
        private Sound _yipSix10 = new Sound(Assets.SFX_YIP6);
        #endregion
        #region yipSeven
        private Sound _yipSeven1 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven2 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven3 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven4 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven5 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven6 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven7 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven8 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven9 = new Sound(Assets.SFX_YIP7);
        private Sound _yipSeven10 = new Sound(Assets.SFX_YIP7);
        #endregion
        #endregion
        #region breathing
        private Sound _breathing1 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing2 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing3 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing4 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing5 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing6 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing7 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing8 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing9 = new Sound(Assets.SFX_BREATHING);
        private Sound _breathing10 = new Sound(Assets.SFX_BREATHING);
        #endregion
        #region SoundInstances
        private static Sound locatedSound;
        #region PunchTree
        /*private Sound _punchTree1 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree2 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree3 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree4 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree5 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree6 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree7 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree8 = new Sound(Assets.SFX_PUNCHTREE);
        private Sound _punchTree9 = new Sound(Assets.SFX_PUNCHTREE);*/
        #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)
        {
            _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 Failed");//testing REMOVE THIS WHEN GOING LIVE (well not that it matters since console is deactiveated...)
            }
        }

        public void LoadSounds()
        {
            sounds.Add("_paattention", _paattention);
            sounds.Add("_pabeep", _pabeep);
            sounds.Add("_pasmog", _pasmog);
            sounds.Add("_pawarning", _pawarning);
            sounds.Add("_patake", _patake);
            sounds.Add("_paheyisee", _paheyisee);
            sounds.Add("_paguns", _paguns);
            sounds.Add("_aaaa", _aaaa);
            sounds.Add("_aaaa2", _aaaa2);
            sounds.Add("_manhahahaha", _manhahahaha);
            sounds.Add("_manigotit", _manigotit);
            sounds.Add("_manwhatwas", _manwhatwas);
            sounds.Add("_girlohok", _girlohok);
            sounds.Add("_grapple", _grapple);
            sounds.Add("_grapple2", _grapple2);
            sounds.Add("_p1aimer", _p1aimer);
            sounds.Add("_p2aimer", _p2aimer);
            sounds.Add("_ringcollect", _ringcollect);
            sounds.Add("_pull", _pull);
            sounds.Add("_pull2", _pull2);
            sounds.Add("_dogstun", _dogstun);
            sounds.Add("_dogstun1", _dogstun1);
            sounds.Add("_dogstun2", _dogstun2);
            sounds.Add("_pickup", _pickup);
            sounds.Add("_death", _death);
            #region goldcoin
            sounds.Add("_goldcoin", _goldcoin);
            sounds.Add("_goldcoin1", _goldcoin1);
            sounds.Add("_goldcoin2", _goldcoin2);
            sounds.Add("_goldcoin3", _goldcoin3);
            sounds.Add("_goldcoin4", _goldcoin4);
            sounds.Add("_goldcoin5", _goldcoin5);
            sounds.Add("_goldcoin6", _goldcoin6);
            sounds.Add("_goldcoin7", _goldcoin7);
            #endregion
            #region platCoin
            sounds.Add("_platcoin", _platcoin);
            sounds.Add("_platcoin1", _platcoin1);
            sounds.Add("_platcoin2", _platcoin2);
            sounds.Add("_platcoin3", _platcoin3);
            sounds.Add("_platcoin4", _platcoin4);
            sounds.Add("_platcoin5", _platcoin5);
            sounds.Add("_platcoin6", _platcoin6);
            sounds.Add("_platcoin7", _platcoin7);
            #endregion
            #region silvercoin
            sounds.Add("_silvercoin", _silvercoin);
            sounds.Add("_silvercoin1", _silvercoin1);
            sounds.Add("_silvercoin2", _silvercoin2);
            sounds.Add("_silvercoin3", _silvercoin3);
            sounds.Add("_silvercoin4", _silvercoin4);
            sounds.Add("_silvercoin5", _silvercoin5);
            sounds.Add("_silvercoin6", _silvercoin6);
            sounds.Add("_silvercoin7", _silvercoin7);
            #endregion
            #region yips
            #region yipOne
            sounds.Add("_yipOne1", _yipOne1);
            sounds.Add("_yipOne2", _yipOne2);
            sounds.Add("_yipOne3", _yipOne3);
            sounds.Add("_yipOne4", _yipOne4);
            sounds.Add("_yipOne5", _yipOne5);
            sounds.Add("_yipOne6", _yipOne6);
            sounds.Add("_yipOne7", _yipOne7);
            sounds.Add("_yipOne8", _yipOne8);
            sounds.Add("_yipOne9", _yipOne9);
            sounds.Add("_yipOne10", _yipOne10);
            #endregion
            #region yipTwo
            sounds.Add("_yipTwo1", _yipTwo1);
            sounds.Add("_yipTwo2", _yipTwo2);
            sounds.Add("_yipTwo3", _yipTwo3);
            sounds.Add("_yipTwo4", _yipTwo4);
            sounds.Add("_yipTwo5", _yipTwo5);
            sounds.Add("_yipTwo6", _yipTwo6);
            sounds.Add("_yipTwo7", _yipTwo7);
            sounds.Add("_yipTwo8", _yipTwo8);
            sounds.Add("_yipTwo9", _yipTwo9);
            sounds.Add("_yipTwo10", _yipTwo10);
            #endregion
            #region yipThree
            sounds.Add("_yipThree1", _yipThree1);
            sounds.Add("_yipThree2", _yipThree2);
            sounds.Add("_yipThree3", _yipThree3);
            sounds.Add("_yipThree4", _yipThree4);
            sounds.Add("_yipThree5", _yipThree5);
            sounds.Add("_yipThree6", _yipThree6);
            sounds.Add("_yipThree7", _yipThree7);
            sounds.Add("_yipThree8", _yipThree8);
            sounds.Add("_yipThree9", _yipThree9);
            sounds.Add("_yipThree10", _yipThree10);
            #endregion
            #region yipFour
            sounds.Add("_yipFour1", _yipFour1);
            sounds.Add("_yipFour2", _yipFour2);
            sounds.Add("_yipFour3", _yipFour3);
            sounds.Add("_yipFour4", _yipFour4);
            sounds.Add("_yipFour5", _yipFour5);
            sounds.Add("_yipFour6", _yipFour6);
            sounds.Add("_yipFour7", _yipFour7);
            sounds.Add("_yipFour8", _yipFour8);
            sounds.Add("_yipFour9", _yipFour9);
            sounds.Add("_yipFour10", _yipFour10);
            #endregion
            #region yipFive
            sounds.Add("_yipFive1", _yipFive1);
            sounds.Add("_yipFive2", _yipFive2);
            sounds.Add("_yipFive3", _yipFive3);
            sounds.Add("_yipFive4", _yipFive4);
            sounds.Add("_yipFive5", _yipFive5);
            sounds.Add("_yipFive6", _yipFive6);
            sounds.Add("_yipFive7", _yipFive7);
            sounds.Add("_yipFive8", _yipFive8);
            sounds.Add("_yipFive9", _yipFive9);
            sounds.Add("_yipFive10", _yipFive10);
            #endregion
            #region yipSix
            sounds.Add("_yipSix1", _yipSix1);
            sounds.Add("_yipSix2", _yipSix2);
            sounds.Add("_yipSix3", _yipSix3);
            sounds.Add("_yipSix4", _yipSix4);
            sounds.Add("_yipSix5", _yipSix5);
            sounds.Add("_yipSix6", _yipSix6);
            sounds.Add("_yipSix7", _yipSix7);
            sounds.Add("_yipSix8", _yipSix8);
            sounds.Add("_yipSix9", _yipSix9);
            sounds.Add("_yipSix10", _yipSix10);
            #endregion
            #region yipSeven
            sounds.Add("_yipSeven1", _yipSeven1);
            sounds.Add("_yipSeven2", _yipSeven2);
            sounds.Add("_yipSeven3", _yipSeven3);
            sounds.Add("_yipSeven4", _yipSeven4);
            sounds.Add("_yipSeven5", _yipSeven5);
            sounds.Add("_yipSeven6", _yipSeven6);
            sounds.Add("_yipSeven7", _yipSeven7);
            sounds.Add("_yipSeven8", _yipSeven8);
            sounds.Add("_yipSeven9", _yipSeven9);
            sounds.Add("_yipSeven10", _yipSeven10);
            #endregion
            #endregion
            #region breathing
            sounds.Add("_breathing1", _breathing1);
            sounds.Add("_breathing2", _breathing2);
            sounds.Add("_breathing3", _breathing3);
            sounds.Add("_breathing4", _breathing4);
            sounds.Add("_breathing5", _breathing5);
            sounds.Add("_breathing6", _breathing6);
            sounds.Add("_breathing7", _breathing7);
            sounds.Add("_breathing8", _breathing8);
            sounds.Add("_breathing9", _breathing9);
            sounds.Add("_breathing10", _breathing10);
            #endregion
        }
        #endregion
    }

}


