示例#1
0
        public static void SaveRawMap(MySql database, string mapID, RawMap rawMap)
        {
            bool localTransaction = false;

            if (database.IsTransactionActive == false)
            {
                database.BeginTransaction();
                localTransaction = true;
            }

            // Delete old map, if it exists
            DeleteMap(database, mapID);

            // Save map general information
            database.UpdateOrInsert("map_general", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "Revision", rawMap.Revision.ToString()),
                database.CreateColumn(false, "MaxX", rawMap.MaxX.ToString()),
                database.CreateColumn(false, "MaxY", rawMap.MaxY.ToString())
            });

            // Save map data
            database.UpdateOrInsert("map_data", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "Name", rawMap.Name),
                database.CreateColumn(false, "Moral", rawMap.Moral.ToString()),
                database.CreateColumn(false, "Music", rawMap.Music),
                database.CreateColumn(false, "Indoors", rawMap.Indoors.ToIntString()),
                database.CreateColumn(false, "Weather", rawMap.Weather.ToString()),
                database.CreateColumn(false, "Darkness", rawMap.Darkness.ToString()),
                database.CreateColumn(false, "HungerEnabled", rawMap.HungerEnabled.ToIntString()),
                database.CreateColumn(false, "RecruitmentEnabled", rawMap.RecruitEnabled.ToIntString()),
                database.CreateColumn(false, "ExpEnabled", rawMap.ExpEnabled.ToIntString()),
                database.CreateColumn(false, "TimeLimit", rawMap.TimeLimit.ToString()),
                database.CreateColumn(false, "MinNpcs", rawMap.MinNpcs.ToString()),
                database.CreateColumn(false, "MaxNpcs", rawMap.MaxNpcs.ToString()),
                database.CreateColumn(false, "NpcSpawnTime", rawMap.NpcSpawnTime.ToString())
            });

            // Save map switchovers
            database.UpdateOrInsert("map_switchovers", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "UpMap", rawMap.Up.ToString()),
                database.CreateColumn(false, "DownMap", rawMap.Down.ToString()),
                database.CreateColumn(false, "LeftMap", rawMap.Left.ToString()),
                database.CreateColumn(false, "RightMap", rawMap.Right.ToString())
            });

            // Save map npc presets
            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "map_npcs", "MapID", "Slot", "Number", "SpawnX",
                                                               "SpawnY", "MinLevel", "MaxLevel", "AppearanceRate", "StartStatus", "StartStatusCounter", "StartStatusChance");

            if (rawMap.Npc.Count > 0)
            {
                for (int i = 0; i < rawMap.Npc.Count; i++)
                {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i, rawMap.Npc[i].NpcNum, rawMap.Npc[i].SpawnX, rawMap.Npc[i].SpawnY, rawMap.Npc[i].MinLevel,
                                                 rawMap.Npc[i].MaxLevel, rawMap.Npc[i].AppearanceRate, rawMap.Npc[i].StartStatus, rawMap.Npc[i].StartStatusCounter,
                                                 rawMap.Npc[i].StartStatusChance);

                    multiRowInsert.AddRowClosing();
                }
                database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());
            }

            // Save map tiles
            multiRowInsert.UpdateParameters("map_tiles", new string[] { "MapID", "X", "Y", "Ground", "GroundAnim", "Mask",
                                                                        "MaskAnim", "Mask2", "Mask2Anim", "Fringe", "FringeAnim", "Fringe2", "Fringe2Anim", "Type", "Data1", "Data2", "Data3", "String1",
                                                                        "String2", "String3", "Light", "GroundTileset", "GroundAnimTileset", "MaskTileset", "MaskAnimTileset",
                                                                        "Mask2Tileset", "Mask2AnimTileset", "FringeTileset", "FringeAnimTileset", "Fringe2Tileset", "Fringe2AnimTileset" });

            for (int x = 0; x <= rawMap.MaxX; x++)
            {
                for (int y = 0; y <= rawMap.MaxY; y++)
                {
                    if (rawMap.Tile[x, y] == null)
                    {
                        rawMap.Tile[x, y] = new Tile();
                    }

                    multiRowInsert.AddRowOpening();
                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(x, y);

                    Tile tile = rawMap.Tile[x, y];

                    multiRowInsert.AddColumnData(tile.Ground, tile.GroundAnim, tile.Mask, tile.Anim, tile.Mask2, tile.M2Anim,
                                                 tile.Fringe, tile.FAnim, tile.Fringe2, tile.F2Anim, tile.Type, tile.Data1, tile.Data2, tile.Data3);
                    multiRowInsert.AddColumnData(tile.String1, tile.String2, tile.String3);
                    multiRowInsert.AddColumnData(tile.RDungeonMapValue, tile.GroundSet, tile.GroundAnimSet, tile.MaskSet, tile.AnimSet,
                                                 tile.Mask2Set, tile.M2AnimSet, tile.FringeSet, tile.FAnimSet, tile.Fringe2Set, tile.F2AnimSet);

                    multiRowInsert.AddRowClosing();
                }
            }

            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            if (localTransaction)
            {
                database.EndTransaction();
            }
        }
