//---------------------------------------------------------------------------------------------------------------------------------------------------
// <copyright file="Player.cs" company="DarkWynter Studios">
//     Copyright (C)2007 DarkWynter Studios.  All rights reserved.
// </copyright>
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------

namespace DarkWynter.Engine.GameObjects
{
    #region Using Statements
    using System;
    using System.Collections.Generic;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Storage;
    using System.Xml;
    using System.Diagnostics;
    using System.Threading;
    using DarkWynter.Engine;
    using DarkWynter.Engine.Globals;
    using DarkWynter.Engine.ObjectLib;
    using DarkWynter.Engine.GameObjects;
    using DarkWynter.Engine.Controllers;
    using DarkWynter.Engine.UserInterface;
    using DarkWynter.Stream;
    using DarkWynter.Engine.Init;
    using Xclna.Xna.Animation;
    using DarkWynter.Engine.EventControl;
    #endregion

    public class ThoughtsAI : AI
    {

        /// <summary>
        /// Constructor
        /// </summary>
        /// 
        public Vector3 whereAreYou = new Vector3();
        public Vector3 destination =  new Vector3();

        public bool destinationReached = false;

        public Vector3 setDestinationFromEvent
        {
            get { return destination; }
            set { destination = value; }
        }


        public ThoughtsAI(Load gameObjectLoader)
            : base(gameObjectLoader)
        {
            this.mass.movementType = Enums_Engine.MovementType.WALK;
            this.mass.SetPosition(new Vector3(1243, 22, 857), Vector3.Zero);
            
        }

        public override void Update(ref ObjectLibrary objectLibrary)
        {
            // ********************************************* HACK ************************************************//
            //                   The AI is still not getting the position from the XML properly                   //
            // ********************************************* HACK ************************************************//

            if (this.mass.currentPosition == new Vector3 (1, 22, 1))
            {
                this.mass.SetPosition(new Vector3(1253, 22, 857), Vector3.Zero);
            }

            if (destination != null && destination != Vector3.Zero)
            {
               // destinationReached = false;
                if (!destinationReached)
                {
                    mass.AddForce(new Vector3(20, 0, 20));
                    Vector3 diff = goToDestination(destination);
                    if (diff.Length() < 50)
                    {
                        destinationReached = true;
                    }
                }
            }


            // If dead they can't update
            if (IsAlive() == false)
            {
                return;
            }

            // Reset all controller inputs
            //DarkWynterGame.playerController.gameInput.init();

            // Turn terrain mod back off
            terrainModEnabled = false;

            // Fuzzy state machine
            // * <- means smarter choice

            // Update percepts
            // UpdatePercepts(objectLibrary);

            UpdateState(objectLibrary);

            //attackAmount = shootAmount + defendAmount;

            Statics_Engine.PlayerSettings.whereAreYou = mass.currentPosition;

            base.Update(ref objectLibrary);
            //}
        }

        public override bool ObjectCollisionResponse(GameObject collidedObject, Vector3 resultantForce, ObjectLibrary objectLibrary)
        {
            if (collidedObject is Arrows)
            {


                Arrows arrow = collidedObject as Arrows;

                GameEventHandler.CurrentGameConditions.lastNodeVisited = arrow.arrowID;
               // GameEventHandler.spawnPosition = arrow.mass.currentPosition;
                GameEventHandler.UpdateEvents();


            }

            return base.ObjectCollisionResponse(collidedObject, resultantForce, objectLibrary);
        }

        public override void Draw_Billboards(ObjectLibrary objectLibrary, BillboardList gameObjectBillboards)
        {
            base.Draw_Billboards(objectLibrary, gameObjectBillboards);

            Texture2D billboardImage = Statics_Engine.SystemSettings.content.Load<Texture2D>("Content/_textures/bomb1");

            List<Billboard> billboards = new List<Billboard>();

            Vector3 offset = mass.currentPosition;
            //offset.Y += 50;

            Billboard billboard = new Billboard(null);
            billboard.Load(mass.currentPosition + offset, Vector3.Zero, 50.0f, 50.0f, draw.textureList[0]);

            //billboard.Load(mass.currentPosition + offset, Vector3.Zero, 15.0f, 15.0f, Engine.DarkWynterEngine.video.CurrentTexture);

            billboards.Add(billboard);


            // Add a billboard texture above the particle
            gameObjectBillboards.AddRange(billboards);



        }



    }
}