/// <summary>
        /// Compile Script -> Return Assembly
        /// </summary>
        public Assembly CompileScript(IRefObject ScriptObject, out CompilerResults Result)
        {
            String ClassName, PrefixName;
            switch (ScriptObject.Type)
            {
                case IRefObject.ScriptType.WEAPON:
                    ClassName = "ScriptWeapon";
                    PrefixName = "WeaponPrefix";
                    break;

                default:
                    ClassName = "ScriptLevelNpc";
                    PrefixName = "LevelNpcPrefix";
                    break;
            }

            // Setup our options
            CompilerParameters options = new CompilerParameters();
            options.GenerateExecutable = false;
            options.GenerateInMemory = true;
            options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
            options.ReferencedAssemblies.Add("System.dll");
            options.ReferencedAssemblies.Add("System.Core.dll");
            options.ReferencedAssemblies.Add("Microsoft.CSharp.dll");

            // Compile our code
            CSharpCodeProvider csProvider = new Microsoft.CSharp.CSharpCodeProvider();
            Result = csProvider.CompileAssemblyFromSource(options, "using CS_NPCServer; public class " + PrefixName + NextId[(int)ScriptObject.Type] + " : " + ClassName + " { public " + PrefixName + NextId[(int)ScriptObject.Type] + "(NPCServer Server, IRefObject Ref) : base(Server, Ref) { } " + ParseJoins(ScriptObject.Script) + " } ");
            NextId[(int)ScriptObject.Type]++;
            return (Result.Errors.HasErrors ? null : Result.CompiledAssembly);
        }
 /// <summary>
 /// Compile & Execute -> Script
 /// </summary>
 /// <returns></returns>
 public void Compile(IRefObject ScriptObj)
 {
     CompilerResults Results;
     Assembly Asm = CompileScript(ScriptObj, out Results);
     if (Asm != null)
         ScriptObj.ScriptObject = this.RunScript(ScriptObj, Asm);
     else
         HandleErrors((ScriptObj.Type == IRefObject.ScriptType.WEAPON ? "weapon" + ((ServerWeapon)ScriptObj).Name : "levelnpc" + ((GraalLevelNPC)ScriptObj).Id), Results);
 }
 public ScriptWeapon(Framework Server, IRefObject Ref)
     : base(Server)
 {
     this.Ref = (ServerWeapon)Ref;
 }
 /// <summary>
 /// Add to Compile List
 /// </summary>
 public void CompileAdd(IRefObject ScriptObj)
 {
     lock (CompileList)
         CompileList.Enqueue(ScriptObj);
 }
        /// <summary>
        /// Run Script -> Return Object
        /// </summary>
        public ScriptObj RunScript(IRefObject Reference, Assembly Script)
        {
            Type[] types = Script.GetTypes();
            foreach (Type type in types)
            {
                if (!type.IsSubclassOf(typeof(ScriptObj)))
                    continue;

                ConstructorInfo constructor = type.GetConstructor(new Type[] { typeof(Framework), typeof(IRefObject) });
                if (constructor != null && constructor.IsPublic)
                {
                    ScriptObj obj = (ScriptObj)constructor.Invoke(new object[] { Server, Reference });
                    return obj;
                }
            }

            // No object created, return null
            return null;
        }
 public ScriptLevelNpc(Framework Server, IRefObject Ref)
     : base(Server)
 {
     this.Ref = (GraalLevelNPC)Ref;
 }