示例#2
0
        public static void SaveMapDump(MySql database, string mapID, MapDump mapDump)
        {
            mapID = database.VerifyValueString(mapID);

            bool localTransaction = false;

            if (database.IsTransactionActive == false)
            {
                database.BeginTransaction();
                localTransaction = true;
            }

            SaveRawMap(database, mapID, mapDump);

            // Save map state data
            database.UpdateOrInsert("mapstate_data", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "ActivationTime", mapDump.ActivationTime.ToString()),
                database.CreateColumn(false, "ProcessingPaused", mapDump.ProcessingPaused.ToIntString()),
                database.CreateColumn(false, "SpawnMarker", mapDump.SpawnMarker.ToString()),
                database.CreateColumn(false, "NpcSpawnWait", mapDump.NpcSpawnWait.ToString()),
                database.CreateColumn(false, "TempChange", mapDump.TempChange.ToIntString()),
                database.CreateColumn(false, "CurrentWeather", mapDump.CurrentWeather.ToString())
            });

            // Save active item data
            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "mapstate_activeitem", "MapID", "Slot", "Number", "Value",
                                                               "Sticky", "Tag", "Hidden", "X", "Y", "TimeRemaining", "ItemOwner");

            for (int i = 0; i < mapDump.ActiveItem.Length; i++)
            {
                if (mapDump.ActiveItem[i].Num > 0)
                {
                    MapItem item = mapDump.ActiveItem[i];

                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i, item.Num, item.Value);
                    multiRowInsert.AddColumnData(item.Sticky.ToIntString(), item.Tag, item.Hidden.ToIntString());
                    multiRowInsert.AddColumnData(item.X, item.Y, item.TimeRemaining);
                    multiRowInsert.AddColumnData(item.PlayerFor);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npcs
            multiRowInsert.UpdateParameters("mapstate_activenpc_data", new string[] { "MapID", "MapNpcSlot", "Name", "Shiny", "Form", "Level",
                                                                                      "NpcNumber", "Sex",
                                                                                      "AttackTimer", "PauseTimer", "StatusAilment", "StatusAilmentCounter", "HPStepCounter",
                                                                                      "Target" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0)
                {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.Name, npc.Shiny.ToString());
                    multiRowInsert.AddColumnData(npc.Form, npc.Level, npc.Num, (int)npc.Sex);
                    multiRowInsert.AddColumnData(npc.AttackTimer, npc.PauseTimer, (int)npc.StatusAilment, npc.StatusAilmentCounter,
                                                 npc.HPStepCounter);
                    multiRowInsert.AddColumnData(npc.Target);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc held items
            multiRowInsert.UpdateParameters("mapstate_activenpc_helditem", new string[]  { "MapID", "MapNpcSlot",
                                                                                           "ItemNumber", "Amount", "Sticky", "Tag" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0 && mapDump.ActiveNpc[i].HeldItem.Num > 0)
                {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    //multiRowInsert.AddColumnData(npc.ItemActive.ToIntString());
                    //if (npc.HeldItem != null) {
                    // The npc is holding an item - save the held item information
                    multiRowInsert.AddColumnData(npc.HeldItem.Num, npc.HeldItem.Amount);
                    multiRowInsert.AddColumnData(npc.HeldItem.Sticky.ToIntString(), npc.HeldItem.Tag);
                    //} else {
                    // The npc is not holding an item! Save default information
                    //    multiRowInsert.AddColumnData(-1, 0, 0);
                    //    multiRowInsert.AddColumnData("");
                    //}

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc locations
            multiRowInsert.UpdateParameters("mapstate_activenpc_location", new string[] { "MapID", "MapNpcSlot", "X", "Y", "Direction" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0)
                {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.X, npc.Y, (int)npc.Direction);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc stats
            multiRowInsert.UpdateParameters("mapstate_activenpc_stats", new string[] { "MapID", "MapNpcSlot", "IQ", "HP", "HPRemainder",
                                                                                       "MaxHPBonus", "AtkBonus", "DefBonus",
                                                                                       "SpdBonus", "SpclAtkBonus", "SpclDefBonus",
                                                                                       "AttackBuff", "DefenseBuff", "SpAtkBuff", "SpDefBuff", "SpeedBuff", "AccuracyBuff", "EvasionBuff" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0)
                {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.IQ, npc.HP, npc.HPRemainder,
                                                 npc.MaxHPBonus, npc.AtkBonus, npc.DefBonus,
                                                 npc.SpdBonus, npc.SpclAtkBonus, npc.SpclDefBonus,
                                                 npc.AttackBuff, npc.DefenseBuff, npc.SpAtkBuff, npc.SpDefBuff,
                                                 npc.SpeedBuff, npc.AccuracyBuff, npc.EvasionBuff);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc moves
            multiRowInsert.UpdateParameters("mapstate_activenpc_moves", new string[] { "MapID", "MapNpcSlot", "MoveSlot", "CurrentPP", "MaxPP", "MoveNum" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0)
                {
                    for (int n = 0; n < npc.Moves.Length; n++)
                    {
                        if (npc.Moves[n].MoveNum > 0)
                        {
                            multiRowInsert.AddRowOpening();

                            multiRowInsert.AddColumnData(mapID);
                            multiRowInsert.AddColumnData(i, n);
                            multiRowInsert.AddColumnData(npc.Moves[n].CurrentPP, npc.Moves[n].MaxPP, npc.Moves[n].MoveNum);
                            //multiRowInsert.AddColumnData(npc.Moves[n].Sealed.ToIntString());

                            multiRowInsert.AddRowClosing();
                        }
                    }
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc mobility
            //multiRowInsert.UpdateParameters("mapstate_activenpc_mobility", new string[] { "MapID", "MapNpcSlot", "MobilitySlot", "Mobile" });
            //for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
            //    MapNpc npc = mapDump.ActiveNpc[i];

            //    for (int n = 0; n < npc.Mobility.Length; n++) {
            //        multiRowInsert.AddRowOpening();

            //        multiRowInsert.AddColumnData(mapID);
            //        multiRowInsert.AddColumnData(i, n);
            //        multiRowInsert.AddColumnData(npc.Mobility[n].ToIntString());

            //        multiRowInsert.AddRowClosing();
            //    }
            //}
            //database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc volatile status
            multiRowInsert.UpdateParameters("mapstate_activenpc_volatilestatus", new string[] { "MapID", "MapNpcSlot", "StatusIndex", "Name", "Emoticon", "Counter", "Tag" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++)
            {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0)
                {
                    for (int n = 0; n < npc.VolatileStatus.Count; n++)
                    {
                        multiRowInsert.AddRowOpening();

                        multiRowInsert.AddColumnData(mapID);
                        multiRowInsert.AddColumnData(i, n);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Name);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Emoticon);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Counter);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Tag);

                        multiRowInsert.AddRowClosing();
                    }
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save map status
            multiRowInsert.UpdateParameters("mapstate_mapstatus", new string[] { "MapID", "StatusIndex", "Name", "Tag", "GraphicEffect", "Counter" });
            for (int i = 0; i < mapDump.TempStatus.Count; i++)
            {
                MapStatus status = mapDump.TempStatus[i];

                multiRowInsert.AddRowOpening();

                multiRowInsert.AddColumnData(mapID);
                multiRowInsert.AddColumnData(i);
                multiRowInsert.AddColumnData(status.Name);
                multiRowInsert.AddColumnData(status.Tag);
                multiRowInsert.AddColumnData(status.GraphicEffect);
                multiRowInsert.AddColumnData(status.Counter);

                multiRowInsert.AddRowClosing();
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            if (localTransaction)
            {
                database.EndTransaction();
            }
        }
        public static void SavePlayerBank(MySql database, PlayerData playerData)
        {
            database.ExecuteNonQuery("DELETE FROM bank WHERE CharID = \'" + playerData.CharID + "\' " +
                "AND ItemSlot > " + (playerData.MaxBank));

            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "bank", "CharID", "ItemSlot", "ItemNum",
                "Amount", "Sticky", "Tag");
            for (int i = 0; i < playerData.Bank.Count; i++) {
                Characters.InventoryItem invItem = playerData.Bank.ValueByIndex(i);
                multiRowInsert.AddRowOpening();

                multiRowInsert.AddColumnData(playerData.CharID);
                multiRowInsert.AddColumnData(playerData.Bank.KeyByIndex(i), invItem.Num, invItem.Amount);
                multiRowInsert.AddColumnData(invItem.Sticky.ToIntString(), invItem.Tag);

                multiRowInsert.AddRowClosing();
            }

            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());
        }
        public static void SavePlayerBankUpdates(MySql database, string charID, ListPair<int, Characters.InventoryItem> updateList)
        {
            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "bank", "CharID", "ItemSlot", "ItemNum",
                "Amount", "Sticky", "Tag");

            for (int i = 0; i < updateList.Count; i++) {
                Characters.InventoryItem invItem = updateList.ValueByIndex(i);

                multiRowInsert.AddRowOpening();

                multiRowInsert.AddColumnData(charID);
                multiRowInsert.AddColumnData(updateList.KeyByIndex(i), invItem.Num, invItem.Amount);
                multiRowInsert.AddColumnData(invItem.Sticky.ToIntString(), invItem.Tag);

                multiRowInsert.AddRowClosing();
            }

            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());
        }
        public static void SaveRawMap(MySql database, string mapID, RawMap rawMap)
        {
            bool localTransaction = false;
            if (database.IsTransactionActive == false) {
                database.BeginTransaction();
                localTransaction = true;
            }

            // Delete old map, if it exists
            DeleteMap(database, mapID);

            // Save map general information
            database.UpdateOrInsert("map_general", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "Revision", rawMap.Revision.ToString()),
                database.CreateColumn(false, "MaxX", rawMap.MaxX.ToString()),
                database.CreateColumn(false, "MaxY", rawMap.MaxY.ToString())
            });

            // Save map data
            database.UpdateOrInsert("map_data", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "Name", rawMap.Name),
                database.CreateColumn(false, "Moral", rawMap.Moral.ToString()),
                database.CreateColumn(false, "Music", rawMap.Music),
                database.CreateColumn(false, "Indoors", rawMap.Indoors.ToIntString()),
                database.CreateColumn(false, "Weather", rawMap.Weather.ToString()),
                database.CreateColumn(false, "Darkness", rawMap.Darkness.ToString()),
                database.CreateColumn(false, "HungerEnabled", rawMap.HungerEnabled.ToIntString()),
                database.CreateColumn(false, "RecruitmentEnabled", rawMap.RecruitEnabled.ToIntString()),
                database.CreateColumn(false, "ExpEnabled", rawMap.ExpEnabled.ToIntString()),
                database.CreateColumn(false, "TimeLimit", rawMap.TimeLimit.ToString()),
                database.CreateColumn(false, "MinNpcs", rawMap.MinNpcs.ToString()),
                database.CreateColumn(false, "MaxNpcs", rawMap.MaxNpcs.ToString()),
                database.CreateColumn(false, "NpcSpawnTime", rawMap.NpcSpawnTime.ToString())
            });

            // Save map switchovers
            database.UpdateOrInsert("map_switchovers", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "UpMap", rawMap.Up.ToString()),
                database.CreateColumn(false, "DownMap", rawMap.Down.ToString()),
                database.CreateColumn(false, "LeftMap", rawMap.Left.ToString()),
                database.CreateColumn(false, "RightMap", rawMap.Right.ToString())
            });

            // Save map npc presets
            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "map_npcs", "MapID", "Slot", "Number", "SpawnX",
                "SpawnY", "MinLevel", "MaxLevel", "AppearanceRate", "StartStatus", "StartStatusCounter", "StartStatusChance");

            if (rawMap.Npc.Count > 0) {
                for (int i = 0; i < rawMap.Npc.Count; i++) {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i, rawMap.Npc[i].NpcNum, rawMap.Npc[i].SpawnX, rawMap.Npc[i].SpawnY, rawMap.Npc[i].MinLevel,
                        rawMap.Npc[i].MaxLevel, rawMap.Npc[i].AppearanceRate, rawMap.Npc[i].StartStatus, rawMap.Npc[i].StartStatusCounter,
                        rawMap.Npc[i].StartStatusChance);

                    multiRowInsert.AddRowClosing();
                }
                database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());
            }

            // Save map tiles
            multiRowInsert.UpdateParameters("map_tiles", new string[] {"MapID", "X", "Y", "Ground", "GroundAnim", "Mask",
                "MaskAnim", "Mask2", "Mask2Anim", "Fringe", "FringeAnim", "Fringe2", "Fringe2Anim", "Type", "Data1", "Data2", "Data3", "String1",
                "String2", "String3", "Light", "GroundTileset", "GroundAnimTileset", "MaskTileset", "MaskAnimTileset",
                "Mask2Tileset", "Mask2AnimTileset", "FringeTileset", "FringeAnimTileset", "Fringe2Tileset", "Fringe2AnimTileset" });

            for (int x = 0; x <= rawMap.MaxX; x++) {
                for (int y = 0; y <= rawMap.MaxY; y++) {
                    if (rawMap.Tile[x, y] == null) {
                        rawMap.Tile[x, y] = new Tile();
                    }

                    multiRowInsert.AddRowOpening();
                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(x, y);

                    Tile tile = rawMap.Tile[x, y];

                    multiRowInsert.AddColumnData(tile.Ground, tile.GroundAnim, tile.Mask, tile.Anim, tile.Mask2, tile.M2Anim,
                        tile.Fringe, tile.FAnim, tile.Fringe2, tile.F2Anim, tile.Type, tile.Data1, tile.Data2, tile.Data3);
                    multiRowInsert.AddColumnData(tile.String1, tile.String2, tile.String3);
                    multiRowInsert.AddColumnData(tile.RDungeonMapValue, tile.GroundSet, tile.GroundAnimSet, tile.MaskSet, tile.AnimSet,
                        tile.Mask2Set, tile.M2AnimSet, tile.FringeSet, tile.FAnimSet, tile.Fringe2Set, tile.F2AnimSet);

                    multiRowInsert.AddRowClosing();
                }
            }

            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            if (localTransaction) {
                database.EndTransaction();
            }
        }
        public static void SaveMapDump(MySql database, string mapID, MapDump mapDump)
        {
            mapID = database.VerifyValueString(mapID);

            bool localTransaction = false;
            if (database.IsTransactionActive == false) {
                database.BeginTransaction();
                localTransaction = true;
            }

            SaveRawMap(database, mapID, mapDump);

            // Save map state data
            database.UpdateOrInsert("mapstate_data", new IDataColumn[] {
                database.CreateColumn(false, "MapID", mapID),
                database.CreateColumn(false, "ActivationTime", mapDump.ActivationTime.ToString()),
                database.CreateColumn(false, "ProcessingPaused", mapDump.ProcessingPaused.ToIntString()),
                database.CreateColumn(false, "SpawnMarker", mapDump.SpawnMarker.ToString()),
                database.CreateColumn(false, "NpcSpawnWait", mapDump.NpcSpawnWait.ToString()),
                database.CreateColumn(false, "TempChange", mapDump.TempChange.ToIntString()),
                database.CreateColumn(false, "CurrentWeather", mapDump.CurrentWeather.ToString())
            });

            // Save active item data
            MultiRowInsert multiRowInsert = new MultiRowInsert(database, "mapstate_activeitem", "MapID", "Slot", "Number", "Value",
                "Sticky", "Tag", "Hidden", "X", "Y", "TimeRemaining", "ItemOwner");

            for (int i = 0; i < mapDump.ActiveItem.Length; i++) {
                if (mapDump.ActiveItem[i].Num > 0) {
                    MapItem item = mapDump.ActiveItem[i];

                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i, item.Num, item.Value);
                    multiRowInsert.AddColumnData(item.Sticky.ToIntString(), item.Tag, item.Hidden.ToIntString());
                    multiRowInsert.AddColumnData(item.X, item.Y, item.TimeRemaining);
                    multiRowInsert.AddColumnData(item.PlayerFor);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npcs
            multiRowInsert.UpdateParameters("mapstate_activenpc_data", new string[] {"MapID", "MapNpcSlot", "Name", "Shiny", "Form", "Level",
                "NpcNumber", "Sex",
                "AttackTimer", "PauseTimer", "StatusAilment", "StatusAilmentCounter", "HPStepCounter",
                "Target" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0) {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.Name, npc.Shiny.ToString());
                    multiRowInsert.AddColumnData(npc.Form, npc.Level, npc.Num, (int)npc.Sex);
                    multiRowInsert.AddColumnData(npc.AttackTimer, npc.PauseTimer, (int)npc.StatusAilment, npc.StatusAilmentCounter,
                        npc.HPStepCounter);
                    multiRowInsert.AddColumnData(npc.Target);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc held items
            multiRowInsert.UpdateParameters("mapstate_activenpc_helditem", new string[]  {"MapID", "MapNpcSlot",
                "ItemNumber", "Amount", "Sticky", "Tag" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0 && mapDump.ActiveNpc[i].HeldItem.Num > 0) {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    //multiRowInsert.AddColumnData(npc.ItemActive.ToIntString());
                    //if (npc.HeldItem != null) {
                        // The npc is holding an item - save the held item information
                        multiRowInsert.AddColumnData(npc.HeldItem.Num, npc.HeldItem.Amount);
                        multiRowInsert.AddColumnData(npc.HeldItem.Sticky.ToIntString(), npc.HeldItem.Tag);
                    //} else {
                        // The npc is not holding an item! Save default information
                    //    multiRowInsert.AddColumnData(-1, 0, 0);
                    //    multiRowInsert.AddColumnData("");
                    //}

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc locations
            multiRowInsert.UpdateParameters("mapstate_activenpc_location", new string[] { "MapID", "MapNpcSlot", "X", "Y", "Direction" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0) {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.X, npc.Y, (int)npc.Direction);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc stats
            multiRowInsert.UpdateParameters("mapstate_activenpc_stats", new string[] { "MapID", "MapNpcSlot", "IQ", "HP", "HPRemainder",
                "MaxHPBonus", "AtkBonus", "DefBonus",
                "SpdBonus", "SpclAtkBonus", "SpclDefBonus",
                "AttackBuff", "DefenseBuff", "SpAtkBuff", "SpDefBuff", "SpeedBuff", "AccuracyBuff", "EvasionBuff" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0) {
                    multiRowInsert.AddRowOpening();

                    multiRowInsert.AddColumnData(mapID);
                    multiRowInsert.AddColumnData(i);
                    multiRowInsert.AddColumnData(npc.IQ, npc.HP, npc.HPRemainder,
                        npc.MaxHPBonus, npc.AtkBonus, npc.DefBonus,
                        npc.SpdBonus, npc.SpclAtkBonus, npc.SpclDefBonus,
                        npc.AttackBuff, npc.DefenseBuff, npc.SpAtkBuff, npc.SpDefBuff,
                        npc.SpeedBuff, npc.AccuracyBuff, npc.EvasionBuff);

                    multiRowInsert.AddRowClosing();
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc moves
            multiRowInsert.UpdateParameters("mapstate_activenpc_moves", new string[] { "MapID", "MapNpcSlot", "MoveSlot", "CurrentPP", "MaxPP", "MoveNum" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0) {
                    for (int n = 0; n < npc.Moves.Length; n++) {
                        if (npc.Moves[n].MoveNum > 0) {
                            multiRowInsert.AddRowOpening();

                            multiRowInsert.AddColumnData(mapID);
                            multiRowInsert.AddColumnData(i, n);
                            multiRowInsert.AddColumnData(npc.Moves[n].CurrentPP, npc.Moves[n].MaxPP, npc.Moves[n].MoveNum);
                            //multiRowInsert.AddColumnData(npc.Moves[n].Sealed.ToIntString());

                            multiRowInsert.AddRowClosing();
                        }
                    }
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc mobility
            //multiRowInsert.UpdateParameters("mapstate_activenpc_mobility", new string[] { "MapID", "MapNpcSlot", "MobilitySlot", "Mobile" });
            //for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
            //    MapNpc npc = mapDump.ActiveNpc[i];

            //    for (int n = 0; n < npc.Mobility.Length; n++) {
            //        multiRowInsert.AddRowOpening();

            //        multiRowInsert.AddColumnData(mapID);
            //        multiRowInsert.AddColumnData(i, n);
            //        multiRowInsert.AddColumnData(npc.Mobility[n].ToIntString());

            //        multiRowInsert.AddRowClosing();
            //    }
            //}
            //database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save active npc volatile status
            multiRowInsert.UpdateParameters("mapstate_activenpc_volatilestatus", new string[] { "MapID", "MapNpcSlot", "StatusIndex", "Name", "Emoticon", "Counter", "Tag" });
            for (int i = 0; i < mapDump.ActiveNpc.Length; i++) {
                MapNpc npc = mapDump.ActiveNpc[i];
                if (mapDump.ActiveNpc[i].Num > 0) {
                    for (int n = 0; n < npc.VolatileStatus.Count; n++) {
                        multiRowInsert.AddRowOpening();

                        multiRowInsert.AddColumnData(mapID);
                        multiRowInsert.AddColumnData(i, n);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Name);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Emoticon);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Counter);
                        multiRowInsert.AddColumnData(npc.VolatileStatus[n].Tag);

                        multiRowInsert.AddRowClosing();
                    }
                }
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            // Save map status
            multiRowInsert.UpdateParameters("mapstate_mapstatus", new string[] { "MapID", "StatusIndex", "Name", "Tag", "GraphicEffect", "Counter" });
            for (int i = 0; i < mapDump.TempStatus.Count; i++) {
                MapStatus status = mapDump.TempStatus[i];

                multiRowInsert.AddRowOpening();

                multiRowInsert.AddColumnData(mapID);
                multiRowInsert.AddColumnData(i);
                multiRowInsert.AddColumnData(status.Name);
                multiRowInsert.AddColumnData(status.Tag);
                multiRowInsert.AddColumnData(status.GraphicEffect);
                multiRowInsert.AddColumnData(status.Counter);

                multiRowInsert.AddRowClosing();
            }
            database.ExecuteNonQuery(multiRowInsert.GetSqlQuery());

            if (localTransaction) {
                database.EndTransaction();
            }
        }