using System;
using Icarus.Graphics.Animation;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for PhysicsGeek.
	/// </summary>
	public class PhysicsGeek : PhysicsPlayer
	{

        /// <summary>
        /// The collision box used when standing
        /// </summary>
        CollisionBoxEnemyDefault cbStanding;

        /// <summary>
        /// The collision box used when attacking
        /// </summary>
        CollisionBoxEnemyDefault cbAttacking;

		public PhysicsGeek()
		{
            //Default health
            this.GameStats.Health = 20;

            cbStanding = new CollisionBoxEnemyDefault();
            cbStanding.BoundingBox.X = 0;
            cbStanding.BoundingBox.Y = 0;
            cbStanding.BoundingBox.Width = 40;
            cbStanding.BoundingBox.Height = 180;
            cbStanding.BoundingBoxWidth = 40;
            cbStanding.BoundingBoxHeight = 180;
            cbStanding.Damage = 5;

            cbAttacking = new CollisionBoxEnemyDefault();
            cbAttacking.BoundingBox.X = 0;
            cbAttacking.BoundingBox.Y = 0;
            cbAttacking.BoundingBox.Width = 80;
            cbAttacking.BoundingBox.Height = 180;
            cbAttacking.BoundingBoxWidth = 80;
            cbAttacking.BoundingBoxHeight = 180;
            cbAttacking.Damage = 2;

            this.CollisionBox = cbStanding;
            this.CBXoffset = 20;

            this.ActionState = (int)PhysicsSettings.enumPlayerActionStates.StandingLeft;

            this.CBYoffset = this.CollisionBox.BoundingBoxHeight;
            this.po_gravity = PhysicsSettings.Instance.sv_mercGravity;
            this.SetAnimation(@"\geek\stand_left\stand_left.png", Icarus.Graphics.Animation.AnimationType.LoopForever, 1);
		}


        /// <summary>
        /// This guy makes specific special updates.
        /// For example, it changes animations depending on current states.
        /// </summary>
        public override int specificUpdates()
        {
            if(!this.Vulnerable)
            {
                this.InvulnerableIterationCount++;
                if(this.InvulnerableIterationCount > this.InvulnerableIterationLimit)
                {
                    this.Vulnerable = true;
                    this.InvulnerableIterationCount = 0;
                }
            }

            //check to see if we are dead
            if(this.GameStats.Health <= 0)
            {
                
                this.DeathIterationCount++;

                this.CollisionBox.Damage = 0;
                if(this.DeathIterationCount < this.DeathIterationLimit)
                {
                    //we are dead, stop all actions and flicker
                    this.stopAll();
                    if((this.DeathIterationCount/5)%2 == 0)//Swap animation every other frame
                    {
                        this.SetAnimation(@"\null\null_fset.png", Icarus.Graphics.Animation.AnimationType.LoopOnce, 1);
                    }
                    else if(this.ActionState == (int)Physics.PhysicsSettings.enumPlayerActionStates.StandingLeft)
                    {
                        this.SetAnimation(@"\geek\stand_left\stand_left.png", AnimationType.LoopOnce, 1);
                    }
                    else
                    {
                        this.SetAnimation(@"\geek\stand_right\stand_right.png", AnimationType.LoopForever, 1);
                    }
                }
                else
                {
                    //return remove
                    return (int)PhysicsSettings.enumActions.Remove;
                }

            }

            if(this.LastActionState != this.ActionState)
            {
                switch (this.ActionState)
                {
                        //TODO: Have the animations stored in the level or player type. ie: don't manually set
                    case (int)Physics.PhysicsSettings.enumPlayerActionStates.StandingLeft:
                        this.CollisionBox = cbStanding;
                        this.CBXoffset = 20;
                        this.SetAnimation(@"\geek\stand_left\stand_left.png",Icarus.Graphics.Animation.AnimationType.LoopForever, 1);
                        break;
                    case (int)Physics.PhysicsSettings.enumPlayerActionStates.StandingRight:
                        this.CollisionBox = cbStanding;
                        this.CBXoffset = 20;
                        this.SetAnimation(@"\geek\stand_right\stand_right.png",Icarus.Graphics.Animation.AnimationType.LoopForever, 1);
                        break;
                    case (int)Physics.PhysicsSettings.enumPlayerActionStates.WalkingLeft:
                        this.CollisionBox = cbAttacking;
                        this.CBXoffset = 40;
                        this.SetAnimation(@"\geek\walk_left\walk_left.png",Icarus.Graphics.Animation.AnimationType.LoopForever, 15);
                        break;
                    case (int)Physics.PhysicsSettings.enumPlayerActionStates.WalkingRight:
                        this.CollisionBox = cbAttacking;
                        this.CBXoffset = 40;
                        this.SetAnimation(@"\geek\walk_right\walk_right.png",Icarus.Graphics.Animation.AnimationType.LoopForever, 15);
                        break;
                }
                this.LastActionState = this.ActionState;
            }
            return (int)PhysicsSettings.enumActions.DoNothing;
        }


	}
}
