using Otter;
using System.Collections.Generic;

namespace GiraffeRoller.Utility
{
    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;
        #region menu sounds
        private Sound _open = new Sound(Assets.SFX_OPEN);
        private Sound _openTwo = new Sound(Assets.SFX_OPEN2);
        private Sound _openThree = new Sound(Assets.SFX_OPEN3);
        private Sound _close = new Sound(Assets.SFX_CLOSE);
        private Sound _blip = new Sound(Assets.SFX_BLIP);
        private Sound _blip1 = new Sound(Assets.SFX_BLIP);
        private Sound _blip2 = new Sound(Assets.SFX_BLIP);
        private Sound _blip3 = new Sound(Assets.SFX_BLIP);
        private Sound _tone = new Sound(Assets.SFX_TONE);
        #endregion
        #region main sounds
        private Sound _bossBoom = new Sound(Assets.SFX_BOSSBOOM);
        private Sound _bossBoom2 = new Sound(Assets.SFX_BOSSBOOM2);
        private Sound _bossBoom3 = new Sound(Assets.SFX_BOSSBOOM3);
        private Sound _bossComeBackHere = new Sound(Assets.SFX_BOSSCOMEBACKHERE);
        private Sound _bossGetAwayThePower = new Sound(Assets.SFX_BOSSGETAWAYTHEPOWER);
        private Sound _bossGetHim = new Sound(Assets.SFX_BOSSGETHIM);
        private Sound _bossHa_HaHa = new Sound(Assets.SFX_BOSSHA_HAHA);
        private Sound _hitCar = new Sound(Assets.SFX_HITCAR);
        private Sound _bossHurt = new Sound(Assets.SFX_BOSSHURT);
        private Sound _bossHurt2 = new Sound(Assets.SFX_BOSSHURT2);
        private Sound _bossIWantToGoOnTheChair = new Sound(Assets.SFX_BOSSIWANTTOGOONTHECHAIR);
        private Sound _bossLaugh = new Sound(Assets.SFX_BOSSLAUGH);
        private Sound _bossLaugh2 = new Sound(Assets.SFX_BOSSLAUGH2);
        private Sound _bossLaugh3 = new Sound(Assets.SFX_BOSSLAUGH3);
        private Sound _bossNotTheWater = new Sound(Assets.SFX_BOSSNOTTHEWATER);
        private Sound _bossNotTheWaterResouvoir = new Sound(Assets.SFX_BOSSNOTTHEWATERRESOUVOIR);
        private Sound _bossOh = new Sound(Assets.SFX_BOSSOH);
        private Sound _bossOof = new Sound(Assets.SFX_BOSSOOF);
        private Sound _bossScarcLaugh = new Sound(Assets.SFX_BOSSSCARCLAUGH);
        private Sound _bossUm = new Sound(Assets.SFX_BOSSUM);
        private Sound _brake = new Sound(Assets.SFX_BRAKE);
        private Sound _brake2 = new Sound(Assets.SFX_BRAKE2);
        private Sound _brake3 = new Sound(Assets.SFX_BRAKE3);
        private Sound _brake4 = new Sound(Assets.SFX_BRAKE4);
        private Sound _carEntrance = new Sound(Assets.SFX_CARENTRANCE);
        private Sound _charge = new Sound(Assets.SFX_CHARGE);
        private Sound _footstep = new Sound(Assets.SFX_FOOTSTEP);
        private Sound _footstep2 = new Sound(Assets.SFX_FOOTSTEP2);
        private Sound _footstep3 = new Sound(Assets.SFX_FOOTSTEP3);
        private Sound _footstep4 = new Sound(Assets.SFX_FOOTSTEP4);
        private Sound _footstep5 = new Sound(Assets.SFX_FOOTSTEP5);
        private Sound _footstep6 = new Sound(Assets.SFX_FOOTSTEP6);
        private Sound _footstep7 = new Sound(Assets.SFX_FOOTSTEP7);
        private Sound _footstep8 = new Sound(Assets.SFX_FOOTSTEP8);
        private Sound _latchClose = new Sound(Assets.SFX_LATCHCLOSE);
        private Sound _latchClose2 = new Sound(Assets.SFX_LATCHCLOSE2);
        private Sound _latchClose3 = new Sound(Assets.SFX_LATCHCLOSE3);
        private Sound _latchOpen = new Sound(Assets.SFX_LATCHOPEN);
        private Sound _latchOpen2 = new Sound(Assets.SFX_LATCHOPEN2);
        private Sound _latchOpen3 = new Sound(Assets.SFX_LATCHOPEN3);
        private Sound _metalHit = new Sound(Assets.SFX_METALHIT);
        private Sound _metalHit2 = new Sound(Assets.SFX_METALHIT2);
        private Sound _metalHit3 = new Sound(Assets.SFX_METALHIT3);
        private Sound _metalHit4 = new Sound(Assets.SFX_METALHIT4);
        private Sound _powerPlantDeath = new Sound(Assets.SFX_POWERPLANTDEATH);
        private Sound _releaseCharge = new Sound(Assets.SFX_RELEASECHARGE);
        private Sound _rocketFlying = new Sound(Assets.SFX_ROCKETFLYING);
        private Sound _roll = new Sound(Assets.SFX_ROLL);
        private Sound _roll2 = new Sound(Assets.SFX_ROLL2);
        private Sound _roll3 = new Sound(Assets.SFX_ROLL3);
        private Sound _roll4 = new Sound(Assets.SFX_ROLL4);
        private Sound _scoot = new Sound(Assets.SFX_SCOOT);
        private Sound _softDoorClose = new Sound(Assets.SFX_SOFTDOORCLOSE);
        private Sound _startGame = new Sound(Assets.SFX_STARTGAME);
        private Sound _suckUp = new Sound(Assets.SFX_SUCKUP);
        private Sound _warehouseHit = new Sound(Assets.SFX_WAREHOUSEHIT);
        private Sound _warehouseHit2 = new Sound(Assets.SFX_WAREHOUSEHIT2);
        private Sound _warehouseHit3 = new Sound(Assets.SFX_WAREHOUSEHIT3);
        private Sound _waterDropDie = new Sound(Assets.SFX_WATERDROPDIE);
        private Sound _waterTowerHit = new Sound(Assets.SFX_WATERTOWERHIT);
        private Sound _waterTowerHit2 = new Sound(Assets.SFX_WATERTOWERHIT2);
        private Sound _waterTowerHit3 = new Sound(Assets.SFX_WATERTOWERHIT3);
        private Sound _waterTowerHit4 = new Sound(Assets.SFX_WATERTOWERHIT4);
        private Sound _waterTowerHit5 = new Sound(Assets.SFX_WATERTOWERHIT5);
        private Sound _waterTowerHit6 = new Sound(Assets.SFX_WATERTOWERHIT6);
        private Sound _waterTowerHit7 = new Sound(Assets.SFX_WATERTOWERHIT7);
        private Sound _waterTowerHit8 = new Sound(Assets.SFX_WATERTOWERHIT8);
        private Sound _waterTowerShot = new Sound(Assets.SFX_WATERTOWERSHOT);
        private Sound _waterTowerShot2 = new Sound(Assets.SFX_WATERTOWERSHOT2);
        private Sound _powerDropShot = new Sound(Assets.SFX_POWERDROPSHOT);
        private Sound _bossDeath = new Sound(Assets.SFX_BOSSDEATH);
        private Sound _bossHitCar2 = new Sound(Assets.SFX_BOSSHITCAR2);
        private Sound _bossHitCar3 = new Sound(Assets.SFX_BOSSHITCAR3);
        private Sound _bossHitCar4 = new Sound(Assets.SFX_BOSSHITCAR4);
        private Sound _concreteShot = new Sound(Assets.SFX_CONCRETESHOT);
        private Sound _concreteShot2 = new Sound(Assets.SFX_CONCRETESHOT2);
        private Sound _concreteShot3 = new Sound(Assets.SFX_CONCRETESHOT3);
        private Sound _concreteShot4 = new Sound(Assets.SFX_CONCRETESHOT4);
        private Sound _rocketShot = new Sound(Assets.SFX_ROCKETSHOT);
        private Sound _rocketShot2 = new Sound(Assets.SFX_ROCKETSHOT2);
        private Sound _rocketShot3 = new Sound(Assets.SFX_ROCKETSHOT3);
        private Sound _rocketShot4 = new Sound(Assets.SFX_ROCKETSHOT4);
        private Sound _rocketShot5 = new Sound(Assets.SFX_ROCKETSHOT5);
        private Sound _rocketShot6 = new Sound(Assets.SFX_ROCKETSHOT6);
        private Sound _rocketShot7 = new Sound(Assets.SFX_ROCKETSHOT7);
        private Sound _rocketShot8 = new Sound(Assets.SFX_ROCKETSHOT8);
        private Sound _rocketShot9 = new Sound(Assets.SFX_ROCKETSHOT9);
        private Sound _rocketShot10 = new Sound(Assets.SFX_ROCKETSHOT10);
        private Sound _rocketShot11 = new Sound(Assets.SFX_ROCKETSHOT11);
        private Sound _rocketShot12 = new Sound(Assets.SFX_ROCKETSHOT12);
        private Sound _rocketShot13 = new Sound(Assets.SFX_ROCKETSHOT13);
        private Sound _rocketShot14 = new Sound(Assets.SFX_ROCKETSHOT14);
        private Sound _rocketShot15 = new Sound(Assets.SFX_ROCKETSHOT15);
        private Sound _rocketShot16 = new Sound(Assets.SFX_ROCKETSHOT16);
        private Sound _warehouseDeath = new Sound(Assets.SFX_WAREHOUSEDEATH);
        private Sound _waterTowerHit9 = new Sound(Assets.SFX_WATERHIT9);
        #endregion
        #region SoundInstances
        private static Sound locatedSound;
        #region DifferentBubbleSound
        private Sound _giraffeDeathFast = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast1 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast2 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast3 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast4 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast5 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast6 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast7 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast8 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast9 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDeathFast10 = new Sound(Assets.SFX_GIRAFFEDEATHFAST);
        private Sound _giraffeDying = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying1 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying2 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying3 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying4 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying5 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying6 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying7 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying8 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying9 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying10 = new Sound(Assets.SFX_GIRAFFEDYING);
        private Sound _giraffeDying11 = new Sound(Assets.SFX_GIRAFFEDYING);
        /* This is when we want to make the same sound, but have more than one going off at a time.
         * Through experience I've found it better to just make 10 unique sounds for this sound and have each one of those play randomly that way they
         * don't stack and fail to play like this one. Then you just add the amount of sounds based on the frequency you want to hear.
        private Sound _differentBubbleSound = new Sound(Assets.SFX_DIFF_BUBBLE_SOUND);
        private Sound _differentBubbleSound1 = new Sound(Assets.SFX_DIFF_BUBBLE_SOUND);
        private Sound _differentBubbleSound2 = new Sound(Assets.SFX_DIFF_BUBBLE_SOUND);
        private Sound _differentBubbleSound3 = new Sound(Assets.SFX_DIFF_BUBBLE_SOUND);
        private Sound _differentBubbleSound4 = new Sound(Assets.SFX_DIFF_BUBBLE_SOUND);
        */
        #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 I don't try to set the volume.
                        {
                            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 whatever we initially set it to.
                            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 really reduce it
                        }
                        #endregion
                        locatedSound.Volume = volume;
                        locatedSound.Play();
                        break;
                    }
                }
            }
            catch
            {
                //Console.WriteLine("playing the sound Failed");
            }
        }

        public void LoadSounds()
        {
            #region menu sounds
            sounds.Add("_open", _open);
            sounds.Add("_openTwo", _openTwo);
            sounds.Add("_openThree", _openThree);
            sounds.Add("_close", _close);
            sounds.Add("_blip", _blip);
            sounds.Add("_blip1", _blip1);
            sounds.Add("_blip2", _blip2);
            sounds.Add("_blip3", _blip3);
            sounds.Add("_tone", _tone);
            #endregion
            #region main sounds
            sounds.Add("_bossBoom", _bossBoom);
            sounds.Add("_bossBoom2", _bossBoom2);
            sounds.Add("_bossBoom3", _bossBoom3);
            sounds.Add("_bossComeBackHere", _bossComeBackHere);
            sounds.Add("_bossGetAwayThePower", _bossGetAwayThePower);
            sounds.Add("_bossGetHim", _bossGetHim);
            sounds.Add("_bossHa_HaHa", _bossHa_HaHa);
            sounds.Add("_hitCar", _hitCar);
            sounds.Add("_bossHurt", _bossHurt);
            sounds.Add("_bossHurt2", _bossHurt2);
            sounds.Add("_bossIWantToGoOnTheChair", _bossIWantToGoOnTheChair);
            sounds.Add("_bossLaugh", _bossLaugh);
            sounds.Add("_bossLaugh2", _bossLaugh2);
            sounds.Add("_bossLaugh3", _bossLaugh3);
            sounds.Add("_bossNotTheWater", _bossNotTheWater);
            sounds.Add("_bossNotTheWaterResouvoir", _bossNotTheWaterResouvoir);
            sounds.Add("_bossOh", _bossOh);
            sounds.Add("_bossOof", _bossOof);
            sounds.Add("_bossScarcLaugh", _bossScarcLaugh);
            sounds.Add("_bossUm", _bossUm);
            sounds.Add("_brake", _brake);
            sounds.Add("_brake2", _brake2);
            sounds.Add("_brake3", _brake3);
            sounds.Add("_brake4", _brake4);
            sounds.Add("_carEntrance", _carEntrance);
            sounds.Add("_charge", _charge);
            sounds.Add("_footstep", _footstep);
            sounds.Add("_footstep2", _footstep2);
            sounds.Add("_footstep3", _footstep3);
            sounds.Add("_footstep4", _footstep4);
            sounds.Add("_footstep5", _footstep5);
            sounds.Add("_footstep6", _footstep6);
            sounds.Add("_footstep7", _footstep7);
            sounds.Add("_footstep8", _footstep8);
            sounds.Add("_latchClose", _latchClose);
            sounds.Add("_latchClose2", _latchClose2);
            sounds.Add("_latchClose3", _latchClose3);
            sounds.Add("_latchOpen", _latchOpen);
            sounds.Add("_latchOpen2", _latchOpen2);
            sounds.Add("_latchOpen3", _latchOpen3);
            sounds.Add("_metalHit", _metalHit);
            sounds.Add("_metalHit2", _metalHit2);
            sounds.Add("_metalHit3", _metalHit3);
            sounds.Add("_metalHit4", _metalHit4);
            sounds.Add("_powerPlantDeath", _powerPlantDeath);
            sounds.Add("_releaseCharge", _releaseCharge);
            sounds.Add("_rocketFlying", _rocketFlying);
            sounds.Add("_roll", _roll);
            sounds.Add("_roll2", _roll2);
            sounds.Add("_roll3", _roll3);
            sounds.Add("_roll4", _roll4);
            sounds.Add("_scoot", _scoot);
            sounds.Add("_softDoorClose", _softDoorClose);
            sounds.Add("_startGame", _startGame);
            sounds.Add("_suckUp", _suckUp);
            sounds.Add("_warehouseHit", _warehouseHit);
            sounds.Add("_warehouseHit2", _warehouseHit2);
            sounds.Add("_warehouseHit3", _warehouseHit3);
            sounds.Add("_waterDropDie", _waterDropDie);
            sounds.Add("_waterTowerHit", _waterTowerHit);
            sounds.Add("_waterTowerHit2", _waterTowerHit2);
            sounds.Add("_waterTowerHit3", _waterTowerHit3);
            sounds.Add("_waterTowerHit4", _waterTowerHit4);
            sounds.Add("_waterTowerHit5", _waterTowerHit5);
            sounds.Add("_waterTowerHit6", _waterTowerHit6);
            sounds.Add("_waterTowerHit7", _waterTowerHit7);
            sounds.Add("_waterTowerHit8", _waterTowerHit8);
            sounds.Add("_waterTowerHit9", _waterTowerHit9);
            sounds.Add("_waterTowerShot", _waterTowerShot);
            sounds.Add("_waterTowerShot2", _waterTowerShot2);
            sounds.Add("_powerDropShot", _powerDropShot);
            //new
            sounds.Add("_bossDeath", _bossDeath);
            sounds.Add("_bossHitCar2", _bossHitCar2);
            sounds.Add("_bossHitCar3", _bossHitCar3);
            sounds.Add("_bossHitCar4", _bossHitCar4);
            sounds.Add("_concreteShot", _concreteShot);
            sounds.Add("_concreteShot2", _concreteShot2);
            sounds.Add("_concreteShot3", _concreteShot3);
            sounds.Add("_concreteShot4", _concreteShot4);
            sounds.Add("_rocketShot", _rocketShot);
            sounds.Add("_rocketShot2", _rocketShot2);
            sounds.Add("_rocketShot3", _rocketShot3);
            sounds.Add("_rocketShot4", _rocketShot4);
            sounds.Add("_rocketShot5", _rocketShot5);
            sounds.Add("_rocketShot6", _rocketShot6);
            sounds.Add("_rocketShot7", _rocketShot7);
            sounds.Add("_rocketShot8", _rocketShot8);
            sounds.Add("_rocketShot9", _rocketShot9);
            sounds.Add("_rocketShot10", _rocketShot10);
            sounds.Add("_rocketShot11", _rocketShot11);
            sounds.Add("_rocketShot12", _rocketShot12);
            sounds.Add("_rocketShot13", _rocketShot13);
            sounds.Add("_rocketShot14", _rocketShot14);
            sounds.Add("_rocketShot15", _rocketShot15);
            sounds.Add("_rocketShot16", _rocketShot16);
            sounds.Add("_warehouseDeath", _warehouseDeath);
            #endregion

            #region different bubble sound
            /*
            sounds.Add("_differentBubbleSound", _differentBubbleSound);
            sounds.Add("_differentBubbleSound1", _differentBubbleSound1);
            sounds.Add("_differentBubbleSound2", _differentBubbleSound2);
            sounds.Add("_differentBubbleSound3", _differentBubbleSound3);
            */
            sounds.Add("_giraffeDeathFast", _giraffeDeathFast);
            sounds.Add("_giraffeDeathFast1", _giraffeDeathFast1);
            sounds.Add("_giraffeDeathFast2", _giraffeDeathFast2);
            sounds.Add("_giraffeDeathFast3", _giraffeDeathFast3);
            sounds.Add("_giraffeDeathFast4", _giraffeDeathFast4);
            sounds.Add("_giraffeDeathFast5", _giraffeDeathFast5);
            sounds.Add("_giraffeDeathFast6", _giraffeDeathFast6);
            sounds.Add("_giraffeDeathFast7", _giraffeDeathFast7);
            sounds.Add("_giraffeDeathFast8", _giraffeDeathFast8);
            sounds.Add("_giraffeDeathFast9", _giraffeDeathFast9);
            sounds.Add("_giraffeDeathFast10", _giraffeDeathFast10);
            sounds.Add("_giraffeDying", _giraffeDying1);
            sounds.Add("_giraffeDying1", _giraffeDying1);
            sounds.Add("_giraffeDying2", _giraffeDying2);
            sounds.Add("_giraffeDying3", _giraffeDying3);
            sounds.Add("_giraffeDying4", _giraffeDying4);
            sounds.Add("_giraffeDying5", _giraffeDying5);
            sounds.Add("_giraffeDying6", _giraffeDying6);
            sounds.Add("_giraffeDying7", _giraffeDying7);
            sounds.Add("_giraffeDying8", _giraffeDying8);
            sounds.Add("_giraffeDying9", _giraffeDying9);
            sounds.Add("_giraffeDying10", _giraffeDying10);
            sounds.Add("_giraffeDying11", _giraffeDying11);
            #endregion
        }
        #endregion
    }

}

