using System;
using System.Xml.Serialization;

namespace Icarus.Logic.Physics
{
	/// <summary>
	/// Summary description for CollisionBoxWhip.
	/// </summary>
	public class CollisionBoxWhip : CollisionBox
	{
		/// <summary>
		/// whether or not to show spark on whip
		/// </summary>
        private bool bShowSpark;

        /// <summary>
        /// This particular box needs to know things about the world obj holding it
        /// </summary>
        private WorldObject wo;
        
        /// <summary>
        /// Allowing the world obj to set a ref to itself
        /// </summary>
        [XmlIgnore]
        public WorldObject WO
        {
            set { this.wo = value;}
        }

        /// <summary>
        /// Gets or sets whether a spark should be shown or not
        /// </summary>
        public bool ShowSpark
        {
            get { return this.bShowSpark; }
            set { this.bShowSpark = value;}
        }

        public CollisionBoxWhip()
		{
            //Amound of Damage the whip does
			this.Damage = 10;
            this.bShowSpark = false;
   		}

        /// <summary>
        /// Handles collisions with a whip
        /// </summary>
        /// <param name="rect">Rect that is being collided with</param>
        /// <param name="po">PO to be affected</param>
        /// <returns></returns>
        public override int handleRectCollision(PhysicsRectangle rect, PhysicsObject po)
        {
            //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;
                    this.ShowSpark = true;
                }
                return (int)Icarus.Logic.Physics.PhysicsSettings.enumActions.DoNothing;
            }

            //Is it a Player?
            if(po is PhysicsPlayer)
            {
                //Can we hurt it?
                if(((PhysicsPlayer)po).Vulnerable)
                {
                    //Pow
                    ((WorldObject)po).GameStats.Health -= this.Damage;

                    //Give it a rest for a bit
                    ((PhysicsPlayer)po).Vulnerable = false;
                    this.ShowSpark = true;
                }
            }

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

	}
}
