Beispiel #1
0
        public static void LoadMapDump(MySql database, string mapID, MapDump mapDump)
        {
            // First, load the raw map data
            LoadRawMap(database, mapID, mapDump);

            mapID = database.VerifyValueString(mapID);

            // Load map state data
            string query = "SELECT mapstate_data.ActivationTime, mapstate_data.ProcessingPaused, mapstate_data.SpawnMarker, " +
                           "mapstate_data.NpcSpawnWait, mapstate_data.TempChange, mapstate_data.CurrentWeather " +
                           "FROM mapstate_data WHERE mapstate_data.MapID = \'" + mapID + "\'";;

            {
                DataColumnCollection row = database.RetrieveRow(query);
                if (row != null)
                {
                    int counter = 0;
                    mapDump.ActivationTime   = Convert.ToInt32(row[counter++].Value);
                    mapDump.ProcessingPaused = row[counter++].ValueString.ToBool();
                    mapDump.SpawnMarker      = Convert.ToInt32(row[counter++].Value);
                    mapDump.NpcSpawnWait     = Convert.ToInt32(row[counter++].Value);
                    mapDump.TempChange       = row[counter++].ValueString.ToBool();
                    mapDump.CurrentWeather   = Convert.ToByte(row[counter++].Value);
                }
                else
                {
                    throw new Exception("Map state data not found");
                }
            }


            { // Load map active items
                query = "SELECT mapstate_activeitem.Slot, mapstate_activeitem.Number, mapstate_activeitem.Value, mapstate_activeitem.Sticky, " +
                        "mapstate_activeitem.Tag, mapstate_activeitem.Hidden, mapstate_activeitem.X, mapstate_activeitem.Y, " +
                        "mapstate_activeitem.TimeRemaining, mapstate_activeitem.ItemOwner " +
                        "FROM mapstate_activeitem WHERE mapstate_activeitem.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
                {
                    MapItem mapItem = new MapItem();
                    int     counter = 0;
                    int     slot    = Convert.ToInt32(row[counter++].Value);
                    mapItem.Num           = Convert.ToInt32(row[counter++].Value);
                    mapItem.Value         = Convert.ToInt32(row[counter++].Value);
                    mapItem.Sticky        = row[counter++].ValueString.ToBool();
                    mapItem.Tag           = row[counter++].ValueString;
                    mapItem.Hidden        = row[counter++].ValueString.ToBool();
                    mapItem.X             = Convert.ToInt32(row[counter++].Value);
                    mapItem.Y             = Convert.ToInt32(row[counter++].Value);
                    mapItem.TimeRemaining = Convert.ToInt32(row[counter++].Value);
                    mapItem.PlayerFor     = row[counter++].ValueString;

                    mapDump.ActiveItem[slot] = mapItem;
                }
            }

            { // Load map active npcs
                query = "SELECT mapstate_activenpc_data.MapNpcSlot, mapstate_activenpc_data.Name, mapstate_activenpc_data.Shiny, mapstate_activenpc_data.Form, " +
                        "mapstate_activenpc_data.Level, mapstate_activenpc_data.NpcNumber, mapstate_activenpc_data.Sex, " +
                        "mapstate_activenpc_data.AttackTimer, mapstate_activenpc_data.PauseTimer, mapstate_activenpc_data.StatusAilment, " +
                        "mapstate_activenpc_data.StatusAilmentCounter, mapstate_activenpc_data.HPStepCounter, " +
                        "mapstate_activenpc_data.Target, " +
                        "mapstate_activenpc_location.X, mapstate_activenpc_location.Y, mapstate_activenpc_location.Direction, " +
                        "mapstate_activenpc_stats.IQ, mapstate_activenpc_stats.HP, mapstate_activenpc_stats.HPRemainder, " +
                        "mapstate_activenpc_stats.MaxHPBonus, mapstate_activenpc_stats.AtkBonus, mapstate_activenpc_stats.DefBonus, " +
                        "mapstate_activenpc_stats.SpdBonus, mapstate_activenpc_stats.SpclAtkBonus, mapstate_activenpc_stats.SpclDefBonus, " +
                        "mapstate_activenpc_stats.AttackBuff, " +
                        "mapstate_activenpc_stats.DefenseBuff, mapstate_activenpc_stats.SpAtkBuff, mapstate_activenpc_stats.SpDefBuff, mapstate_activenpc_stats.SpeedBuff, " +
                        "mapstate_activenpc_stats.AccuracyBuff, mapstate_activenpc_stats.EvasionBuff " +
                        "FROM mapstate_activenpc_data " +
                        "LEFT OUTER JOIN mapstate_activenpc_location ON mapstate_activenpc_data.MapID = mapstate_activenpc_location.MapID AND mapstate_activenpc_data.MapNpcSlot = mapstate_activenpc_location.MapNpcSlot " +
                        "JOIN mapstate_activenpc_stats ON mapstate_activenpc_data.MapID = mapstate_activenpc_stats.MapID AND mapstate_activenpc_data.MapNpcSlot = mapstate_activenpc_stats.MapNpcSlot " +
                        "WHERE mapstate_activenpc_data.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
                {
                    int    counter = 0;
                    int    slot    = Convert.ToInt32(row[counter++].Value);
                    MapNpc npc     = new MapNpc(slot);
                    npc.Name  = row[counter++].ValueString;
                    npc.Shiny = Convert.ToByte(row[counter++].Value);
                    npc.Form  = Convert.ToInt32(row[counter++].Value);
                    npc.Level = Convert.ToInt32(row[counter++].Value);
                    npc.Num   = Convert.ToInt32(row[counter++].Value);
                    //npc.Sprite = Convert.ToInt32(row[counter++].Value);
                    npc.Sex = Convert.ToByte(row[counter++].Value);
                    //npc.Type1 = Convert.ToByte(row[counter++].Value);
                    //npc.Type2 = Convert.ToByte(row[counter++].Value);
                    //npc.Ability1 = row[counter++].ValueString;
                    //npc.Ability2 = row[counter++].ValueString;
                    //npc.Ability3 = row[counter++].ValueString;
                    //npc.TimeMultiplier = Convert.ToInt32(row[counter++].Value);
                    npc.AttackTimer          = Convert.ToInt32(row[counter++].Value);
                    npc.PauseTimer           = Convert.ToInt32(row[counter++].Value);
                    npc.StatusAilment        = Convert.ToByte(row[counter++].Value);
                    npc.StatusAilmentCounter = Convert.ToInt32(row[counter++].Value);
                    npc.HPStepCounter        = Convert.ToInt32(row[counter++].Value);
                    //npc.ConfusionStepCounter = Convert.ToInt32(row[counter++].Value);
                    //npc.SpeedLimit = Convert.ToByte(row[counter++].Value);
                    npc.Target = row[counter++].ValueString;
                    //npc.ItemActive = row[counter++].ValueString.ToBool();


                    // Load location data
                    npc.X         = Convert.ToInt32(row[counter++].Value);
                    npc.Y         = Convert.ToInt32(row[counter++].Value);
                    npc.Direction = Convert.ToByte(row[counter++].Value);

                    // Load stat data
                    npc.IQ          = Convert.ToInt32(row[counter++].Value);
                    npc.HP          = Convert.ToInt32(row[counter++].Value);
                    npc.HPRemainder = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseMaxHP = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseAtk = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseDef = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpd = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpclAtk = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpclDef = Convert.ToInt32(row[counter++].Value);
                    //npc.MaxHPBonus = Convert.ToInt32(row[counter++].Value);
                    npc.AtkBonus     = Convert.ToInt32(row[counter++].Value);
                    npc.DefBonus     = Convert.ToInt32(row[counter++].Value);
                    npc.SpdBonus     = Convert.ToInt32(row[counter++].Value);
                    npc.SpclAtkBonus = Convert.ToInt32(row[counter++].Value);
                    npc.SpclDefBonus = Convert.ToInt32(row[counter++].Value);
                    //npc.MaxHPBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.AtkBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.DefBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpdBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpclAtkBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpclDefBoost = Convert.ToInt32(row[counter++].Value);
                    npc.AttackBuff   = Convert.ToInt32(row[counter++].Value);
                    npc.DefenseBuff  = Convert.ToInt32(row[counter++].Value);
                    npc.SpAtkBuff    = Convert.ToInt32(row[counter++].Value);
                    npc.SpDefBuff    = Convert.ToInt32(row[counter++].Value);
                    npc.SpeedBuff    = Convert.ToInt32(row[counter++].Value);
                    npc.AccuracyBuff = Convert.ToInt32(row[counter++].Value);
                    npc.EvasionBuff  = Convert.ToInt32(row[counter++].Value);

                    mapDump.ActiveNpc[slot] = npc;
                }

                query = "SELECT mapstate_activenpc_helditem.MapNpcSlot, mapstate_activenpc_helditem.ItemNumber, mapstate_activenpc_helditem.Amount, " +
                        "mapstate_activenpc_helditem.Sticky, mapstate_activenpc_helditem.Tag " +
                        "FROM mapstate_activenpc_helditem " +
                        "WHERE mapstate_activenpc_helditem.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
                {
                    int    counter = 0;
                    int    slot    = Convert.ToInt32(row[counter++].Value);
                    MapNpc npc     = new MapNpc(slot);
                    // Load held item
                    {
                        int heldItemNum = Convert.ToInt32(row[counter++].Value);
                        if (heldItemNum > 0)
                        {
                            // The npc has a held item! Continue loading it
                            npc.HeldItem        = new Characters.InventoryItem();
                            npc.HeldItem.Num    = heldItemNum;
                            npc.HeldItem.Amount = Convert.ToInt32(row[counter++].Value);
                            npc.HeldItem.Sticky = row[counter++].ValueString.ToBool();
                            npc.HeldItem.Tag    = row[counter++].ValueString;
                        }
                        else
                        {
                            // No held item - skip loading the other values
                            npc.HeldItem = new Characters.InventoryItem();
                            counter     += 3;
                        }
                    }

                    mapDump.ActiveNpc[slot] = npc;
                }

                query = "SELECT mapstate_activenpc_moves.MapNpcSlot, mapstate_activenpc_moves.MoveSlot, mapstate_activenpc_moves.CurrentPP, " +
                        "mapstate_activenpc_moves.MaxPP, mapstate_activenpc_moves.MoveNum " +
                        "FROM mapstate_activenpc_moves WHERE mapstate_activenpc_moves.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
                {
                    int counter  = 0;
                    int slot     = Convert.ToInt32(row[counter++].Value);
                    int moveSlot = Convert.ToInt32(row[counter++].Value);

                    Characters.Move move = new Characters.Move();
                    move.CurrentPP = Convert.ToInt32(row[counter++].Value);
                    move.MaxPP     = Convert.ToInt32(row[counter++].Value);
                    move.MoveNum   = Convert.ToInt32(row[counter++].Value);
                    //move.Sealed = row[counter++].ValueString.ToBool();

                    mapDump.ActiveNpc[slot].Moves[moveSlot] = move;
                }

                //query = "SELECT mapstate_activenpc_mobility.MapNpcSlot, mapstate_activenpc_mobility.MobilitySlot, mapstate_activenpc_mobility.Mobile " +
                //   "FROM mapstate_activenpc_mobility WHERE mapstate_activenpc_mobility.MapID = \'" + mapID + "\'";
                //foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                //    int counter = 0;
                //    int slot = Convert.ToInt32(row[counter++].Value);
                //    int mobilitySlot = Convert.ToInt32(row[counter++].Value);

                //    mapDump.ActiveNpc[slot].Mobility[mobilitySlot] = row[counter++].ValueString.ToBool();
                //}

                query = "SELECT mapstate_activenpc_volatilestatus.MapNpcSlot, mapstate_activenpc_volatilestatus.Name, " +
                        "mapstate_activenpc_volatilestatus.Emoticon, mapstate_activenpc_volatilestatus.Counter, mapstate_activenpc_volatilestatus.Tag " +
                        "FROM mapstate_activenpc_volatilestatus WHERE mapstate_activenpc_volatilestatus.MapID = \'" + mapID + "\' ORDER BY mapstate_activenpc_volatilestatus.StatusIndex";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
                {
                    int counter = 0;
                    int slot    = Convert.ToInt32(row[counter++].Value);

                    Characters.VolatileStatus status = new Characters.VolatileStatus();
                    status.Name     = row[counter++].ValueString;
                    status.Emoticon = Convert.ToInt32(row[counter++].Value);
                    status.Counter  = Convert.ToInt32(row[counter++].ValueString);
                    status.Tag      = row[counter++].ValueString;

                    mapDump.ActiveNpc[slot].VolatileStatus.Add(status);
                }
            }

            // Load map status
            query = "SELECT mapstate_mapstatus.StatusIndex, mapstate_mapstatus.Name, mapstate_mapstatus.Tag, mapstate_mapstatus.GraphicEffect, mapstate_mapstatus.Tag, mapstate_mapstatus.Counter " +
                    "FROM mapstate_mapstatus WHERE mapstate_mapstatus.MapID = \'" + mapID + "\' ORDER BY mapstate_mapstatus.StatusIndex";
            foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query))
            {
                MapStatus status  = new MapStatus();
                int       counter = 1;

                status.Name          = row[counter++].ValueString;
                status.Tag           = row[counter++].ValueString;
                status.GraphicEffect = Convert.ToInt32(row[counter++].ValueString);
                status.Counter       = Convert.ToInt32(row.FindByName("Counter").Value);

                mapDump.TempStatus.Add(status);
            }
        }
