ConquerServer_v2 Problem with converting to MySQL

01/08/2012 23:44 Kiyono#1
//edit Different question

Will using MySQL done in the way below (randomly starting new readers in the same void) be bad?
Code:
MySqlCommand command3 = new MySqlCommand(MySqlCommandType.SELECT);
            command3.Select("cq_generator");
            MySqlReader reader3 = new MySqlReader(command3);
            num = 0;
            uint SpawnID = 0;
            List<uint> UsedMaps = new List<uint>();
            List<uint> SpawnIDs = new List<uint>();
            // Monster Spawns (cq_generator)
            while (reader3.Read())
            {
                uint tMapID = reader3.ReadUInt32("mapid");
                if (UsedMaps.Contains(tMapID))
                    continue;

                if (tMapID == MapID.TrainingGrounds.Id || tMapID == 1219 || tMapID == 1052 || tMapID == 4025 || tMapID == 4024 || tMapID == 4023 || tMapID == 4022 || tMapID == 4021)
                    continue;

                UsedMaps.Add(tMapID);
                MobCollection Linker = new MobCollection(tMapID, 5000);
                if (Kernel.DMaps.TryGetValue(tMapID, out Linker.DMap))
                    Linker.DMap.Mobs = Linker;

                MySqlCommand command4 = new MySqlCommand(MySqlCommandType.SELECT);
                command4.Select("cq_generator");
                MySqlReader reader4 = new MySqlReader(command4);

                while (reader4.Read())
                {
                    if (reader4.ReadUInt32("mapid") == tMapID)
                    {
                        SpawnID = reader4.ReadUInt32("id");
                        while (!SpawnIDs.Contains(SpawnID))
                        {
                            MonsterSpawn Spawn = new MonsterSpawn();
                            Spawn.CollectionOwner = Linker;
                            uint ID = reader4.ReadUInt32("npctype");

                            if (!MonsterFamilies.TryGetValue(ID, out Spawn.Family))
                            {
                                continue;
                            }
                            Spawn.SpawnX = reader4.ReadUInt16("bound_x");
                            Spawn.SpawnY = reader4.ReadUInt16("bound_y");
                            Spawn.MaxSpawnX = (ushort)(Spawn.SpawnX + reader4.ReadUInt16("bound_cx"));
                            Spawn.MaxSpawnY = (ushort)(Spawn.SpawnY + reader4.ReadUInt16("bound_cy"));
                            Spawn.MapID = tMapID;
                            Spawn.SpawnCount = reader4.ReadByte("max_per_gen");
                            Linker.AddSpawn(Spawn);
                            SpawnIDs.Add(SpawnID);
                        }
                    }
                }
                num += Linker.FinalizeCollection();
            }
            MonsterSpawn.StartSingleChildAI();
            Console.WriteLine("\tLoaded {0} Monsters.",
Albetros' MySQL system btw.

//edit In case the person reading this doesn't know, ConquerServer_v2 is the 5135 source that Hybrid released; aka, Project Manifest.
01/09/2012 00:38 Kiyono#2
Too be honest; it'd be faster for you to download the source and check it then to wait for me to figure out what part the mobspawn code is.

//edit I think that I know why it doesn't work. In the original code, it creates 1 mobcollection per map while in my code it keeps recreating the collection. This explains why it loads the monsters while they don't appear on the map; they are simply not part of the collection. Also more or less explains why only 1 mob gets spawned; it's the last mob in the table, in other words the last time the collection gets recreated.

//edit Behold; the most roundabout and probably most shitty way to do it:
Code:
MySqlCommand command3 = new MySqlCommand(MySqlCommandType.SELECT);
            command3.Select("cq_generator");
            MySqlReader reader3 = new MySqlReader(command3);
            num = 0;
            uint SpawnID = 0;
            List<uint> UsedMaps = new List<uint>();
            List<uint> SpawnIDs = new List<uint>();
            // Monster Spawns (cq_generator)
            while (reader3.Read())
            {
                uint tMapID = reader3.ReadUInt32("mapid");
                if (UsedMaps.Contains(tMapID))
                    continue;

                if (tMapID == MapID.TrainingGrounds.Id || tMapID == 1219 || tMapID == 1052 || tMapID == 4025 || tMapID == 4024 || tMapID == 4023 || tMapID == 4022 || tMapID == 4021)
                    continue;

                UsedMaps.Add(tMapID);
                MobCollection Linker = new MobCollection(tMapID, 5000);
                if (Kernel.DMaps.TryGetValue(tMapID, out Linker.DMap))
                    Linker.DMap.Mobs = Linker;

                MySqlCommand command4 = new MySqlCommand(MySqlCommandType.SELECT);
                command4.Select("cq_generator");
                MySqlReader reader4 = new MySqlReader(command4);

                while (reader4.Read())
                {
                    if (reader4.ReadUInt32("mapid") == tMapID)
                    {
                        SpawnID = reader4.ReadUInt32("id");
                        while (!SpawnIDs.Contains(SpawnID))
                        {
                            MonsterSpawn Spawn = new MonsterSpawn();
                            Spawn.CollectionOwner = Linker;
                            uint ID = reader4.ReadUInt32("npctype");

                            if (!MonsterFamilies.TryGetValue(ID, out Spawn.Family))
                            {
                                continue;
                            }
                            Spawn.SpawnX = reader4.ReadUInt16("bound_x");
                            Spawn.SpawnY = reader4.ReadUInt16("bound_y");
                            Spawn.MaxSpawnX = (ushort)(Spawn.SpawnX + reader4.ReadUInt16("bound_cx"));
                            Spawn.MaxSpawnY = (ushort)(Spawn.SpawnY + reader4.ReadUInt16("bound_cy"));
                            Spawn.MapID = tMapID;
                            Spawn.SpawnCount = reader4.ReadByte("max_per_gen");
                            Linker.AddSpawn(Spawn);
                            SpawnIDs.Add(SpawnID);
                        }
                    }
                }
                num += Linker.FinalizeCollection();
            }
            MonsterSpawn.StartSingleChildAI();
            Console.WriteLine("\tLoaded {0} Monsters.", num);
        }
But it works, lol
01/10/2012 01:48 InfamousNoone#3
I'd like to mention I've never really been proud of my monster system in any of my sources and don't think I really did as well as a job implementing them as I possibly could have. I'd highly recommend recoding the entire system if you ever get a chance.
01/10/2012 16:09 Kiyono#4
Ok, question changed, check OP.