using Otter;
using PpbbffttMiningHa.Utility;

namespace PpbbffttMiningHa.entities
{
    class Explosion : Entity
    {
        private Spritemap<string> _spriteMap;

        public Explosion(float x, float y, float scale, bool useInMenu = false)
        {
            X = x; Y = y;
            SetHitbox(100, 100, (int)Global.Type.EXPLOSION);
            Collider.X = -50;
            Collider.Y = -50;
            _spriteMap = new Spritemap<string>(Assets.EXPLOSION, 100, 100);
            _spriteMap.Add("main", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }, new float[] { 5f, 5f });
            _spriteMap.Scale = scale;
            _spriteMap.Play("main");
            _spriteMap.CenterOrigin();
            if (useInMenu)
                Layer = 2;
            Graphic = _spriteMap;
        }

        public override void Update()
        {
            base.Update();
            if (_spriteMap.CurrentAnim == "main" && _spriteMap.CurrentFrameIndex == 10)
            {
                var colb = Collider.Collide((int)X, (int)Y, Global.Type.ALLIGATOR);
                if (colb != null)
                {
                    SoundManager.PlayRequestedSound(RandomAlligatorSound());
                    Global.AlligatorHealth--;
                }
                var colpd = Collider.Collide((int)X, (int)Y, Global.Type.PRAIRIEDOG);
                if (colpd != null)
                {
                    SoundManager.PlayRequestedSound("_praireDogYip");
                    Global.PrairieDogHealth--;
                }
                var colg = Collider.Collide((int)X, (int)Y, Global.Type.GHOST);
                if (colg != null)
                {
                    SoundManager.PlayRequestedSound(RandomHurtSound());
                    Global.GhostHealth--;
                }
                Destroy();
            }
        }//end of update
        private string RandomHurtSound()
        {
            switch (Rand.Int(1, 7))//one more than the last
            {
                case 1:
                    return "_monsterYell";
                case 2:
                    return "_monsterYell2";
                case 3:
                    return "_monsterYell3";
                case 4:
                    return "_monsterYell4";
                case 5:
                    return "_monsterYell5";

                default:
                    return "_monsterYell";
            }
        }

        private string RandomAlligatorSound()
        {
            switch (Rand.Int(1, 12))//one more than the last
            {
                case 1:
                    return "_alligatorHurt";
                case 2:
                    return "_alligatorHurt2";
                case 3:
                    return "_alligatorHurt3";
                case 4:
                    return "_alligatorHurt4";
                case 5:
                    return "_alligatorHurt5";
                case 6:
                    return "_alligatorHurt6";
                case 7:
                    return "_alligatorHurt7";
                case 8:
                    return "_alligatorHurt8";
                case 9:
                    return "_alligatorHurt9";
                case 10:
                    return "_alligatorHurt10";
                case 11:
                    return "_alligatorHurt11";

                default:
                    return "_alligatorHurt";
            }
        }

        public override void Render()//mainly for testing colliders :D
        {
            base.Render();
            //Collider.Render();
        }

        public void Destroy()
        {
            RemoveSelf();
        }
    }
}


