using System;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for CollisionBoxCD.
	/// </summary>
	public class CollisionBoxCD : CollisionBox
	{
        /// <summary>
        /// The spark that happens after a CD hits something
        /// </summary>
		private PhysicsShortLife pslHitSpark;

        public CollisionBoxCD()
		{
			this.Damage = 5;

            pslHitSpark = new PhysicsShortLife();
            pslHitSpark.FlickerTime = 0;
            pslHitSpark.IterationsToLive = 15;
            pslHitSpark.SetAnimation(@"\hit\hit.png", Icarus.Graphics.Animation.AnimationType.LoopOnce, 3);
		}

        /// <summary>
        /// Handles collisions for CDs
        /// </summary>
        /// <param name="rect">the cd bounding box</param>
        /// <param name="po">the po that the cd hit</param>
        /// <returns></returns>
        public override int handleRectCollision(PhysicsRectangle rect, PhysicsObject po)
        {
            if(po is PhysicsMerc || po is PhysicsShortLife) return (int)PhysicsSettings.enumActions.DoNothing;
            
            //Special case for fighting tux robot
            if(po is PhysicsTuxHead)
            {
                PhysicsTuxRobot tux = (PhysicsTuxRobot)(((ChildObject)po).Parent);
                if(tux.Vulnerable)
                {
                    tux.GameStats.Health -= this.Damage;
                    tux.Vulnerable = false;
                }
            }

            if(po is PhysicsPlayer)
            {
                if(((PhysicsPlayer)po).Vulnerable)
                {
                    //Damage code
                    ((PhysicsPlayer)po).GameStats.Health -= this.Damage;
                    ((PhysicsPlayer)po).Vulnerable = false;
                }
            }

            //Add spark then tell physics engine to remove CD object
            int i;
            for(i = 0; i < Logic.GameEngine.GameSettings.Instance.sv_maxActors; i++)
            {
                if(PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i] == null) break;
            }
            //is there room?
            if((Logic.GameEngine.GameSettings.Instance.sv_maxActors - 1) > i)
            {
                Vector vec = new Vector();
                vec.j = 0;
                pslHitSpark.po_gravity = vec;
                pslHitSpark.Location.x = rect.X;
                pslHitSpark.Location.y = rect.Y;
                pslHitSpark.IterationCount = 0;
                pslHitSpark.SetAnimation(@"\hit\hit.png", Icarus.Graphics.Animation.AnimationType.LoopOnce, 3);
                PhysicsEngine.Instance.currentLevel.CurrStage.actorList[i] = pslHitSpark;
            }

            return (int)PhysicsSettings.enumActions.Remove;

        }



	}
}
