FindTypeByFullName() public static méthode

public static FindTypeByFullName ( string fullName ) : Type
fullName string
Résultat System.Type
        public static Type ReadType(this GenericReader reader)
        {
            if (!reader.ReadBool())
            {
                return(null);
            }

            bool   full = reader.ReadBool();
            string name = reader.ReadString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            Type type = Type.GetType(name, false) ??
                        (full ? ScriptCompiler.FindTypeByFullName(name) : ScriptCompiler.FindTypeByName(name));

            return(type);
        }
Exemple #2
0
        private static EntityType[] LoadTypes(BinaryReader tdbReader)
        {
            int count = tdbReader.ReadInt32();

            Type[] ctorTypes = new Type[1] {
                typeof(Serial)
            };

            EntityType[] types = new EntityType[count];

            for (int i = 0; i < count; ++i)
            {
                string typeName = tdbReader.ReadString();
                if (typeName == null || typeName == "")
                {
                    continue;
                }

                Type t = ScriptCompiler.FindTypeByFullName(typeName);

                if (t == null)
                {
                    log.ErrorFormat("Type '{0}' was not found. All entities referring to it will be deleted.",
                                    typeName);
                    continue;
                }

                ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                if (ctor == null)
                {
                    log.ErrorFormat("Type '{0}' does not have a serialization constructor. All entities referring to it will be deleted.",
                                    typeName);
                    continue;
                }

                types[i] = new EntityType(typeName, ctor);
            }

            return(types);
        }
Exemple #3
0
        public static Type ReadType(this GenericReader reader)
        {
            if (!reader.ReadBool())
            {
                return(null);
            }

            // Peek preamble for upgrade support
            if (reader.PeekInt() == 0x0C0FFEE0 && reader.ReadInt() == 0x0C0FFEE0)
            {
                return(_Types.GetValue(reader.ReadInt()));
            }

            var full = reader.ReadBool();
            var name = reader.ReadString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            return(Type.GetType(name, false) ??
                   (full ? ScriptCompiler.FindTypeByFullName(name) : ScriptCompiler.FindTypeByName(name)));
        }
