using System;

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

        #region Declarations

        /// <summary>
        /// The health that this transition will set to the player
        /// </summary>
        private int iHealth;


        /// <summary>
        /// The index of the next stage to be displayed
        /// </summary>
        private int iNextStage;

        /// <summary>
        /// The x coordinate to place merc in the next stage
        /// </summary>
        private int iX;

        /// <summary>
        /// The y coordinate to place merc in the next stage
        /// </summary>
        private int iY;

        /// <summary>
        /// The x coord of the new place to center the stage
        /// </summary>
        private int iXviewCenter;
        

        /// <summary>
        /// The y coord of the new place to center the stage
        /// </summary>
        private int iYviewCenter;

        #endregion

        #region Construction

        /// <summary>
        /// Construction
        /// </summary>
		public CollisionBoxTransition()
		{
			this.Description = "Transition Obj";
		}

        #endregion

        #region Properties


        /// <summary>
        /// gets or sets the amount of health this transition gives the player
        /// </summary>
        public int Health
        {
            get { return this.iHealth; }
            set { this.iHealth = value; }
        }
        
        /// <summary>
        /// The index of the next level
        /// </summary>
        public int NextStage
        {
            get { return this.iNextStage; }
            set { this.iNextStage = value; }
        }

        /// <summary>
        /// X location of merc after transition
        /// </summary>
        public int X 
        {
            get { return this.iX; }
            set { this.iX = value; }
        }

        /// <summary>
        /// Y location of merc after transition
        /// </summary>
        public int Y
        {
            get { return this.iY; }
            set { this.iY = value; }
        }

        /// <summary>
        /// X location to set screen center to after transition
        /// </summary>
        public int XViewCenter
        {
            get { return this.iXviewCenter; }
            set { this.iXviewCenter = value; }
        }

        /// <summary>
        /// Y location to set screen center to after transition
        /// </summary>
        public int YViewCenter
        {
            get { return this.iYviewCenter; }
            set { this.iYviewCenter = value; }
        }

        #endregion

        #region Collision Override

        public override int handleRectCollision(PhysicsRectangle rect, PhysicsObject po)
        {
            
            if(po.GetType().Equals(typeof(Physics.PhysicsMerc)))
            {
                
                //Set the next stage to the current.
                Physics.PhysicsEngine.Instance.currentLevel.CurrentStageIndex = this.iNextStage;

                //Move Player to new actor list
                Physics.PhysicsEngine.Instance.currentLevel.CurrStage.actorList[Physics.PhysicsEngine.Instance.currentLevel.CurrStage.PlayerActorIndex] = (Physics.PhysicsMerc)po;

                //Set Player's location in the new stage.
                Physics.PhysicsEngine.Instance.currentLevel.CurrStage.actorList[Physics.PhysicsEngine.Instance.currentLevel.CurrStage.PlayerActorIndex].Location.x = this.X;
                Physics.PhysicsEngine.Instance.currentLevel.CurrStage.actorList[Physics.PhysicsEngine.Instance.currentLevel.CurrStage.PlayerActorIndex].Location.y = this.Y;
                //If a health value has been set, give it to player
                if(this.Health > 0)
                {
                    Physics.PhysicsEngine.Instance.currentLevel.CurrStage.actorList[Physics.PhysicsEngine.Instance.currentLevel.CurrStage.PlayerActorIndex].GameStats.Health = this.Health;
                }


                //Set new screen centering location
                if(this.iXviewCenter == 0 || this.iYviewCenter == 0)
                {
                    //Center on merc if center position not set
                    this.iXviewCenter = this.iX;
                    this.iYviewCenter = this.iY;
                }
                Physics.PhysicsEngine.Instance.currentLevel.CurrStage.ViewCenter.x = this.iXviewCenter;
                Physics.PhysicsEngine.Instance.currentLevel.CurrStage.ViewCenter.y = this.iYviewCenter;

            }
            //Do what ever we need... Nothing.
            return (int)PhysicsSettings.enumActions.DoNothing;

        }

        #endregion

    }	
}