Beispiel #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();
            }
        }
Beispiel #3
0
        public static void LoadMapDump(MySql database, string mapID, MapDump mapDump)
        {
            // First, load the raw map data
            LoadRawMap(database, mapID, mapDump);

            mapID = database.VerifyValueString(mapID);

            // Load map state data
            string query = "SELECT mapstate_data.ActivationTime, mapstate_data.ProcessingPaused, mapstate_data.SpawnMarker, " +
                "mapstate_data.NpcSpawnWait, mapstate_data.TempChange, mapstate_data.CurrentWeather " +
                "FROM mapstate_data WHERE mapstate_data.MapID = \'" + mapID + "\'"; ;
            {
                DataColumnCollection row = database.RetrieveRow(query);
                if (row != null) {
                    int counter = 0;
                    mapDump.ActivationTime = Convert.ToInt32(row[counter++].Value);
                    mapDump.ProcessingPaused = row[counter++].ValueString.ToBool();
                    mapDump.SpawnMarker = Convert.ToInt32(row[counter++].Value);
                    mapDump.NpcSpawnWait = Convert.ToInt32(row[counter++].Value);
                    mapDump.TempChange = row[counter++].ValueString.ToBool();
                    mapDump.CurrentWeather = Convert.ToByte(row[counter++].Value);
                } else {
                    throw new Exception("Map state data not found");
                }
            }

            { // Load map active items
                query = "SELECT mapstate_activeitem.Slot, mapstate_activeitem.Number, mapstate_activeitem.Value, mapstate_activeitem.Sticky, " +
                   "mapstate_activeitem.Tag, mapstate_activeitem.Hidden, mapstate_activeitem.X, mapstate_activeitem.Y, " +
                   "mapstate_activeitem.TimeRemaining, mapstate_activeitem.ItemOwner " +
                   "FROM mapstate_activeitem WHERE mapstate_activeitem.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                    MapItem mapItem = new MapItem();
                    int counter = 0;
                    int slot = Convert.ToInt32(row[counter++].Value);
                    mapItem.Num = Convert.ToInt32(row[counter++].Value);
                    mapItem.Value = Convert.ToInt32(row[counter++].Value);
                    mapItem.Sticky = row[counter++].ValueString.ToBool();
                    mapItem.Tag = row[counter++].ValueString;
                    mapItem.Hidden = row[counter++].ValueString.ToBool();
                    mapItem.X = Convert.ToInt32(row[counter++].Value);
                    mapItem.Y = Convert.ToInt32(row[counter++].Value);
                    mapItem.TimeRemaining = Convert.ToInt32(row[counter++].Value);
                    mapItem.PlayerFor = row[counter++].ValueString;

                    mapDump.ActiveItem[slot] = mapItem;
                }
            }

            { // Load map active npcs
                query = "SELECT mapstate_activenpc_data.MapNpcSlot, mapstate_activenpc_data.Name, mapstate_activenpc_data.Shiny, mapstate_activenpc_data.Form, " +
                   "mapstate_activenpc_data.Level, mapstate_activenpc_data.NpcNumber, mapstate_activenpc_data.Sex, " +
                   "mapstate_activenpc_data.AttackTimer, mapstate_activenpc_data.PauseTimer, mapstate_activenpc_data.StatusAilment, " +
                   "mapstate_activenpc_data.StatusAilmentCounter, mapstate_activenpc_data.HPStepCounter, " +
                   "mapstate_activenpc_data.Target, " +
                   "mapstate_activenpc_location.X, mapstate_activenpc_location.Y, mapstate_activenpc_location.Direction, " +
                   "mapstate_activenpc_stats.IQ, mapstate_activenpc_stats.HP, mapstate_activenpc_stats.HPRemainder, " +
                   "mapstate_activenpc_stats.MaxHPBonus, mapstate_activenpc_stats.AtkBonus, mapstate_activenpc_stats.DefBonus, " +
                   "mapstate_activenpc_stats.SpdBonus, mapstate_activenpc_stats.SpclAtkBonus, mapstate_activenpc_stats.SpclDefBonus, " +
                   "mapstate_activenpc_stats.AttackBuff, " +
                   "mapstate_activenpc_stats.DefenseBuff, mapstate_activenpc_stats.SpAtkBuff, mapstate_activenpc_stats.SpDefBuff, mapstate_activenpc_stats.SpeedBuff, " +
                   "mapstate_activenpc_stats.AccuracyBuff, mapstate_activenpc_stats.EvasionBuff " +
                   "FROM mapstate_activenpc_data " +
                   "LEFT OUTER JOIN mapstate_activenpc_location ON mapstate_activenpc_data.MapID = mapstate_activenpc_location.MapID AND mapstate_activenpc_data.MapNpcSlot = mapstate_activenpc_location.MapNpcSlot " +
                   "JOIN mapstate_activenpc_stats ON mapstate_activenpc_data.MapID = mapstate_activenpc_stats.MapID AND mapstate_activenpc_data.MapNpcSlot = mapstate_activenpc_stats.MapNpcSlot " +
                   "WHERE mapstate_activenpc_data.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                    int counter = 0;
                    int slot = Convert.ToInt32(row[counter++].Value);
                    MapNpc npc = new MapNpc(slot);
                    npc.Name = row[counter++].ValueString;
                    npc.Shiny = Convert.ToByte(row[counter++].Value);
                    npc.Form = Convert.ToInt32(row[counter++].Value);
                    npc.Level = Convert.ToInt32(row[counter++].Value);
                    npc.Num = Convert.ToInt32(row[counter++].Value);
                    //npc.Sprite = Convert.ToInt32(row[counter++].Value);
                    npc.Sex = Convert.ToByte(row[counter++].Value);
                    //npc.Type1 = Convert.ToByte(row[counter++].Value);
                    //npc.Type2 = Convert.ToByte(row[counter++].Value);
                    //npc.Ability1 = row[counter++].ValueString;
                    //npc.Ability2 = row[counter++].ValueString;
                    //npc.Ability3 = row[counter++].ValueString;
                    //npc.TimeMultiplier = Convert.ToInt32(row[counter++].Value);
                    npc.AttackTimer = Convert.ToInt32(row[counter++].Value);
                    npc.PauseTimer = Convert.ToInt32(row[counter++].Value);
                    npc.StatusAilment = Convert.ToByte(row[counter++].Value);
                    npc.StatusAilmentCounter = Convert.ToInt32(row[counter++].Value);
                    npc.HPStepCounter = Convert.ToInt32(row[counter++].Value);
                    //npc.ConfusionStepCounter = Convert.ToInt32(row[counter++].Value);
                    //npc.SpeedLimit = Convert.ToByte(row[counter++].Value);
                    npc.Target = row[counter++].ValueString;
                    //npc.ItemActive = row[counter++].ValueString.ToBool();

                    // Load location data
                    npc.X = Convert.ToInt32(row[counter++].Value);
                    npc.Y = Convert.ToInt32(row[counter++].Value);
                    npc.Direction = Convert.ToByte(row[counter++].Value);

                    // Load stat data
                    npc.IQ = Convert.ToInt32(row[counter++].Value);
                    npc.HP = Convert.ToInt32(row[counter++].Value);
                    npc.HPRemainder = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseMaxHP = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseAtk = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseDef = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpd = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpclAtk = Convert.ToInt32(row[counter++].Value);
                    //npc.BaseSpclDef = Convert.ToInt32(row[counter++].Value);
                    //npc.MaxHPBonus = Convert.ToInt32(row[counter++].Value);
                    npc.AtkBonus = Convert.ToInt32(row[counter++].Value);
                    npc.DefBonus = Convert.ToInt32(row[counter++].Value);
                    npc.SpdBonus = Convert.ToInt32(row[counter++].Value);
                    npc.SpclAtkBonus = Convert.ToInt32(row[counter++].Value);
                    npc.SpclDefBonus = Convert.ToInt32(row[counter++].Value);
                    //npc.MaxHPBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.AtkBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.DefBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpdBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpclAtkBoost = Convert.ToInt32(row[counter++].Value);
                    //npc.SpclDefBoost = Convert.ToInt32(row[counter++].Value);
                    npc.AttackBuff = Convert.ToInt32(row[counter++].Value);
                    npc.DefenseBuff = Convert.ToInt32(row[counter++].Value);
                    npc.SpAtkBuff = Convert.ToInt32(row[counter++].Value);
                    npc.SpDefBuff = Convert.ToInt32(row[counter++].Value);
                    npc.SpeedBuff = Convert.ToInt32(row[counter++].Value);
                    npc.AccuracyBuff = Convert.ToInt32(row[counter++].Value);
                    npc.EvasionBuff = Convert.ToInt32(row[counter++].Value);

                    mapDump.ActiveNpc[slot] = npc;
                }

                query = "SELECT mapstate_activenpc_helditem.MapNpcSlot, mapstate_activenpc_helditem.ItemNumber, mapstate_activenpc_helditem.Amount, " +
                   "mapstate_activenpc_helditem.Sticky, mapstate_activenpc_helditem.Tag " +
                   "FROM mapstate_activenpc_helditem " +
                   "WHERE mapstate_activenpc_helditem.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                    int counter = 0;
                    int slot = Convert.ToInt32(row[counter++].Value);
                    MapNpc npc = new MapNpc(slot);
                    // Load held item
                    {
                        int heldItemNum = Convert.ToInt32(row[counter++].Value);
                        if (heldItemNum > 0) {
                            // The npc has a held item! Continue loading it
                            npc.HeldItem = new Characters.InventoryItem();
                            npc.HeldItem.Num = heldItemNum;
                            npc.HeldItem.Amount = Convert.ToInt32(row[counter++].Value);
                            npc.HeldItem.Sticky = row[counter++].ValueString.ToBool();
                            npc.HeldItem.Tag = row[counter++].ValueString;
                        } else {
                            // No held item - skip loading the other values
                            npc.HeldItem = new Characters.InventoryItem();
                            counter += 3;
                        }
                    }

                    mapDump.ActiveNpc[slot] = npc;
                }

                query = "SELECT mapstate_activenpc_moves.MapNpcSlot, mapstate_activenpc_moves.MoveSlot, mapstate_activenpc_moves.CurrentPP, " +
                    "mapstate_activenpc_moves.MaxPP, mapstate_activenpc_moves.MoveNum " +
                    "FROM mapstate_activenpc_moves WHERE mapstate_activenpc_moves.MapID = \'" + mapID + "\'";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                    int counter = 0;
                    int slot = Convert.ToInt32(row[counter++].Value);
                    int moveSlot = Convert.ToInt32(row[counter++].Value);

                    Characters.Move move = new Characters.Move();
                    move.CurrentPP = Convert.ToInt32(row[counter++].Value);
                    move.MaxPP = Convert.ToInt32(row[counter++].Value);
                    move.MoveNum = Convert.ToInt32(row[counter++].Value);
                    //move.Sealed = row[counter++].ValueString.ToBool();

                    mapDump.ActiveNpc[slot].Moves[moveSlot] = move;
                }

                //query = "SELECT mapstate_activenpc_mobility.MapNpcSlot, mapstate_activenpc_mobility.MobilitySlot, mapstate_activenpc_mobility.Mobile " +
                //   "FROM mapstate_activenpc_mobility WHERE mapstate_activenpc_mobility.MapID = \'" + mapID + "\'";
                //foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                //    int counter = 0;
                //    int slot = Convert.ToInt32(row[counter++].Value);
                //    int mobilitySlot = Convert.ToInt32(row[counter++].Value);

                //    mapDump.ActiveNpc[slot].Mobility[mobilitySlot] = row[counter++].ValueString.ToBool();
                //}

                query = "SELECT mapstate_activenpc_volatilestatus.MapNpcSlot, mapstate_activenpc_volatilestatus.Name, " +
                    "mapstate_activenpc_volatilestatus.Emoticon, mapstate_activenpc_volatilestatus.Counter, mapstate_activenpc_volatilestatus.Tag " +
                    "FROM mapstate_activenpc_volatilestatus WHERE mapstate_activenpc_volatilestatus.MapID = \'" + mapID + "\' ORDER BY mapstate_activenpc_volatilestatus.StatusIndex";
                foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                    int counter = 0;
                    int slot = Convert.ToInt32(row[counter++].Value);

                    Characters.VolatileStatus status = new Characters.VolatileStatus();
                    status.Name = row[counter++].ValueString;
                    status.Emoticon = Convert.ToInt32(row[counter++].Value);
                    status.Counter = Convert.ToInt32(row[counter++].ValueString);
                    status.Tag = row[counter++].ValueString;

                    mapDump.ActiveNpc[slot].VolatileStatus.Add(status);
                }

            }

            // Load map status
            query = "SELECT mapstate_mapstatus.StatusIndex, mapstate_mapstatus.Name, mapstate_mapstatus.Tag, mapstate_mapstatus.GraphicEffect, mapstate_mapstatus.Tag, mapstate_mapstatus.Counter " +
                "FROM mapstate_mapstatus WHERE mapstate_mapstatus.MapID = \'" + mapID + "\' ORDER BY mapstate_mapstatus.StatusIndex";
            foreach (DataColumnCollection row in database.RetrieveRowsEnumerable(query)) {
                MapStatus status = new MapStatus();
                int counter = 1;

                status.Name = row[counter++].ValueString;
                status.Tag = row[counter++].ValueString;
                status.GraphicEffect = Convert.ToInt32(row[counter++].ValueString);
                status.Counter = Convert.ToInt32(row.FindByName("Counter").Value);

                mapDump.TempStatus.Add(status);
            }
        }