Exemple #4
0
        public static void Load()
        {
            if (m_Loaded)
            {
                return;
            }

            m_Loaded      = true;
            m_LoadingType = null;

            Console.Write("World: Loading...");

            Stopwatch watch = Stopwatch.StartNew();

            m_Loading = true;

            _addQueue    = new Queue <IEntity>();
            _deleteQueue = new Queue <IEntity>();

            int mobileCount = 0, itemCount = 0, guildCount = 0;

            object[] ctorArgs  = new object[1];
            Type[]   ctorTypes = new Type[1] {
                typeof(Serial)
            };

            List <ItemEntry>   items   = new List <ItemEntry>();
            List <MobileEntry> mobiles = new List <MobileEntry>();
            List <GuildEntry>  guilds  = new List <GuildEntry>();

            if (File.Exists(MobileIndexPath) && File.Exists(MobileTypesPath))
            {
                using (FileStream idx = new FileStream(MobileIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(MobileTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, null });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        mobileCount = idxReader.ReadInt32();

                        m_Mobiles = new Dictionary <Serial, Mobile>(mobileCount);

                        for (int i = 0; i < mobileCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = ( object[] )types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Mobile          m        = null;
                            ConstructorInfo ctor     = ( ConstructorInfo )objs[0];
                            string          typeName = ( string )objs[1];

                            try {
                                ctorArgs[0] = ( Serial )serial;
                                m           = ( Mobile )(ctor.Invoke(ctorArgs));
                            } catch {
                            }

                            if (m != null)
                            {
                                mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length));
                                AddMobile(m);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Mobiles = new Dictionary <Serial, Mobile>();
            }

            if (File.Exists(ItemIndexPath) && File.Exists(ItemTypesPath))
            {
                using (FileStream idx = new FileStream(ItemIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(ItemTypesPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, typeName });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        itemCount = idxReader.ReadInt32();

                        m_Items = new Dictionary <Serial, Item>(itemCount);

                        for (int i = 0; i < itemCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = ( object[] )types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Item            item     = null;
                            ConstructorInfo ctor     = ( ConstructorInfo )objs[0];
                            string          typeName = ( string )objs[1];

                            try {
                                ctorArgs[0] = ( Serial )serial;
                                item        = ( Item )(ctor.Invoke(ctorArgs));
                            } catch {
                            }

                            if (item != null)
                            {
                                items.Add(new ItemEntry(item, typeID, typeName, pos, length));
                                AddItem(item);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Items = new Dictionary <Serial, Item>();
            }

            if (File.Exists(GuildIndexPath))
            {
                using (FileStream idx = new FileStream(GuildIndexPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryReader idxReader = new BinaryReader(idx);

                    guildCount = idxReader.ReadInt32();

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < guildCount; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);
                        if (guild != null)
                        {
                            guilds.Add(new GuildEntry(guild, pos, length));
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(MobileDataPath))
            {
                using (FileStream bin = new FileStream(MobileDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobiles.Count; ++i)
                    {
                        MobileEntry entry = mobiles[i];
                        Mobile      m     = entry.Mobile;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            } catch (Exception e) {
                                mobiles.RemoveAt(i);

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && File.Exists(ItemDataPath))
            {
                using (FileStream bin = new FileStream(ItemDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < items.Count; ++i)
                    {
                        ItemEntry entry = items[i];
                        Item      item  = entry.Item;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            } catch (Exception e) {
                                items.RemoveAt(i);

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            m_LoadingType = null;

            if (!failedMobiles && !failedItems && File.Exists(GuildDataPath))
            {
                using (FileStream bin = new FileStream(GuildDataPath, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guilds.Count; ++i)
                    {
                        GuildEntry entry = guilds[i];
                        BaseGuild  g     = entry.Guild;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            } catch (Exception e) {
                                guilds.RemoveAt(i);

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (failedItems || failedMobiles || failedGuilds)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                {
                    if (failedType != typeof(BaseGuild))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadKey(true).Key == ConsoleKey.Y)
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobiles.Count;)
                                {
                                    if (mobiles[i].TypeID == failedTypeID)
                                    {
                                        mobiles.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < items.Count;)
                                {
                                    if (items[i].TypeID == failedTypeID)
                                    {
                                        items.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                        }
                    }

                    SaveIndex <MobileEntry>(mobiles, MobileIndexPath);
                    SaveIndex <ItemEntry>(items, ItemIndexPath);
                    SaveIndex <GuildEntry>(guilds, GuildIndexPath);
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, type={3}, serial={4})", failedItems, failedMobiles, failedGuilds, failedType, failedSerial), failed);
            }

            EventSink.InvokeWorldLoad();

            m_Loading = false;

            ProcessSafetyQueues();

            foreach (Item item in m_Items.Values)
            {
                if (item.Parent == null)
                {
                    item.UpdateTotals();
                }

                item.ClearProperties();
            }

            foreach (Mobile m in m_Mobiles.Values)
            {
                m.UpdateRegion();                 // Is this really needed?
                m.UpdateTotals();

                m.ClearProperties();
            }

            watch.Stop();

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, m_Items.Count, m_Mobiles.Count);

            // Genova: remover personagens não confirmados.
            ControladorODBC.ODBCRemoverPersonagensNaoConfirmados();
        }
        public static void Load()
        {
            BinaryReader    reader1;
            BinaryReader    reader2;
            int             num5;
            ArrayList       list5;
            int             num6;
            string          text1;
            Type            type1;
            ConstructorInfo info1;
            int             num7;
            int             num8;
            int             num9;
            long            num10;
            int             num11;

            object[]        objArray2;
            Mobile          mobile1;
            ConstructorInfo info2;
            string          text2;
            BinaryReader    reader3;
            BinaryReader    reader4;
            int             num12;
            ArrayList       list6;
            int             num13;
            string          text3;
            Type            type2;
            ConstructorInfo info3;
            int             num14;
            int             num15;
            int             num16;
            long            num17;
            int             num18;

            object[]             objArray3;
            Item                 item1;
            ConstructorInfo      info4;
            string               text4;
            BinaryReader         reader5;
            CreateGuildEventArgs args1;
            int              num19;
            int              num20;
            long             num21;
            int              num22;
            BaseGuild        guild1;
            BinaryReader     reader6;
            int              num23;
            int              num24;
            long             num25;
            int              num26;
            Region           region1;
            BinaryFileReader reader7;
            int              num28;
            MobileEntry      entry1;
            Mobile           mobile2;
            BinaryFileReader reader8;
            int              num29;
            ItemEntry        entry2;
            Item             item2;
            BinaryFileReader reader9;
            int              num30;
            GuildEntry       entry3;
            BaseGuild        guild2;
            BinaryFileReader reader10;
            int              num31;
            RegionEntry      entry4;
            Region           region2;
            int              num32;
            int              num33;
            int              num34;
            object           obj1;

            object[] objArray4;
            if (World.m_Loaded)
            {
                return;
            }
            World.m_Loaded      = true;
            World.m_LoadingType = null;
            Console.Write("World: Loading...");
            DateTime time1 = DateTime.Now;

            World.m_Loading    = true;
            World.m_DeleteList = new ArrayList();
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = 0;

            object[] objArray1  = new object[1];
            Type[]   typeArray2 = new Type[1];
            typeArray2[0] = typeof(Serial);
            Type[]    typeArray1 = typeArray2;
            ArrayList list1      = new ArrayList();
            ArrayList list2      = new ArrayList();
            ArrayList list3      = new ArrayList();
            ArrayList list4      = new ArrayList();

            if (File.Exists(World.mobIdxPath) && File.Exists(World.mobTdbPath))
            {
                using (FileStream stream1 = new FileStream(World.mobIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader1 = new BinaryReader(stream1);
                    using (FileStream stream2 = new FileStream(World.mobTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        reader2 = new BinaryReader(stream2);
                        num5    = reader2.ReadInt32();
                        list5   = new ArrayList(num5);
                        num6    = 0;
                        while ((num6 < num5))
                        {
                            text1 = reader2.ReadString();
                            type1 = ScriptCompiler.FindTypeByFullName(text1);
                            if (type1 == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type \'{0}\' was not found. Delete all of those types? (y/n)", text1);
                                if (Console.ReadLine() == "y")
                                {
                                    list5.Add(null);
                                    Console.Write("World: Loading...");
                                    goto Label_018C;
                                }
                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");
                                throw new Exception(string.Format("Bad type \'{0}\'", text1));
                            }
                            info1 = type1.GetConstructor(typeArray1);
                            if (info1 != null)
                            {
                                objArray4    = new object[2];
                                objArray4[0] = info1;
                                list5.Add(objArray4);
                            }
                            else
                            {
                                throw new Exception(string.Format("Type \'{0}\' does not have a serialization constructor", type1));
                            }
Label_018C:
                            ++num6;
                        }
                        num1            = reader1.ReadInt32();
                        World.m_Mobiles = new Hashtable(num1);
                        for (num7 = 0; (num7 < num1); ++num7)
                        {
                            num8      = reader1.ReadInt32();
                            num9      = reader1.ReadInt32();
                            num10     = reader1.ReadInt64();
                            num11     = reader1.ReadInt32();
                            objArray2 = ((object[])list5[num8]);
                            if (objArray2 != null)
                            {
                                mobile1 = null;
                                info2   = ((ConstructorInfo)objArray2[0]);
                                text2   = ((string)objArray2[1]);
                                try
                                {
                                    objArray1[0] = Serial.op_Implicit(num9);
                                    mobile1      = ((Mobile)info2.Invoke(objArray1));
                                }
                                catch
                                {
                                }
                                if (mobile1 != null)
                                {
                                    list2.Add(new MobileEntry(mobile1, num8, text2, num10, num11));
                                    World.AddMobile(mobile1);
                                }
                            }
                        }
                        goto Label_0282;
                    }
                    goto Label_0282;
                }
            }
            World.m_Mobiles = new Hashtable();
Label_0282:
            if (File.Exists(World.itemIdxPath) && File.Exists(World.itemTdbPath))
            {
                using (FileStream stream3 = new FileStream(World.itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader3 = new BinaryReader(stream3);
                    using (FileStream stream4 = new FileStream(World.itemTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        reader4 = new BinaryReader(stream4);
                        num12   = reader4.ReadInt32();
                        list6   = new ArrayList(num12);
                        num13   = 0;
                        while ((num13 < num12))
                        {
                            text3 = reader4.ReadString();
                            type2 = ScriptCompiler.FindTypeByFullName(text3);
                            if (type2 == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type \'{0}\' was not found. Delete all of those types? (y/n)", text3);
                                if (Console.ReadLine() == "y")
                                {
                                    list6.Add(null);
                                    Console.Write("World: Loading...");
                                    goto Label_0399;
                                }
                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");
                                throw new Exception(string.Format("Bad type \'{0}\'", text3));
                            }
                            info3 = type2.GetConstructor(typeArray1);
                            if (info3 != null)
                            {
                                objArray4    = new object[2];
                                objArray4[0] = info3;
                                objArray4[1] = text3;
                                list6.Add(objArray4);
                            }
                            else
                            {
                                throw new Exception(string.Format("Type \'{0}\' does not have a serialization constructor", type2));
                            }
Label_0399:
                            ++num13;
                        }
                        num2          = reader3.ReadInt32();
                        World.m_Items = new Hashtable(num2);
                        for (num14 = 0; (num14 < num2); ++num14)
                        {
                            num15     = reader3.ReadInt32();
                            num16     = reader3.ReadInt32();
                            num17     = reader3.ReadInt64();
                            num18     = reader3.ReadInt32();
                            objArray3 = ((object[])list6[num15]);
                            if (objArray3 != null)
                            {
                                item1 = null;
                                info4 = ((ConstructorInfo)objArray3[0]);
                                text4 = ((string)objArray3[1]);
                                try
                                {
                                    objArray1[0] = Serial.op_Implicit(num16);
                                    item1        = ((Item)info4.Invoke(objArray1));
                                }
                                catch
                                {
                                }
                                if (item1 != null)
                                {
                                    list1.Add(new ItemEntry(item1, num15, text4, num17, num18));
                                    World.AddItem(item1);
                                }
                            }
                        }
                        goto Label_048F;
                    }
                    goto Label_048F;
                }
            }
            World.m_Items = new Hashtable();
Label_048F:
            if (File.Exists(World.guildIdxPath))
            {
                using (FileStream stream5 = new FileStream(World.guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader5 = new BinaryReader(stream5);
                    num3    = reader5.ReadInt32();
                    args1   = new CreateGuildEventArgs(-1);
                    for (num19 = 0; (num19 < num3); ++num19)
                    {
                        reader5.ReadInt32();
                        num20    = reader5.ReadInt32();
                        num21    = reader5.ReadInt64();
                        num22    = reader5.ReadInt32();
                        args1.Id = num20;
                        guild1   = EventSink.InvokeCreateGuild(args1);
                        if (guild1 != null)
                        {
                            list3.Add(new GuildEntry(guild1, num21, num22));
                        }
                    }
                }
            }
            if (File.Exists(World.regionIdxPath))
            {
                using (FileStream stream6 = new FileStream(World.regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader6 = new BinaryReader(stream6);
                    num4    = reader6.ReadInt32();
                    for (num23 = 0; (num23 < num4); ++num23)
                    {
                        reader6.ReadInt32();
                        num24   = reader6.ReadInt32();
                        num25   = reader6.ReadInt64();
                        num26   = reader6.ReadInt32();
                        region1 = Region.FindByUId(num24);
                        if (region1 != null)
                        {
                            list4.Add(new RegionEntry(region1, num25, num26));
                            Region.AddRegion(region1);
                            ++num4;
                        }
                    }
                }
            }
            bool      flag1      = false;
            bool      flag2      = false;
            bool      flag3      = false;
            bool      flag4      = false;
            Type      type3      = null;
            Serial    serial1    = Serial.Zero;
            Exception exception1 = null;
            int       num27      = 0;

            if (File.Exists(World.mobBinPath))
            {
                using (FileStream stream7 = new FileStream(World.mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader7 = new BinaryFileReader(new BinaryReader(stream7));
                    for (num28 = 0; (num28 < list2.Count); ++num28)
                    {
                        entry1  = ((MobileEntry)list2[num28]);
                        mobile2 = ((Mobile)entry1.Object);
                        if (mobile2 != null)
                        {
                            reader7.Seek(entry1.Position, SeekOrigin.Begin);
                            try
                            {
                                World.m_LoadingType = entry1.TypeName;
                                mobile2.Deserialize(reader7);
                                if (reader7.Position != (entry1.Position + entry1.Length))
                                {
                                    throw new Exception(string.Format("***** Bad serialize on {0} *****", mobile2.GetType()));
                                }
                            }
                            catch (Exception exception2)
                            {
                                list2.RemoveAt(num28);
                                exception1 = exception2;
                                flag1      = true;
                                type3      = mobile2.GetType();
                                num27      = entry1.TypeID;
                                serial1    = mobile2.Serial;
                                goto Label_06F2;
                            }
                        }
                    }
                }
            }
Label_06F2:
            if (!flag1 && File.Exists(World.itemBinPath))
            {
                using (FileStream stream8 = new FileStream(World.itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader8 = new BinaryFileReader(new BinaryReader(stream8));
                    for (num29 = 0; (num29 < list1.Count); ++num29)
                    {
                        entry2 = ((ItemEntry)list1[num29]);
                        item2  = ((Item)entry2.Object);
                        if (item2 != null)
                        {
                            reader8.Seek(entry2.Position, SeekOrigin.Begin);
                            try
                            {
                                World.m_LoadingType = entry2.TypeName;
                                item2.Deserialize(reader8);
                                if (reader8.Position != (entry2.Position + entry2.Length))
                                {
                                    throw new Exception(string.Format("***** Bad serialize on {0} *****", item2.GetType()));
                                }
                            }
                            catch (Exception exception3)
                            {
                                list1.RemoveAt(num29);
                                exception1 = exception3;
                                flag2      = true;
                                type3      = item2.GetType();
                                num27      = entry2.TypeID;
                                serial1    = item2.Serial;
                                goto Label_07FA;
                            }
                        }
                    }
                }
            }
Label_07FA:
            World.m_LoadingType = null;
            if ((!flag1 && !flag2) && File.Exists(World.guildBinPath))
            {
                using (FileStream stream9 = new FileStream(World.guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader9 = new BinaryFileReader(new BinaryReader(stream9));
                    for (num30 = 0; (num30 < list3.Count); ++num30)
                    {
                        entry3 = ((GuildEntry)list3[num30]);
                        guild2 = ((BaseGuild)entry3.Object);
                        if (guild2 != null)
                        {
                            reader9.Seek(entry3.Position, SeekOrigin.Begin);
                            try
                            {
                                guild2.Deserialize(reader9);
                                if (reader9.Position != (entry3.Position + entry3.Length))
                                {
                                    throw new Exception(string.Format("***** Bad serialize on Guild {0} *****", guild2.Id));
                                }
                            }
                            catch (Exception exception4)
                            {
                                list3.RemoveAt(num30);
                                exception1 = exception4;
                                flag3      = true;
                                type3      = typeof(BaseGuild);
                                num27      = guild2.Id;
                                serial1    = Serial.op_Implicit(guild2.Id);
                                goto Label_0910;
                            }
                        }
                    }
                }
            }
Label_0910:
            if ((!flag1 && !flag2) && File.Exists(World.regionBinPath))
            {
                using (FileStream stream10 = new FileStream(World.regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    reader10 = new BinaryFileReader(new BinaryReader(stream10));
                    for (num31 = 0; (num31 < list4.Count); ++num31)
                    {
                        entry4  = ((RegionEntry)list4[num31]);
                        region2 = ((Region)entry4.Object);
                        if (region2 != null)
                        {
                            reader10.Seek(entry4.Position, SeekOrigin.Begin);
                            try
                            {
                                region2.Deserialize(reader10);
                                if (reader10.Position != (entry4.Position + entry4.Length))
                                {
                                    throw new Exception(string.Format("***** Bad serialize on {0} *****", region2.GetType()));
                                }
                            }
                            catch (Exception exception5)
                            {
                                list4.RemoveAt(num31);
                                exception1 = exception5;
                                flag4      = true;
                                type3      = region2.GetType();
                                num27      = entry4.TypeID;
                                serial1    = Serial.op_Implicit(region2.UId);
                                goto Label_0A1B;
                            }
                        }
                    }
                }
            }
Label_0A1B:
            if ((flag2 || flag1) || (flag3 || flag4))
            {
                Console.WriteLine("An error was encountered while loading a saved object");
                Console.WriteLine(" - Type: {0}", type3);
                Console.WriteLine(" - Serial: {0}", serial1);
                Console.WriteLine("Delete the object? (y/n)");
                if (Console.ReadLine() == "y")
                {
                    if ((type3 != typeof(BaseGuild)) && !type3.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");
                        if (Console.ReadLine() == "y")
                        {
                            if (flag1)
                            {
                                for (num32 = 0; (num32 < list2.Count); ++num32)
                                {
                                    if (((MobileEntry)list2[num32]).TypeID == num27)
                                    {
                                        list2.RemoveAt(num32);
                                        continue;
                                    }
                                }
                            }
                            else if (flag2)
                            {
                                for (num33 = 0; (num33 < list1.Count); ++num33)
                                {
                                    if (((ItemEntry)list1[num33]).TypeID == num27)
                                    {
                                        list1.RemoveAt(num33);
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                    World.SaveIndex(list2, World.mobIdxPath);
                    World.SaveIndex(list1, World.itemIdxPath);
                    World.SaveIndex(list3, World.guildIdxPath);
                    World.SaveIndex(list4, World.regionIdxPath);
                }
                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();
                objArray4    = new object[6];
                objArray4[0] = flag2;
                objArray4[1] = flag1;
                objArray4[2] = flag3;
                objArray4[3] = flag4;
                objArray4[4] = type3;
                objArray4[5] = serial1;
                throw new Exception(string.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", objArray4), exception1);
            }
            EventSink.InvokeWorldLoad();
            World.m_Loading = false;
            for (num34 = 0; (num34 < World.m_DeleteList.Count); ++num34)
            {
                obj1 = World.m_DeleteList[num34];
                if ((obj1 is Item))
                {
                    ((Item)obj1).Delete();
                }
                else if ((obj1 is Mobile))
                {
                    ((Mobile)obj1).Delete();
                }
            }
            foreach (Item item3 in World.m_Items.Values)
            {
                if (item3.Parent == null)
                {
                    item3.UpdateTotals();
                }
            }
            ArrayList list7 = new ArrayList(World.m_Mobiles.Values);

            foreach (Mobile mobile3 in list7)
            {
                mobile3.ForceRegionReEnter(true);
                mobile3.UpdateTotals();
            }
            TimeSpan span1 = ((TimeSpan)(DateTime.Now - time1));

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F1} seconds)", span1.TotalSeconds, World.m_Items.Count, World.m_Mobiles.Count);
        }
Exemple #6
0
        public static void LoadItems()
        {
            Console.Write("Start Loading items...");

            string filePath = "itemstosave.xml";

            if (!File.Exists(filePath))
            {
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(filePath);

            XmlElement root = doc["items"];

            foreach (XmlElement node in root.GetElementsByTagName("item"))
            {
                string itemstring = Utility.GetText(node["type"], null);
                if (!String.IsNullOrEmpty(itemstring))
                {
                    Type itemtype = ScriptCompiler.FindTypeByFullName(itemstring, true);

                    if (itemtype != null)
                    {
                        Item item = Activator.CreateInstance(itemtype) as Item;

                        if (item != null)
                        {
                            item.ItemID  = Utility.GetXMLInt32(Utility.GetText(node["itemid"], "0"), 0);
                            item.Hue     = Utility.GetXMLInt32(Utility.GetText(node["hue"], "0"), 0);
                            item.Movable = false;

                            int x   = Utility.GetXMLInt32(Utility.GetAttribute(node, "x"), 0);
                            int y   = Utility.GetXMLInt32(Utility.GetAttribute(node, "y"), 0);
                            int z   = Utility.GetXMLInt32(Utility.GetAttribute(node, "z"), 0);
                            Map map = Map.Parse(Utility.GetAttribute(node, "map"));

                            item.MoveToWorld(new Point3D(x, y, z), map);

                            if (item is FillableContainer)
                            {
                                ((FillableContainer)item).ContentType = (FillableContentType)Utility.GetXMLInt32(Utility.GetText(node["contenttype"], "0"), 0);
                            }

                            if (item is LockableContainer)
                            {
                                LockableContainer cont = item as LockableContainer;

                                cont.MaxLockLevel  = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0);
                                cont.LockLevel     = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0);
                                cont.RequiredSkill = Utility.GetXMLInt32(Utility.GetText(node["maxlocklevel"], "0"), 0);

                                cont.Locked         = Utility.GetText(node["locked"], "false") == "true";
                                cont.TrapOnLockpick = Utility.GetText(node["traponlockpick"], "false") == "true";
                            }

                            if (item is BaseLight)
                            {
                                BaseLight light = item as BaseLight;
                                light.Protected = Utility.GetText(node["protected"], "true") == "true";
                                light.Duration  = Utility.GetXMLTimeSpan(Utility.GetText(node["duration"], "0"), TimeSpan.Zero);
                                light.Burning   = Utility.GetText(node["burning"], "true") == "true";
                            }
                        }
                        else
                        {
                            Console.WriteLine("Error loading: {0}", itemtype.FullName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Error loading type from xml: {0}", itemstring);
                    }
                }
                else
                {
                    Console.WriteLine("Error loading string from xml: {0}", itemstring);
                }
            }

            Console.WriteLine("done.");
        }
Exemple #7
0
        public static void Load()
        {
            if (m_Loaded)
            {
                return;
            }

            m_Loaded      = true;
            m_LoadingType = null;

            Console.Write("World: Loading...");

            DateTime start = DateTime.Now;

            m_Loading    = true;
            m_DeleteList = new ArrayList();

            int mobileCount = 0, itemCount = 0, guildCount = 0, regionCount = 0;

            object[] ctorArgs  = new object[1];
            Type[]   ctorTypes = new Type[1] {
                typeof(Serial)
            };

            ArrayList items   = new ArrayList();
            ArrayList mobiles = new ArrayList();
            ArrayList guilds  = new ArrayList();
            ArrayList regions = new ArrayList();

            if (File.Exists(mobIdxPath) && File.Exists(mobTdbPath))
            {
                using (FileStream idx = new FileStream(mobIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(mobTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, null });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        mobileCount = idxReader.ReadInt32();

                        m_Mobiles = new Hashtable(mobileCount);

                        for (int i = 0; i < mobileCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Mobile          m        = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                m           = (Mobile)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (m != null)
                            {
                                mobiles.Add(new MobileEntry(m, typeID, typeName, pos, length));
                                AddMobile(m);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Mobiles = new Hashtable();
            }

            if (File.Exists(itemIdxPath) && File.Exists(itemTdbPath))
            {
                using (FileStream idx = new FileStream(itemIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    using (FileStream tdb = new FileStream(itemTdbPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        BinaryReader tdbReader = new BinaryReader(tdb);

                        int count = tdbReader.ReadInt32();

                        ArrayList types = new ArrayList(count);

                        for (int i = 0; i < count; ++i)
                        {
                            string typeName = tdbReader.ReadString();

                            Type t = ScriptCompiler.FindTypeByFullName(typeName);

                            if (t == null)
                            {
                                Console.WriteLine("failed");
                                Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                                if (Console.ReadLine() == "y")
                                {
                                    types.Add(null);
                                    Console.Write("World: Loading...");
                                    continue;
                                }

                                Console.WriteLine("Types will not be deleted. An exception will be thrown when you press return");

                                throw new Exception(String.Format("Bad type '{0}'", typeName));
                            }

                            ConstructorInfo ctor = t.GetConstructor(ctorTypes);

                            if (ctor != null)
                            {
                                types.Add(new object[] { ctor, typeName });
                            }
                            else
                            {
                                throw new Exception(String.Format("Type '{0}' does not have a serialization constructor", t));
                            }
                        }

                        itemCount = idxReader.ReadInt32();

                        m_Items = new Hashtable(itemCount);

                        for (int i = 0; i < itemCount; ++i)
                        {
                            int  typeID = idxReader.ReadInt32();
                            int  serial = idxReader.ReadInt32();
                            long pos    = idxReader.ReadInt64();
                            int  length = idxReader.ReadInt32();

                            object[] objs = (object[])types[typeID];

                            if (objs == null)
                            {
                                continue;
                            }

                            Item            item     = null;
                            ConstructorInfo ctor     = (ConstructorInfo)objs[0];
                            string          typeName = (string)objs[1];

                            try
                            {
                                ctorArgs[0] = (Serial)serial;
                                item        = (Item)(ctor.Invoke(ctorArgs));
                            }
                            catch
                            {
                            }

                            if (item != null)
                            {
                                items.Add(new ItemEntry(item, typeID, typeName, pos, length));
                                AddItem(item);
                            }
                        }

                        tdbReader.Close();
                    }

                    idxReader.Close();
                }
            }
            else
            {
                m_Items = new Hashtable();
            }

            if (File.Exists(guildIdxPath))
            {
                using (FileStream idx = new FileStream(guildIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    guildCount = idxReader.ReadInt32();

                    CreateGuildEventArgs createEventArgs = new CreateGuildEventArgs(-1);
                    for (int i = 0; i < guildCount; ++i)
                    {
                        idxReader.ReadInt32();                        //no typeid for guilds
                        int  id     = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        createEventArgs.Id = id;
                        BaseGuild guild = EventSink.InvokeCreateGuild(createEventArgs);                          //new Guild( id );
                        if (guild != null)
                        {
                            guilds.Add(new GuildEntry(guild, pos, length));
                        }
                    }

                    idxReader.Close();
                }
            }

            if (File.Exists(regionIdxPath))
            {
                using (FileStream idx = new FileStream(regionIdxPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryReader idxReader = new BinaryReader(idx);

                    regionCount = idxReader.ReadInt32();

                    for (int i = 0; i < regionCount; ++i)
                    {
                        int  typeID = idxReader.ReadInt32();
                        int  serial = idxReader.ReadInt32();
                        long pos    = idxReader.ReadInt64();
                        int  length = idxReader.ReadInt32();

                        Region r = Region.FindByUId(serial);

                        if (r != null)
                        {
                            regions.Add(new RegionEntry(r, pos, length));
                            Region.AddRegion(r);
                            regionCount++;
                        }
                    }

                    idxReader.Close();
                }
            }

            bool      failedMobiles = false, failedItems = false, failedGuilds = false, failedRegions = false;
            Type      failedType   = null;
            Serial    failedSerial = Serial.Zero;
            Exception failed       = null;
            int       failedTypeID = 0;

            if (File.Exists(mobBinPath))
            {
                using (FileStream bin = new FileStream(mobBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < mobiles.Count; ++i)
                    {
                        MobileEntry entry = (MobileEntry)mobiles[i];
                        Mobile      m     = (Mobile)entry.Object;

                        if (m != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                m.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", m.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                mobiles.RemoveAt(i);

                                failed        = e;
                                failedMobiles = true;
                                failedType    = m.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = m.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && File.Exists(itemBinPath))
            {
                using (FileStream bin = new FileStream(itemBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < items.Count; ++i)
                    {
                        ItemEntry entry = (ItemEntry)items[i];
                        Item      item  = (Item)entry.Object;

                        if (item != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                m_LoadingType = entry.TypeName;
                                item.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", item.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                items.RemoveAt(i);

                                failed       = e;
                                failedItems  = true;
                                failedType   = item.GetType();
                                failedTypeID = entry.TypeID;
                                failedSerial = item.Serial;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            m_LoadingType = null;

            if (!failedMobiles && !failedItems && File.Exists(guildBinPath))
            {
                using (FileStream bin = new FileStream(guildBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < guilds.Count; ++i)
                    {
                        GuildEntry entry = (GuildEntry)guilds[i];
                        BaseGuild  g     = (BaseGuild)entry.Object;

                        if (g != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                g.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on Guild {0} *****", g.Id));
                                }
                            }
                            catch (Exception e)
                            {
                                guilds.RemoveAt(i);

                                failed       = e;
                                failedGuilds = true;
                                failedType   = typeof(BaseGuild);
                                failedTypeID = g.Id;
                                failedSerial = g.Id;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (!failedMobiles && !failedItems && File.Exists(regionBinPath))
            {
                using (FileStream bin = new FileStream(regionBinPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFileReader reader = new BinaryFileReader(new BinaryReader(bin));

                    for (int i = 0; i < regions.Count; ++i)
                    {
                        RegionEntry entry = (RegionEntry)regions[i];
                        Region      r     = (Region)entry.Object;

                        if (r != null)
                        {
                            reader.Seek(entry.Position, SeekOrigin.Begin);

                            try
                            {
                                r.Deserialize(reader);

                                if (reader.Position != (entry.Position + entry.Length))
                                {
                                    throw new Exception(String.Format("***** Bad serialize on {0} *****", r.GetType()));
                                }
                            }
                            catch (Exception e)
                            {
                                regions.RemoveAt(i);

                                failed        = e;
                                failedRegions = true;
                                failedType    = r.GetType();
                                failedTypeID  = entry.TypeID;
                                failedSerial  = r.UId;

                                break;
                            }
                        }
                    }

                    reader.Close();
                }
            }

            if (failedItems || failedMobiles || failedGuilds || failedRegions)
            {
                Console.WriteLine("An error was encountered while loading a saved object");

                Console.WriteLine(" - Type: {0}", failedType);
                Console.WriteLine(" - Serial: {0}", failedSerial);

                Console.WriteLine("Delete the object? (y/n)");

                if (Console.ReadLine() == "y")
                {
                    if (failedType != typeof(BaseGuild) && !failedType.IsSubclassOf(typeof(Region)))
                    {
                        Console.WriteLine("Delete all objects of that type? (y/n)");

                        if (Console.ReadLine() == "y")
                        {
                            if (failedMobiles)
                            {
                                for (int i = 0; i < mobiles.Count;)
                                {
                                    if (((MobileEntry)mobiles[i]).TypeID == failedTypeID)
                                    {
                                        mobiles.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                            else if (failedItems)
                            {
                                for (int i = 0; i < items.Count;)
                                {
                                    if (((ItemEntry)items[i]).TypeID == failedTypeID)
                                    {
                                        items.RemoveAt(i);
                                    }
                                    else
                                    {
                                        ++i;
                                    }
                                }
                            }
                        }
                    }

                    SaveIndex(mobiles, mobIdxPath);
                    SaveIndex(items, itemIdxPath);
                    SaveIndex(guilds, guildIdxPath);
                    SaveIndex(regions, regionIdxPath);
                }

                Console.WriteLine("After pressing return an exception will be thrown and the server will terminate");
                Console.ReadLine();

                throw new Exception(String.Format("Load failed (items={0}, mobiles={1}, guilds={2}, regions={3}, type={4}, serial={5})", failedItems, failedMobiles, failedGuilds, failedRegions, failedType, failedSerial), failed);
            }

            EventSink.InvokeWorldLoad();

            m_Loading = false;

            for (int i = 0; i < m_DeleteList.Count; ++i)
            {
                object o = m_DeleteList[i];

                if (o is Item)
                {
                    ((Item)o).Delete();
                }
                else if (o is Mobile)
                {
                    ((Mobile)o).Delete();
                }
            }

            m_DeleteList.Clear();

            foreach (Item item in m_Items.Values)
            {
                if (item.Parent == null)
                {
                    item.UpdateTotals();
                }

                item.ClearProperties();
            }

            ArrayList list = new ArrayList(m_Mobiles.Values);

            foreach (Mobile m in list)
            {
                m.ForceRegionReEnter(true);
                m.UpdateTotals();

                m.ClearProperties();
            }

            Console.WriteLine("done ({1} items, {2} mobiles) ({0:F1} seconds)", (DateTime.Now - start).TotalSeconds, m_Items.Count, m_Mobiles.Count);
        }
        public static void ImportWorld()
        {
            ArrayList retry = new ArrayList(), houses = new ArrayList();
            int       count = 0;

            foreach (Account a in Accounts.List.Values)
            {
                for (int i = 0; i < 6; i++)
                {
                    if (a[i] != null)
                    {
                        a[i].Player = false;
                    }

                    a[i] = null;
                }
            }

            using (StreamReader r = new StreamReader("world.txt", System.Text.Encoding.ASCII))
            {
                string  line;
                IEntity curObj  = null;
                Mobile  prevMob = null;
                Type    curType = null;

                while ((line = r.ReadLine()) != null)
                {
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }

                    string[] parts = line.Split(new char[] { '=' }, 3, StringSplitOptions.None);

                    if (parts.Length != 3)
                    {
                        Console.WriteLine("Warning! Wrong number of fields: {0} -- {1}", parts.Length, line);
                        continue;
                    }

                    /*if (parts[0] == "Profile")
                     * {
                     *  long prevPos = r.BaseStream.Position;
                     *  while ((line = r.ReadLine()) != null)
                     *  {
                     *      string[] split = line.Split(new char[] { '=' }, 3, StringSplitOptions.None);
                     *
                     *      if (split.Length != 3)
                     *      {
                     *          parts[2] += "\n" + line;
                     *          prevPos = r.BaseStream.Position;
                     *      }
                     *      else
                     *      {
                     *          r.BaseStream.Seek(prevPos, SeekOrigin.Begin);
                     *          break;
                     *      }
                     *  }
                     * }*/

                    try
                    {
                        if (parts[0] == "Object")
                        {
                            PostProcess(curObj);
                            parts[1] = TranslateType(parts[1]);
                            curObj   = null;
                            curType  = ScriptCompiler.FindTypeByFullName(parts[1], true);

                            if (curType == null)
                            {
                                InsertError("{0}: Type missing", parts[1]);
                                continue;
                            }

                            Serial oldSer = Utility.ToInt32(parts[2]);

                            /*if (IsType(curType, typeof(Item)))
                             *  Serial.NewItem = Utility.ToInt32(parts[2]) - 1;
                             * else if (IsType(curType, typeof(Mobile) ))
                             *  Serial.NewMobile = Utility.ToInt32(parts[2]) - 1;
                             */
                            try { curObj = Activator.CreateInstance(curType, new object[0]) as IEntity; } catch { }

                            if (curObj == null)
                            {
                                try
                                {
                                    if (curType == typeof(BankBox) && prevMob != null)
                                    {
                                        curObj = new BankBox(prevMob);
                                    }
                                    //curObj = Activator.CreateInstance( curType, new object[1]{prevMob} ) as IEntity;
                                }
                                catch { }

                                if (curObj == null)
                                {
                                    InsertError("{0}: Unable to construct", parts[1]);
                                    continue;
                                }
                            }

                            if (curObj is Mobile)
                            {
                                _Mobiles[oldSer] = curObj;
                                prevMob          = (Mobile)curObj;
                            }
                            else if (curObj is Item)
                            {
                                _Items[oldSer] = curObj;
                            }

                            count++;
                            if ((count % 10000) == 0)
                            {
                                Console.WriteLine("Completed {0} objects so far", count - 1);
                            }
                        }
                        else if (parts[0] == "House")
                        {
                            string type, loc, map, owner;

                            type  = r.ReadLine();
                            loc   = r.ReadLine();
                            map   = r.ReadLine();
                            owner = r.ReadLine();
                            houses.Add(new string[] { type, loc, map, owner });
                        }
                        else if (parts[0] == "Skills")
                        {
                            Mobile m = FindMobile(Utility.ToInt32(parts[2]));

                            while ((line = r.ReadLine()) != null)
                            {
                                if (line == "EndSkills" || line == "")
                                {
                                    break;
                                }

                                parts = line.Split(new char[] { '=' }, 3, StringSplitOptions.None);

                                if (parts.Length != 3)
                                {
                                    continue;
                                }

                                SkillName name = (SkillName)Enum.Parse(typeof(SkillName), parts[0]);

                                m.Skills[name].BaseFixedPoint = Utility.ToInt32(parts[2]);
                            }
                        }
                        else if (parts[0] == "RuneBookEntry")
                        {
                            if (curObj is Runebook)
                            {
                                Point3D pt = Point3D.Parse(parts[1]);

                                bool okay = true;
                                if (Spells.SpellHelper.IsAnyT2A(Map.Felucca, pt))
                                {
                                    okay = false;
                                }
                                else if (Spells.SpellHelper.IsFeluccaDungeon(Map.Felucca, pt))
                                {
                                    Regions.DungeonRegion reg = Region.Find(pt, Map.Felucca) as Regions.DungeonRegion;

                                    if (reg != null)
                                    {
                                        if (reg.Name == "Fire" || reg.Name == "Ice" || reg.Name == "Orc Cave" || reg.Name == "Terathan Keep")
                                        {
                                            okay = false;
                                        }
                                    }
                                }

                                if (okay)
                                {
                                    ((Runebook)curObj).Entries.Add(new RunebookEntry(pt, Map.Felucca, parts[2], null));
                                }
                            }
                        }
                        else if (curObj != null)
                        {
                            DoProperty(curObj, curType, parts, retry);
                        }
                    }
                    catch (Exception e)
                    {
                        InsertError("Exception '{0}' for line '{1}'", e.Message, line);
                    }
                }

                PostProcess(curObj);
            }

            foreach (object[] list in retry)
            {
                DoProperty(list[0], list[1] as Type, list[2] as string[], null);
            }

            foreach (string[] list in houses)
            {
                list[0] = TranslateType(list[0]);
                Type    deedType = ScriptCompiler.FindTypeByFullName(list[0], true);
                Point3D loc      = Point3D.Parse(list[1]);
                Map     map      = Map.Parse(list[2]);
                Mobile  owner    = FindMobile(Utility.ToInt32(list[3]));

                if (deedType == null || !deedType.IsSubclassOf(typeof(HouseDeed)))
                {
                    InsertError("{0}: Type missing\n", list[0]);
                    continue;
                }

                if (owner == null || map == null || map == Map.Internal || loc == Point3D.Zero)
                {
                    InsertError("House properties messed up (owner probably missing)\n");
                    continue;
                }

                HouseDeed deed = null;
                try { deed = Activator.CreateInstance(deedType, new object[0]) as HouseDeed; }
                catch { }

                if (deed == null)
                {
                    InsertError("Failed to create deed {0}\n", list[0]);
                    continue;
                }

                BaseHouse house = deed.GetHouse(owner);
                house.MoveToWorld(loc, map);
                deed.Delete();
            }

            Console.WriteLine("Import complete, imported {0} objects.", count);
            Console.WriteLine("\nErrors:");
            foreach (string err in _Errors.Keys)
            {
                Console.WriteLine("{0}  (Count={1})", err, _Errors[err]);
            }

            Console.WriteLine("Done.  Saving...");
            World.Save();

            Console.WriteLine("Press enter to quit.  REMOVE THIS SCRIPT BEFORE RUNNING THE SERVER AGAIN");
            Console.ReadLine();
            System.Diagnostics.Process.GetCurrentProcess().Kill();
        }
        private static void DoProperty(object curObj, Type curType, string[] parts, ArrayList retry)
        {
            TranslateProperty(curObj, parts);

            if (parts[0] == "")
            {
                return;
            }

            Type         thisType = ScriptCompiler.FindTypeByFullName(parts[1], true);
            PropertyInfo prop     = null;

            if (thisType != null)
            {
                prop = curType.GetProperty(parts[0], thisType);
            }
            if (prop == null)
            {
                prop = curType.GetProperty(parts[0]);
            }

            if (prop == null)
            {
                InsertError("{0}.{1}: Prop missing", curObj.GetType().FullName, parts[0]);
                return;
            }

            if (thisType == null || !prop.PropertyType.IsAssignableFrom(thisType))
            {
                thisType = prop.PropertyType;
            }

            object val = GetObjectFromString(thisType, parts[2]);

            if (val == null)
            {
                if (retry != null)
                {
                    retry.Add(new object[] { curObj, curType, parts });
                }
                else
                {
                    InsertError("{0}.{1}: Value ({2}) is null", curObj.GetType().FullName, parts[0], parts[2]);
                }
                return;
            }
            else
            {
                if (val is Account && curObj is Mobile)
                {
                    Account a    = (Account)val;
                    int     free = -1;
                    for (int i = 0; i < a.Length; i++)
                    {
                        if (a[i] == null || a[i] == curObj)
                        {
                            free = i;
                            break;
                        }
                    }

                    if (free != -1)
                    {
                        a[free] = (Mobile)curObj;
                    }
                }

                if (parts[0] == "Parent" && curObj is Item)
                {
                    if (val is Mobile)
                    {
                        ((Mobile)val).AddItem((Item)curObj);
                    }
                    else if (val is Item)
                    {
                        ((Item)val).AddItem((Item)curObj);
                    }
                    else
                    {
                        Console.WriteLine("wtf?");
                    }
                }
                else
                {
                    prop.SetValue(curObj, val, null);
                }
            }
        }
Exemple #10
0
        private static List <Tuple <ConstructorInfo, string> > ReadTypes(BinaryReader tdbReader)
        {
            int count = tdbReader.ReadInt32();

            List <Tuple <ConstructorInfo, string> > types = new List <Tuple <ConstructorInfo, string> >(count);

            for (int i = 0; i < count; ++i)
            {
                string typeName = tdbReader.ReadString();

                Type t = ScriptCompiler.FindTypeByFullName(typeName);

                if (t == null)
                {
                    Console.WriteLine("failed");

                    if (!Core.Service)
                    {
                        Console.WriteLine("Error: Type '{0}' was not found. Delete all of those types? (y/n)", typeName);

                        if (Console.ReadKey(true).Key == ConsoleKey.Y)
                        {
                            types.Add(null);
                            Utility.PushColor(ConsoleColor.Yellow);
                            Console.Write("World: Loading...");
                            Utility.PopColor();
                            continue;
                        }

                        Console.WriteLine("Types will not be deleted. An exception will be thrown.");
                    }
                    else
                    {
                        Console.WriteLine("Error: Type '{0}' was not found.", typeName);
                    }

                    throw new Exception(String.Format("Missing type '{0}'", typeName));
                }

                if (t.IsAbstract)
                {
                    foreach (var at in ScriptCompiler.FindTypesByFullName(t.FullName))
                    {
                        if (at != t && !at.IsAbstract)
                        {
                            t        = at;
                            typeName = at.FullName;
                            break;
                        }
                    }

                    if (t.IsAbstract)
                    {
                        Console.WriteLine("failed");

                        if (!Core.Service)
                        {
                            Console.WriteLine("Error: Type '{0}' is abstract. Delete all of those types? (y/n)", typeName);

                            if (Console.ReadKey(true).Key == ConsoleKey.Y)
                            {
                                types.Add(null);
                                Utility.PushColor(ConsoleColor.Yellow);
                                Console.Write("World: Loading...");
                                Utility.PopColor();
                                continue;
                            }

                            Console.WriteLine("Types will not be deleted. An exception will be thrown.");
                        }
                        else
                        {
                            Console.WriteLine("Error: Type '{0}' is abstract.", typeName);
                        }

                        throw new Exception(String.Format("Abstract type '{0}'", typeName));
                    }
                }

                ConstructorInfo ctor = t.GetConstructor(m_SerialTypeArray);

                if (ctor != null)
                {
                    types.Add(new Tuple <ConstructorInfo, string>(ctor, typeName));
                }
                else
                {
                    throw new Exception(string.Format("Type '{0}' does not have a serialization constructor", t));
                }
            }

            return(types);
        }
		private static BaseDoor DeserializeDoor(XmlElement node)
		{
			var t = node.GetAttribute("type");

			var type = ScriptCompiler.FindTypeByName(t, true) ?? //
					   ScriptCompiler.FindTypeByFullName(t, true) ?? //
					   Type.GetType(t, false, true);

			BaseDoor door;

			try
			{
				door = (Activator.CreateInstance(type, _ImportArgs) ?? Activator.CreateInstance(type)) as BaseDoor;
			}
			catch
			{
				return null;
			}

			if (door == null)
			{
				return null;
			}

			var x = XmlConvert.ToInt32(node.GetAttribute("x"));
			var y = XmlConvert.ToInt32(node.GetAttribute("y"));
			var z = XmlConvert.ToInt32(node.GetAttribute("z"));

			door.Location = new Point3D(x, y, z);

			var ox = XmlConvert.ToInt32(node.GetAttribute("ox"));
			var oy = XmlConvert.ToInt32(node.GetAttribute("oy"));
			var oz = XmlConvert.ToInt32(node.GetAttribute("oz"));

			door.Offset = new Point3D(ox, oy, oz);

			door.OpenedID = XmlConvert.ToInt32(node.GetAttribute("oid"));
			door.ClosedID = XmlConvert.ToInt32(node.GetAttribute("cid"));

			door.Locked = XmlConvert.ToBoolean(node.GetAttribute("locked"));

			if (node.HasAttribute("keyval"))
			{
				door.KeyValue = XmlConvert.ToUInt32(node.GetAttribute("keyval"));
			}

			if (node.HasAttribute("osound"))
			{
				door.OpenedSound = XmlConvert.ToInt32(node.GetAttribute("osound"));
			}

			if (node.HasAttribute("csound"))
			{
				door.ClosedSound = XmlConvert.ToInt32(node.GetAttribute("csound"));
			}

			if (node.HasAttribute("hue"))
			{
				door.Hue = XmlConvert.ToInt32(node.GetAttribute("hue"));
			}

			if (door.Open)
			{
				door.ItemID = door.OpenedID;
			}
			else
			{
				door.ItemID = door.ClosedID;
			}

			return door;
		}
Exemple #12
0
        public static void LoadItems()
        {
            FileStream fs = null;

            try
            {
                fs = File.Open("items.xml", FileMode.Open, FileAccess.Read);
            }
            catch
            {
                Console.WriteLine("Could not open file");
            }

            if (fs == null)
            {
                World.Broadcast(0x35, false, "Loading failed.");
                return;
            }

            DataSet ds = new DataSet("static");

            try
            {
                ds.ReadXml(fs);
            }
            catch
            {
                World.Broadcast(0x35, false, "Error with xml");
                return;
            }
            finally
            {
                fs.Close();
            }

            if (ds.Tables != null && ds.Tables.Count > 0)
            {
                World.Broadcast(0x35, false, "Table successfully populated.");

                if (ds.Tables["item"] != null && ds.Tables["item"].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables["item"].Rows)
                    {
                        string temp = string.Empty;
                        Type   type = null;
                        try
                        {
                            type = ScriptCompiler.FindTypeByFullName(dr["Type"].ToString(), false);
                        }
                        catch
                        {
                            Console.WriteLine("Type loading failed");
                        }

                        if (type == null)
                        {
                            continue;
                        }

                        Item item;
                        try
                        {
                            item = Activator.CreateInstance(type) as Item;
                        }
                        catch
                        {
                            Console.WriteLine("Type creation failed.");
                            continue;
                        }

                        if (item == null)
                        {
                            continue;
                        }

                        try
                        {
                            item.ItemID = int.Parse(dr["ItemID"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("ItemID loading failed");
                        }

                        try
                        {
                            item.Amount = int.Parse(dr["Amount"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Amount loading failed");
                            item.Amount = 1;
                        }

                        try
                        {
                            temp = dr["Movable"].ToString();
                            switch (temp)
                            {
                            case "True":
                                item.Movable = true;
                                break;

                            case "False":
                                item.Movable = false;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Movable loading failed");
                            item.Movable = false;
                        }

                        try
                        {
                            temp = dr["Direction"].ToString();

                            switch (temp)
                            {
                            case "North":
                                item.Direction = Direction.North;
                                break;

                            case "Right":
                                item.Direction = Direction.Right;
                                break;

                            case "East":
                                item.Direction = Direction.East;
                                break;

                            case "Down":
                                item.Direction = Direction.Down;
                                break;

                            case "South":
                                item.Direction = Direction.South;
                                break;

                            case "Left":
                                item.Direction = Direction.Left;
                                break;

                            case "West":
                                item.Direction = Direction.West;
                                break;

                            case "Up":
                                item.Direction = Direction.Up;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Direction loading failed");
                        }

                        try
                        {
                            item.Hue = int.Parse(dr["Hue"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Hue loading failed");
                        }

                        try
                        {
                            temp = dr["Layer"].ToString();
                            switch (temp)
                            {
                            case "Invalid":
                                item.Layer = Layer.Invalid;
                                break;

                            case "FirstValid":
                                item.Layer = Layer.FirstValid;
                                break;

                            case "OneHanded":
                                item.Layer = Layer.OneHanded;
                                break;

                            case "TwoHanded":
                                item.Layer = Layer.TwoHanded;
                                break;

                            case "Shoes":
                                item.Layer = Layer.Shoes;
                                break;

                            case "Pants":
                                item.Layer = Layer.Pants;
                                break;

                            case "Shirt":
                                item.Layer = Layer.Shirt;
                                break;

                            case "Helm":
                                item.Layer = Layer.Helm;
                                break;

                            case "Gloves":
                                item.Layer = Layer.Gloves;
                                break;

                            case "Ring":
                                item.Layer = Layer.Ring;
                                break;

                            case "Talisman":
                                item.Layer = Layer.Talisman;
                                break;

                            case "Neck":
                                item.Layer = Layer.Neck;
                                break;

                            case "Hair":
                                item.Layer = Layer.Hair;
                                break;

                            case "Waist":
                                item.Layer = Layer.Waist;
                                break;

                            case "InnerTorso":
                                item.Layer = Layer.InnerTorso;
                                break;

                            case "Bracelet":
                                item.Layer = Layer.Bracelet;
                                break;

                            case "Unused_xF":
                                item.Layer = Layer.Unused_xF;
                                break;

                            case "FacialHair":
                                item.Layer = Layer.FacialHair;
                                break;

                            case "MiddleTorso":
                                item.Layer = Layer.MiddleTorso;
                                break;

                            case "Earrings":
                                item.Layer = Layer.Earrings;
                                break;

                            case "Arms":
                                item.Layer = Layer.Arms;
                                break;

                            case "Cloak":
                                item.Layer = Layer.Cloak;
                                break;

                            case "Backpack":
                                item.Layer = Layer.Backpack;
                                break;

                            case "OuterTorso":
                                item.Layer = Layer.OuterTorso;
                                break;

                            case "OuterLegs":
                                item.Layer = Layer.OuterLegs;
                                break;

                            case "InnerLegs":
                                item.Layer = Layer.InnerLegs;
                                break;

                            case "LastUserValid":
                                item.Layer = Layer.LastUserValid;
                                break;

                            case "Mount":
                                item.Layer = Layer.Mount;
                                break;

                            case "ShopBuy":
                                item.Layer = Layer.ShopBuy;
                                break;

                            case "ShopResale":
                                item.Layer = Layer.ShopResale;
                                break;

                            case "ShopSell":
                                item.Layer = Layer.ShopSell;
                                break;

                            case "Bank":
                                item.Layer = Layer.Bank;
                                break;

                            case "LastValid":
                                item.Layer = Layer.LastValid;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Layer loading failed");
                        }

                        try
                        {
                            temp = dr["Light"].ToString();

                            switch (temp)
                            {
                            case "ArchedWindowEast":
                                item.Light = LightType.ArchedWindowEast;
                                break;

                            case "Circle225":
                                item.Light = LightType.Circle225;
                                break;

                            case "Circle150":
                                item.Light = LightType.Circle150;
                                break;

                            case "DoorSouth":
                                item.Light = LightType.DoorSouth;
                                break;

                            case "DoorEast":
                                item.Light = LightType.DoorEast;
                                break;

                            case "NorthBig":
                                item.Light = LightType.NorthBig;
                                break;

                            case "NorthEastBig":
                                item.Light = LightType.NorthEastBig;
                                break;

                            case "EastBig":
                                item.Light = LightType.EastBig;
                                break;

                            case "WestBig":
                                item.Light = LightType.WestBig;
                                break;

                            case "SouthWestBig":
                                item.Light = LightType.SouthWestBig;
                                break;

                            case "SouthBig":
                                item.Light = LightType.SouthBig;
                                break;

                            case "NorthSmall":
                                item.Light = LightType.NorthSmall;
                                break;

                            case "NorthEastSmall":
                                item.Light = LightType.NorthEastSmall;
                                break;

                            case "EastSmall":
                                item.Light = LightType.EastSmall;
                                break;

                            case "WestSmall":
                                item.Light = LightType.WestSmall;
                                break;

                            case "SouthSmall":
                                item.Light = LightType.SouthSmall;
                                break;

                            case "DecorationNorth":
                                item.Light = LightType.DecorationNorth;
                                break;

                            case "DecorationNorthEast":
                                item.Light = LightType.DecorationNorthEast;
                                break;

                            case "EastTiny":
                                item.Light = LightType.EastTiny;
                                break;

                            case "DecorationWest":
                                item.Light = LightType.DecorationWest;
                                break;

                            case "DecorationSouthWest":
                                item.Light = LightType.DecorationSouthWest;
                                break;

                            case "SouthTiny":
                                item.Light = LightType.SouthTiny;
                                break;

                            case "RectWindowSouthNoRay":
                                item.Light = LightType.RectWindowSouthNoRay;
                                break;

                            case "RectWindowEastNoRay":
                                item.Light = LightType.RectWindowEastNoRay;
                                break;

                            case "RectWindowSouth":
                                item.Light = LightType.RectWindowSouth;
                                break;

                            case "RectWindowEast":
                                item.Light = LightType.RectWindowEast;
                                break;

                            case "ArchedWindowSouthNoRay":
                                item.Light = LightType.ArchedWindowSouthNoRay;
                                break;

                            case "ArchedWindowEastNoRay":
                                item.Light = LightType.ArchedWindowEastNoRay;
                                break;

                            case "ArchedWindowSouth":
                                item.Light = LightType.ArchedWindowSouth;
                                break;

                            case "Cirle300":
                                item.Light = LightType.Circle300;
                                break;

                            case "NorthWestBig":
                                item.Light = LightType.NorthWestBig;
                                break;

                            case "DarkSouthEast":
                                item.Light = LightType.DarkSouthEast;
                                break;

                            case "DarkSouth":
                                item.Light = LightType.DarkSouth;
                                break;

                            case "DarkNorthWest":
                                item.Light = LightType.DarkNorthWest;
                                break;

                            case "DarkSouthEast2":
                                item.Light = LightType.DarkSouthEast2;
                                break;

                            case "DarkEast":
                                item.Light = LightType.DarkEast;
                                break;

                            case "DarkCircle300":
                                item.Light = LightType.DarkCircle300;
                                break;

                            case "DoorOpenSouth":
                                item.Light = LightType.DoorOpenSouth;
                                break;

                            case "DoorOpenEast":
                                item.Light = LightType.DoorOpenEast;
                                break;

                            case "SquareWindowEast":
                                item.Light = LightType.SquareWindowEast;
                                break;

                            case "SquareWindowEastNoRay":
                                item.Light = LightType.SquareWindowEastNoRay;
                                break;

                            case "SquareWindowSouth":
                                item.Light = LightType.SquareWindowSouth;
                                break;

                            case "SquareWindowSouthNoRay":
                                item.Light = LightType.SquareWindowSouthNoRay;
                                break;

                            case "Empty":
                                item.Light = LightType.Empty;
                                break;

                            case "SkinnyWindowSouthNoRay":
                                item.Light = LightType.SkinnyWindowSouthNoRay;
                                break;

                            case "SkinnyWindowEast":
                                item.Light = LightType.SkinnyWindowEast;
                                break;

                            case "SkinnyWindowEastNoRay":
                                item.Light = LightType.SkinnyWindowEastNoRay;
                                break;

                            case "HoleSouth":
                                item.Light = LightType.HoleSouth;
                                break;

                            case "HoleEast":
                                item.Light = LightType.HoleEast;
                                break;

                            case "Moongate":
                                item.Light = LightType.Moongate;
                                break;

                            case "Strips":
                                item.Light = LightType.Strips;
                                break;

                            case "SmallHoleSouth":
                                item.Light = LightType.SmallHoleSouth;
                                break;

                            case "SmallHoleEast":
                                item.Light = LightType.SmallHoleEast;
                                break;

                            case "NorthBig2":
                                item.Light = LightType.NorthBig2;
                                break;

                            case "WestBig2":
                                item.Light = LightType.WestBig2;
                                break;

                            case "NorthWestBig2":
                                item.Light = LightType.NorthWestBig2;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Light loading failed");
                        }

                        try
                        {
                            temp = dr["LootType"].ToString();
                            switch (temp)
                            {
                            case "Regular":
                                item.LootType = LootType.Regular;
                                break;

                            case "Newbied":
                                item.LootType = LootType.Newbied;
                                break;

                            case "Blessed":
                                item.LootType = LootType.Blessed;
                                break;

                            case "Cursed":
                                item.LootType = LootType.Cursed;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("LootType loading failed");
                        }

                        try
                        {
                            item.Name = dr["Name"].ToString();
                        }
                        catch
                        {
                            Console.WriteLine("Name loading failed");
                        }

                        try
                        {
                            temp = dr["Stackable"].ToString();
                            switch (temp)
                            {
                            case "True":
                                item.Stackable = true;
                                break;

                            case "False":
                                item.Stackable = false;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Stackable loading failed");
                        }

                        try
                        {
                            item.Weight = double.Parse(dr["Weight"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Weight loading failed");
                        }

                        try
                        {
                            temp = dr["Visible"].ToString();
                            switch (temp)
                            {
                            case "True":
                                item.Visible = true;
                                break;

                            case "False":
                                item.Visible = false;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Visible loading failed");
                        }

                        try
                        {
                            item.X = int.Parse(dr["X"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("X loading failed");
                        }

                        try
                        {
                            item.Y = int.Parse(dr["Y"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Y loading failed");
                        }

                        try
                        {
                            item.Z = int.Parse(dr["Z"].ToString());
                        }
                        catch
                        {
                            Console.WriteLine("Z loading failed");
                        }

                        try
                        {
                            temp = dr["Map"].ToString();

                            switch (temp)
                            {
                            case "Felucca":
                                item.Map = Map.Felucca;
                                break;

                            case "Trammel":
                                item.Map = Map.Trammel;
                                break;

                            case "Ilshenar":
                                item.Map = Map.Ilshenar;
                                break;

                            case "Malas":
                                item.Map = Map.Malas;
                                break;

                            case "Tokuno":
                                item.Map = Map.Tokuno;
                                break;

                            case "Internal":
                                item.Map = Map.Internal;
                                break;
                            }
                        }
                        catch
                        {
                            Console.WriteLine("Map loading failed");
                        }
                    }
                    World.Broadcast(0x35, false, "Items should now populate the shard...");
                }
            }
        }
Exemple #13
0
 public static Type FindTypeByFullName(string fullName)
 {
     return(ScriptCompiler.FindTypeByFullName(fullName, true));
 }