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

namespace DarkWynter.Game.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;
    #endregion

    using DarkWynter.Engine.GameObjects;
    using DarkWynter.Engine.Init;
    using DarkWynter.Engine.Globals;



    /// <summary>
    /// User-Defined types can be added to the engine by inheriting from GameObjectTypes
    ///   and overloading it's CreateGameobjectType method.  This method must create a new
    ///   GameObject and assign it to the incoming GameObject.  Creation of the GameObject
    ///   by the overloaded User-Defined class should use a case statement to decide what 
    ///   kind of GameObject to create based on the Xml-based "type" parameter.
    /// </summary>
    public class UserDefinedTypes : GameObjectTypes
    {
    
        /// <summary>
        /// Create an GameObject using the "type" string included in the XmlNode.
        /// GameObject must be included in Engine, or added using GameObject override in Game.
        /// </summary>
        /// <param name="objectNode">Xml data describing the Gameobject.</param>
        /// <param name="gameObject">A blank GameObject to replace with User-Defined GameObject.</param>
        /// <returns>Returns true if GameObject was successfully created.</returns>
        public override bool CreateGameObjectType(ref GameObject gameObject)
        {
            
            // Get the Object Type
            string type = gameObject.load.node.LocalName;

            // Create the GameObject based on type
            switch (type)
            {

                case "Human":
                    gameObject = new Human(gameObject.load);
                    return true;
                case "Bot":
                    gameObject = new AI(gameObject.load);
                    return true;

                case "Prop":
                    gameObject = new Prop(gameObject.load);
                    return true;

                case "GpuObject":
                    gameObject = new GpuObject(gameObject.load);
                    return true;

                case "GameObject":
                    if (gameObject.load.node.Attributes["typeID"].Value == "Thought")
                    {
                        gameObject = new ThoughtsAI(gameObject.load);
                        return true;
                    } 
                        
                    if (gameObject.load.node.Attributes["typeID"].Value == "Sky")
                    {
                        gameObject = new SkySphere(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes["typeID"].Value == "Portal")
                    {
                        gameObject = new Portal(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes[0].Value == "WaterPlane")
                    {
                        gameObject = new WaterPlane(gameObject.load);
                        return true;
                    }

                    if (gameObject.load.node.Attributes["typeID"].Value == "TriggerPlane")
                    {
                        gameObject = new TriggerPlane(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes["typeID"].Value == "Bomb")
                    {
                        gameObject = new Bomb(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes["typeID"].Value == "Coins")
                    {
                        gameObject = new Coins(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes["typeID"].Value == "Arrows")
                    {
                        gameObject = new Arrows(gameObject.load);
                        return true;
                    }
                    if (gameObject.load.node.Attributes["typeID"].Value == "CubeOfCubes")
                    {
                        gameObject = new CubeOfCubes(gameObject.load);
                        return true;
                    }
 
                    break;

                default:
                    Console.WriteLine("Error Loading XML Object: " + type);
                    break;
            }
            return false;
        }
    }
}