using System;

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

        /// <summary>
        /// The direction to throw merc on collision
        /// Defined in PhysicsSetting.enumDirection
        /// Left
        /// Right
        /// Center - throws left or right, which ever is closer
        /// </summary>
        private int iThrowDirection;

        /// <summary>
        /// Contructor
        /// </summary>
        public CollisionBoxEnemyDefault()
		{
			iThrowDirection = (int)PhysicsSettings.enumDirection.Center;
		}

        /// <summary>
        /// Gets or sets the direction this collision box throws merc
        /// </summary>
        public int ThrowDirection
        {
            get { return this.iThrowDirection; }
            set { this.iThrowDirection = value; }
        }

        /// <summary>
        /// Handles collisions with all types of objects and enemy default.
        /// </summary>
        /// <param name="rect">colliding rectangle</param>
        /// <param name="po">po to be affected</param>
        /// <returns></returns>
        public override int handleRectCollision(PhysicsRectangle rect, PhysicsObject po)
        {
            //TODO: Do Damage if needed


            //Is it merc?
            if(po is PhysicsMerc)
            {
                
                //Do Damage to merc
                ((WorldObject)po).GameStats.Health -= this.Damage;
                ((PhysicsMerc)po).Vulnerable = false;

                po.Velocity.j = .35f * PhysicsSettings.Instance.JumpVelocity;
                
                switch (this.iThrowDirection)
                {
                    case (int)PhysicsSettings.enumDirection.Center:
                        //Knock player back
                        
                        if(rect.X > po.CollisionBox.BoundingBox.X)
                        {
                            //Move away from collision
                            po.Location.x = rect.X - po.CollisionBox.BoundingBoxWidth;
                    
                            //set velocity
                            po.Velocity.i = .4f * PhysicsSettings.Instance.JumpVelocity;

                            po.LastActionState = po.ActionState;
                            po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.JumpingLeft;
                        }
                        else
                        {
                            //Move away from collision
                            po.Location.x = rect.X + rect.Width + po.CBXoffset;

                            //set velocity
                            po.Velocity.i = -.4f * PhysicsSettings.Instance.JumpVelocity;

                            po.LastActionState = po.ActionState;
                            po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.JumpingRight;
                        }
                        break;
                    case (int)PhysicsSettings.enumDirection.Left:
                        //Move away from collision
                        po.Location.x = rect.X - po.CollisionBox.BoundingBoxWidth;
                
                        //set velocity
                        po.Velocity.i = .4f * PhysicsSettings.Instance.JumpVelocity;

                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.JumpingLeft;

                        break;
                    case (int)PhysicsSettings.enumDirection.Right:
                        //Move away from collision
                        po.Location.x = rect.X + rect.Width + po.CBXoffset;

                        //set velocity
                        po.Velocity.i = -.4f * PhysicsSettings.Instance.JumpVelocity;

                        po.LastActionState = po.ActionState;
                        po.ActionState = (int)PhysicsSettings.enumPlayerActionStates.JumpingRight;
                        
                        break;

                }
            }

            return (int)Icarus.Logic.Physics.PhysicsSettings.enumActions.DoNothing;
        }


	}
}
