Exemplo n.º 1
0
        /// <summary>
        /// Loads all the revive spots.
        /// </summary>
        /// <returns>Returns true if the revive spots were loaded.</returns>
        public static bool LoadReviveSpots()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Revive Spots...");
            using (var revive = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(revive, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_ReviveSpots");
                }
                while (revive.Read())
                {
                    Maps.MapPoint revivepoint = new ProjectX_V3_Game.Maps.MapPoint(revive.ReadUInt16("ReviveTargetMapID"), revive.ReadUInt16("ReviveX"), revive.ReadUInt16("ReviveY"));

                    ushort frommap = revive.ReadUInt16("ReviveMapID");
                    if (!Core.Kernel.Maps.Contains(frommap))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load revive spots. Failed at map: {0}, perhaps the map is not existing.", revivepoint.MapID);
                        Console.ResetColor();
                        return false;
                    }
                    Core.Kernel.Maps[frommap].RevivePoint = revivepoint;
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded Revive Spots...");
            return true;
        }
Exemplo n.º 2
0
        public static void LoadBots()
        {
            #if SPAWN_BOTS

            #region AfkBots
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_BotInfo");
                }
                while (sql.Read())
                {
                    Entities.AIBot bot = new ProjectX_V3_Game.Entities.AIBot();
                    bot.LoadBot(Enums.BotType.AFKBot,
                                sql.ReadInt32("BotRefID"),
                                new Maps.MapPoint(
                                    sql.ReadUInt16("BotMapID"),
                                    sql.ReadUInt16("BotX"),
                                    sql.ReadUInt16("BotY")),
                                null);
                }
            }
            #endregion

            #endif
        }
Exemplo n.º 3
0
 public static bool LoadNobilityBoard()
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
         {
             cmd.Finish("DB_NobilityBoard");
         }
         while (sql.Read())
         {
             Data.NobilityDonation donation = new ProjectX_V3_Game.Data.NobilityDonation();
             donation.DatabaseID = sql.ReadInt32("PlayerID");
             donation.Name = sql.ReadString("PlayerName");
             donation.Donation = sql.ReadInt64("NobilityDonation");
             donation.Rank = Enums.NobilityRank.Serf;
             donation.OldRank = donation.Rank;
             donation.RecordID = sql.ReadInt32("NobilityID");
             if (!Data.NobilityBoard.AddNobility(donation))
             {
                 return false;
             }
         }
     }
     Data.NobilityBoard.GetTop50();
     return true;
 }
Exemplo n.º 4
0
        public static void AddNewArenaInfo(Data.ArenaInfo arena)
        {
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                {
                    cmd.AddInsertValue("PlayerID", arena.DatabaseID);
                    cmd.AddInsertValue("PlayerName", arena.Name);
                    cmd.AddInsertValue("ArenaLevel", arena.Level);
                    cmd.AddInsertValue("ArenaClass", arena.Class);
                    cmd.AddInsertValue("Mesh", arena.Mesh);
                    cmd.AddInsertValue("HonorPoints", arena.DatabaseID);
                    cmd.AddInsertValue("ArenaPoints", arena.ArenaPoints);
                    cmd.AddInsertValue("TotalWins", arena.ArenaTotalWins);
                    cmd.AddInsertValue("TotalWinsToday", arena.ArenaWinsToday);
                    cmd.AddInsertValue("TotalLoss", arena.ArenaTotalLoss);
                    cmd.AddInsertValue("TotalLossToday", arena.ArenaLossToday);
                    cmd.AddInsertValue("TodayUpdate", DateTime.Now);
                    cmd.Finish("DB_ArenaQualifier");
                }
                sql.Execute();
            }

            SetRecordID(arena);
        }
Exemplo n.º 5
0
 public static void UpdateNobilityDonation(int Identifier, string Column, object Value)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
         {
             cmd.AddWhereValue("PlayerID", Identifier);
             cmd.AddUpdateValue(Column, Value);
             cmd.Finish("DB_NobilityBoard");
         }
         sql.Execute();
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Loads all the drop data.
        /// </summary>
        /// <returns>Returns true if the drops were loaded.</returns>
        public static bool LoadDropData()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Drops...");

            using (var drop = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(drop, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MapDrops");
                }
                while (drop.Read())
                {
                    int dropid = drop.ReadInt32("MapID");
                    Data.DropData data = new ProjectX_V3_Game.Data.DropData();
                    data.MinGoldDrop = drop.ReadUInt32("MinMoney");
                    data.MaxGoldDrop = drop.ReadUInt32("MaxMoney");
                    data.CPsDropChance = drop.ReadByte("CPsChance");
                    data.MinCPsDrop = drop.ReadUInt32("MinCPs");
                    data.MaxCPsDrop = drop.ReadUInt32("MaxCPs");
                    data.DragonballChance = drop.ReadByte("DragonballChance");
                    data.MeteorChance = drop.ReadByte("MeteorChance");
                    data.FirstSocketChance = drop.ReadByte("FirstSocketChance");
                    data.SecondSocketChance = drop.ReadByte("SecondSocketChance");
                    data.PlusChance = drop.ReadByte("PlusChance");
                    data.QualityChance = drop.ReadByte("QualityChance");
                    data.MinPlus = drop.ReadByte("MinPlus");
                    data.MaxPlus = drop.ReadByte("MaxPlus");
                    data.BlessChance = drop.ReadByte("BlessChance");
                    foreach (string item in drop.ReadString("ItemList").Split('-'))
                    {
                        if (!string.IsNullOrWhiteSpace(item))
                        {
                            data.ItemDrops.Add(uint.Parse(item));
                        }
                    }

                    if (!Core.Kernel.DropData.TryAdd(dropid, data))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load drops. Failed at ID: {0}", dropid);
                        Console.ResetColor();
                        return false;
                    }
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Drops...", Core.Kernel.DropData.Count);
            return true;
        }
Exemplo n.º 7
0
 public static void AddNewNobility(int Identifier, string Name, long Donation)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
         {
             cmd.AddInsertValue("PlayerID", Identifier);
             cmd.AddInsertValue("PlayerName", Name);
             cmd.AddInsertValue("NobilityDonation", Donation);
             cmd.Finish("DB_NobilityBoard");
         }
         sql.Execute();
     }
 }
Exemplo n.º 8
0
        public static Enums.AccountStatus Authenticate(Client.AuthClient client, string Account, string Password)
        {
            try
            {
                using (var sql = new SqlHandler(Program.Config.ReadString("AuthConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
                    {
                        cmd.AddWhereValue("AccountName", Account);
                        cmd.AddWhereValue("AccountPassword", Password);

                        cmd.Finish("DB_Accounts");
                    }

                    if (!sql.Read())
                        return Enums.AccountStatus.Invalid_AccountID_Or_Password;
                    client.DatabaseUID = sql.ReadInt32("AccountID");
                    client.Server = sql.ReadByte("AccountServer");
                    client.Account = Account;
                    client.Password = Password;
                    using (var sql2 = new SqlHandler(Program.Config.ReadString("AuthConnectionString")))
                    {
                        using (var cmd2 = new SqlCommandBuilder(sql2, SqlCommandType.UPDATE, true))
                        {
                            cmd2.AddWhereValue("AccountID", client.DatabaseUID);
                            if (sql.ReadBoolean("AccountBanned"))
                            {
                                DateTime banexpire = sql.ReadDateTime("AccountBanExpire");
                                if (DateTime.Now < banexpire)
                                    return Enums.AccountStatus.Account_Banned;

                                cmd2.AddUpdateValue("AccountBanned", false);
                            }

                            cmd2.AddUpdateValue("AccountLastLoginIP", client.NetworkClient.IP);
                            cmd2.Finish("DB_Accounts");
                        }
                        sql2.Execute();
                    }
                }
                return Enums.AccountStatus.Ready;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return Enums.AccountStatus.Datebase_Error;
            }
        }
Exemplo n.º 9
0
        public static void AddNewMonsterSpawn(ushort mapid, ushort x, ushort y, int monsterid, int count, int drop, int range, bool guard)
        {
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                {
                    cmd.AddInsertValue("MonsterID", monsterid);
                    cmd.AddInsertValue("CenterX", x);
                    cmd.AddInsertValue("CenterY", y);
                    cmd.AddInsertValue("Drop", drop);
                    cmd.AddInsertValue("Count", count);
                    if (guard)
                        cmd.AddInsertValue("Range", (int)1);
                    else
                        cmd.AddInsertValue("Range", range);
                    cmd.Finish("DB_MobSpawns");
                }
                sql.Execute();
            }

            for (int i = 0; i < count; i++)
            {
                Entities.Monster spawnmob = Core.Kernel.Monsters[monsterid].Copy();
                spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8);
                if (Core.Kernel.Maps[mapid].EnterMap(spawnmob))
                {
                    Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation<Entities.Monster>(x, y, range);
                    if (Location != null)
                    {
                        spawnmob.X = Location.X;
                        spawnmob.Y = Location.Y;
                        spawnmob.OriginalRange = range;
                        spawnmob.OriginalX = x;
                        spawnmob.OriginalY = y;

                        //if (drop > 0)
                        //{
                        //	spawnmob.DropData = Core.Kernel.DropData[drop].Copy();
                        //}

                        Threads.MonsterThread.AddToMonsterThread(spawnmob, !(((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard));

                        spawnmob.Screen.UpdateScreen(null);
                    }
                }
            }
        }
Exemplo n.º 10
0
 public static bool LoadSystemVariables()
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
         {
             cmd.Finish("DB_SystemVariables");
         }
         while (sql.Read())
         {
             if (!Core.SystemVariables.Variables.TryAdd(sql.ReadString("SystemVariableName"), sql.ReadString("SystemVariableValue")))
             {
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 11
0
        public static void SetRecordID(Entities.GameClient client)
        {
            if (client.Nobility == null)
                return;

            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
                {
                    cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                    cmd.Finish("DB_NobilityBoard");
                }
                if (sql.Read())
                {
                    client.Nobility.RecordID = sql.ReadInt32("NobilityID");
                }
            }
        }
Exemplo n.º 12
0
        public static bool LoadArenaQualifiers()
        {
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_ArenaQualifier");
                }
                while (sql.Read())
                {
                    Data.ArenaInfo arena = new ProjectX_V3_Game.Data.ArenaInfo();
                    arena.ArenaID = sql.ReadInt32("ArenaID");
                    arena.DatabaseID = sql.ReadInt32("PlayerID");
                    arena.Level = sql.ReadUInt32("ArenaLevel");
                    arena.Class = sql.ReadUInt32("ArenaClass");
                    arena.Name = sql.ReadString("PlayerName");
                    arena.Mesh = sql.ReadUInt32("Mesh");
                    arena.ArenaTotalWins = sql.ReadUInt32("TotalWins");
                    arena.ArenaWinsToday = sql.ReadUInt32("TotalWinsToday");
                    arena.ArenaTotalLoss = sql.ReadUInt32("TotalLoss");
                    arena.ArenaLossToday = sql.ReadUInt32("TotalLossToday");
                    arena.ArenaPoints = sql.ReadUInt32("ArenaPoints");
                    arena.ArenaHonorPoints = sql.ReadUInt32("HonorPoints");

                    DateTime dailyupdate = sql.ReadDateTime("TodayUpdate");

                    if (DateTime.Now >= dailyupdate.AddHours(24))
                    {
                        UpdateArenaInfo(arena.DatabaseID, "TodayUpdate", DateTime.Now);
                        arena.ArenaLossToday = 0;
                        arena.ArenaWinsToday = 0;
                        arena.Save();
                    }
                    if (!Data.ArenaQualifier.AddArenaInfo(arena))
                    {
                        return false;
                    }
                }
            }
            Data.ArenaQualifier.GetTop10();
            Data.ArenaQualifier.GetTop10();
            return true;
        }
Exemplo n.º 13
0
 public static bool LoadPortals()
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
         {
             cmd.Finish("DB_Portals");
         }
         while (sql.Read())
         {
             if (!Core.Kernel.Portals.TryAdd(
                 new Core.PortalPoint(sql.ReadUInt16("StartMap"), sql.ReadUInt16("StartX"), sql.ReadUInt16("StartY")),
                 new Core.PortalPoint(sql.ReadUInt16("EndMap"), sql.ReadUInt16("EndX"), sql.ReadUInt16("EndY"))))
             {
                 return false;
             }
         }
     }
     return true;
 }
Exemplo n.º 14
0
        public static void AddSpouse(Entities.GameClient client1, Entities.GameClient client2)
        {
            client1.SpouseDatabaseUID = client2.DatabaseUID;
            client2.SpouseDatabaseUID = client1.DatabaseUID;

            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                {
                    cmd.AddWhereValue("PlayerID", client1.DatabaseUID);
                    cmd.AddUpdateValue("PlayerSpouseID", client2.DatabaseUID);
                    cmd.Finish("DB_Players");
                }
                sql.Execute();
                sql.Forward(Program.Config.ReadString("GameConnectionString"), "");
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                {
                    cmd.AddWhereValue("PlayerID", client2.DatabaseUID);
                    cmd.AddUpdateValue("PlayerSpouseID", client1.DatabaseUID);
                    cmd.Finish("DB_Players");
                }
                sql.Execute();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Loads all the shopflag informations and spawns.
        /// </summary>
        /// <returns>Returns true if the the infos/spawns were loaded.</returns>
        public static bool LoadShopFlags()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading ShopFlags...");
            int NpcCount = Core.Kernel.NPCs.Count;
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_ShopFlags");
                }
                while (sql.Read())
                {
                    Entities.NPC npc = new ProjectX_V3_Game.Entities.NPC();
                    npc.EntityUID = sql.ReadUInt32("ShopFlagID");
                    ushort mapid = sql.ReadUInt16("ShopFlagMapID");
                    if (mapid == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load shopflags. [MAPID]");
                        Console.ResetColor();
                        return false;
                    }

                    Maps.Map map;
                    Core.Kernel.Maps.TrySelect(mapid, out map);
                    npc.Map = map;
                    if (!npc.Map.EnterMap(npc))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load shopflags. [MAP]");
                        Console.ResetColor();
                        return false;
                    }

                    npc.Mesh = sql.ReadUInt16("ShopFlagMesh");
                    npc.Flag = sql.ReadUInt32("ShopFlagFlag");
                    npc.Name = "";
                    npc.X = sql.ReadUInt16("ShopFlagX");
                    npc.Y = sql.ReadUInt16("ShopFlagY");
                    npc.NPCType = Enums.NPCType.ShopFlag;
                    npc.Avatar = 0;

                    if (!Core.Kernel.NPCs.TryAdd(npc.EntityUID, npc))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load shopflags. [ADD]");
                        Console.ResetColor();
                        return false;
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} ShopFlags...", (Core.Kernel.NPCs.Count - NpcCount));
            return true;
        }
Exemplo n.º 16
0
 public static void SaveGuildRank(int UID, Enums.GuildRank rank)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
         {
             cmd.AddWhereValue("PlayerID", UID);
             cmd.AddUpdateValue("PlayerGuildRank", rank.ToString());
             cmd.Finish("DB_Players");
         }
         sql.Execute();
     }
 }
Exemplo n.º 17
0
 public static bool CharacterExists(string Name)
 {
     try
     {
         using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
         {
             using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
             {
                 cmd.AddWhereValue("PlayerName", Name);
                 cmd.Finish("DB_Players");
             }
             return sql.Read();
         }
     }
     catch { return false; }
 }
Exemplo n.º 18
0
        // -1 = finished
        public static void SaveQuest(Entities.GameClient client, string Name, int Progress, string InfoString)
        {
            bool Exists = false;
            using (var existsql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var existcmd = new SqlCommandBuilder(existsql, SqlCommandType.SELECT, true))
                {
                    existcmd.AddWhereValue("PlayerID", client.DatabaseUID);
                    existcmd.AddWhereValue("QuestName", Name);
                    existcmd.Finish("DB_Quests");
                }
                Exists = existsql.Read();
            }

            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                if (Exists)
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.AddWhereValue("QuestName", Name);
                        cmd.AddUpdateValue("QuestProgress", Progress.ToString());
                        cmd.AddUpdateValue("QuestInfo", InfoString);
                        cmd.Finish("DB_Quests");
                    }
                }
                else
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                    {
                        cmd.AddInsertValue("PlayerID", client.DatabaseUID);
                        cmd.AddInsertValue("QuestName", Name);
                        cmd.AddInsertValue("QuestProgress", Progress.ToString());
                        cmd.AddInsertValue("QuestInfo", InfoString);
                        cmd.Finish("DB_Quests");
                    }
                }
                sql.Execute();
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Saves profs.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="prof">The prof.</param>
        public static void SaveProf(Entities.GameClient client, Data.SpellInfo prof)
        {
            if (!client.LoggedIn || client.IsAIBot)
                return;
            bool Exists = false;
            using (var existsql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var existcmd = new SqlCommandBuilder(existsql, SqlCommandType.SELECT, true))
                {
                    existcmd.AddWhereValue("PlayerID", client.DatabaseUID);
                    existcmd.AddWhereValue("Prof", prof.ID);
                    existcmd.Finish("DB_PlayerProfs");
                }
                Exists = existsql.Read();
            }

            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                if (Exists)
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.AddWhereValue("Prof", prof.ID);
                        cmd.AddUpdateValue("ProfLevel", prof.Level);
                        cmd.AddUpdateValue("ProfExperience", prof.Experience);
                        cmd.Finish("DB_PlayerProfs");
                    }
                }
                else
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                    {
                        cmd.AddInsertValue("PlayerID", client.DatabaseUID);
                        cmd.AddInsertValue("Prof", prof.ID);
                        cmd.AddInsertValue("ProfLevel", prof.Level);
                        cmd.AddInsertValue("ProfExperience", prof.Experience);
                        cmd.Finish("DB_PlayerProfs");
                    }
                }

                sql.Execute();
            }
        }
Exemplo n.º 20
0
        public static bool LoadMonsterSpawns()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            string wrt = "\tLoading Monster Spawns...";
            Console.WriteLine(wrt);
            int SpawnCount = 0;
            int GuardSpawnCount = 0;

            using (var spawn = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(spawn, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MobSpawns");
                }
                while (spawn.Read())
                {
                    ushort mapid = spawn.ReadUInt16("MapID");

                    Maps.Map map;
                    if (!Core.Kernel.Maps.TrySelect(mapid, out map))
                    {
                        return false;
                    }

                    ushort CenterX = spawn.ReadUInt16("CenterX");
                    ushort CenterY = spawn.ReadUInt16("CenterY");
                    int Range = spawn.ReadUInt16("Range");
                //	int DropData = spawn.ReadInt32("DropID");
                    int Monster = spawn.ReadInt32("MonsterID");
                    int MobCount = spawn.ReadInt32("Count");

                    if (CenterX > 0 && CenterY > 0 && Range > 0 && Monster > 0 && MobCount > 0)
                    {
                        for (int j = 0; j < MobCount; j++)
                        {
                            Entities.Monster spawnmob = Core.Kernel.Monsters[Monster].Copy();
                            spawnmob.MobID = Monster;
                            spawnmob.Direction = (byte)ProjectX_V3_Lib.ThreadSafe.RandomGenerator.Generator.Next(0, 8);
                            if (!map.EnterMap(spawnmob))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("[MAP] Failed to load spawns. Failed at Map: {0} and MobID: {1}", mapid, Monster);
                                Console.ResetColor();
                                return false;
                            }
                            Maps.MapPoint Location = spawnmob.Map.CreateAvailableLocation<Entities.Monster>(CenterX, CenterY, Range);
                            if (Location != null)
                            {
                                spawnmob.X = Location.X;
                                spawnmob.Y = Location.Y;
                                spawnmob.OriginalRange = Range;
                                spawnmob.OriginalX = CenterX;
                                spawnmob.OriginalY = CenterY;

                                spawnmob.DropData = Core.Kernel.DropData[map.MapID].Copy();

                                if (((byte)spawnmob.Behaviour) < 3 || spawnmob.Behaviour == Enums.MonsterBehaviour.PhysicalGuard) // physical guards should walk around
                                {
                                    #if SPAWN_MOBS
                                    Threads.MonsterThread.AddToMonsterThread(spawnmob, false);
                                    SpawnCount++;
                                    #endif
                                }
                                else
                                {
                                    Threads.MonsterThread.AddToMonsterThread(spawnmob, true);
                                    GuardSpawnCount++;
                                }
                            }
                            else
                                spawnmob.Map.LeaveMap(spawnmob); // there was no location available

                            Console.Clear();
                            Console.WriteLine(wrt);
                            Console.WriteLine("\tLoaded {0} Monster Spawns and {1} Guard Spawns...", SpawnCount, GuardSpawnCount);
                        }
                    }
                }
            }
            return true;
        }
Exemplo n.º 21
0
 public static void SaveArenaInfo(Data.ArenaInfo arena)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
         {
             cmd.AddWhereValue("PlayerID", arena.DatabaseID);
             cmd.AddUpdateValue("PlayerName", arena.Name);
             cmd.AddUpdateValue("ArenaLevel", arena.Level);
             cmd.AddUpdateValue("ArenaClass", arena.Class);
             cmd.AddUpdateValue("Mesh", arena.Mesh);
             cmd.AddUpdateValue("HonorPoints", arena.DatabaseID);
             cmd.AddUpdateValue("ArenaPoints", arena.ArenaPoints);
             cmd.AddUpdateValue("TotalWins", arena.ArenaTotalWins);
             cmd.AddUpdateValue("TotalWinsToday", arena.ArenaWinsToday);
             cmd.AddUpdateValue("TotalLoss", arena.ArenaTotalLoss);
             cmd.AddUpdateValue("TotalLossToday", arena.ArenaLossToday);
             cmd.Finish("DB_ArenaQualifier");
         }
         sql.Execute();
     }
 }
Exemplo n.º 22
0
 public static void SetRecordID(Data.ArenaInfo arena)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
         {
             cmd.AddWhereValue("PlayerID", arena.DatabaseID);
             cmd.Finish("DB_ArenaQualifier");
         }
         if (sql.Read())
         {
             arena.ArenaID = sql.ReadInt32("ArenaID");
         }
     }
 }
Exemplo n.º 23
0
        public static bool LoadMonsterInfo()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Monsters...");

            using (var mob = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(mob, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MobInfo");
                }
                while (mob.Read())
                {
                    int mobid = mob.ReadInt32("MobID");
                    Entities.Monster monster = new Entities.Monster();
                    monster.Name = mob.ReadString("Name");
                    monster.Level = mob.ReadByte("MobLevel");
                    monster.Mesh = mob.ReadUInt32("Lookface");
                    monster.MinAttack = mob.ReadUInt32("MinAttack");
                    monster.MaxAttack = mob.ReadUInt32("MaxAttack");
                    monster.Defense = mob.ReadUInt32("Defense");
                    monster.Dexterity = mob.ReadByte("Dexterity");
                    monster.Dodge = mob.ReadByte("Dodge");
                    monster.AttackRange = mob.ReadInt32("AttackRange");
                    monster.ViewRange = mob.ReadInt32("ViewRange");
                    monster.AttackSpeed = mob.ReadInt32("AttackSpeed");
                    monster.MoveSpeed = mob.ReadInt32("MoveSpeed");
                    if (monster.MoveSpeed < 100)
                        monster.MoveSpeed = 100;
                    if (monster.MoveSpeed > 5000)
                        monster.MoveSpeed = 5000;
                    monster.AttackType = mob.ReadInt32("AttackType");
                    monster.Behaviour = (Enums.MonsterBehaviour)Enum.Parse(typeof(Enums.MonsterBehaviour), mob.ReadString("Behaviour"));
                    monster.MagicType = mob.ReadInt32("MagicType");
                    monster.MagicDefense = mob.ReadInt32("MagicDefense");
                    monster.MagicHitRate = mob.ReadInt32("MagicHitRate");
                    monster.ExtraExperience = mob.ReadUInt64("ExtraExp");
                    monster.ExtraDamage = mob.ReadUInt32("ExtraDamage");
                    monster.Boss = (mob.ReadByte("Boss") != 0);
                    monster.Action = mob.ReadUInt32("Action");
                    monster.MaxHP = mob.ReadInt32("Life");

                    monster.HP = monster.MaxHP;
                    monster.MaxMP = mob.ReadInt32("Mana");
                    monster.MP = monster.MaxMP;

                    if (monster.Boss)
                    {
                        monster.AttackRange = 20;
                    }

                    string skillstring = mob.ReadString("Skills");
                    if (!string.IsNullOrWhiteSpace(skillstring))
                    {
                        int[] ids = new int[0];
                        skillstring.Split(',').ConverToInt32(out ids);
                        if (ids[0] != 0)
                        {
                            foreach (int skillid in ids)
                                monster.Skills.Add((ushort)skillid);
                        }
                    }

                    if (!Core.Kernel.Monsters.TryAdd(mobid, monster))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load monster. Failed at ID: {0}", mobid);
                        Console.ResetColor();
                        return false;
                    }
                }
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Monsters...", Core.Kernel.Monsters.Count);
            return true;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Loads all the items.
        /// </summary>
        /// <returns>Returns true if the items were loaded.</returns>
        public static bool LoadItemInfos()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            string wrt = "\tLoading Items...";
            /*using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_ItemInfo");
                }
                //int count = 0;
                while (sql.Read())
                {
                    count++;
                    Console.WriteLine("\tLoaded {0} item additions...", count);
                    Console.Clear();
                }
            }
             */
            //Console.WriteLine("SWAG");
            //return true;
            Console.WriteLine(wrt);
            System.Threading.Thread.Sleep(2000);
            int nameduplicates = 0;
            int loaded = 0;
            using (var item = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(item, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_ItemInfo");
                }
                while (item.Read())
                {
                    Data.ItemInfo info = new ProjectX_V3_Game.Data.ItemInfo();
                    info.ItemID = item.ReadUInt32("ItemID");
                    info.Name = item.ReadString("Name");
                    byte prof = item.ReadByte("Profession");
                    if (prof == 190)
                        info.Profession = Enums.Class.InternTaoist;
                    info.RequiredProf = item.ReadByte("WeaponSkill");
                    info.RequiredLevel = item.ReadByte("RequiredLevel");
                    info.Sex = (Enums.Sex)Enum.Parse(typeof(Enums.Sex), item.ReadString("Sex"));
                    info.RequiredStrength = item.ReadUInt16("RequiredStrength");
                    info.RequiredAgility = item.ReadUInt16("RequiredAgility");
                    info.RequiredVitality = item.ReadUInt16("RequiredVitality");
                    info.RequiredSpirit = item.ReadUInt16("RequiredSpirit");
                    info.Monopoly = item.ReadByte("Monopoly");
                    info.Weight = item.ReadUInt16("Weight");
                    info.Price = item.ReadUInt32("Price");
                    info.ActionID = item.ReadUInt32("ActionID");
                    info.MaxAttack = item.ReadUInt16("MaxAttack");
                    info.MinAttack = item.ReadUInt16("MinAttack");
                    info.Defense = item.ReadUInt16("Defense");
                    info.Dexterity = item.ReadUInt16("Dexterity");
                    info.Dodge = item.ReadUInt16("Dodge");
                    info.HP = item.ReadUInt16("Life");
                    info.MP = item.ReadUInt16("Mana");
                    info.AmountLimit = item.ReadUInt16("Amount");
                    if (info.IsArrow())
                    {
                        info.MaxDura = (short)info.AmountLimit;
                        info.CurrentDura = info.MaxDura;
                    }
                    info.Ident = item.ReadByte("Ident");
                    info.StGem1 = item.ReadByte("Gem1");
                    info.StGem2 = item.ReadByte("Gem2");
                    info.Magic1 = item.ReadUInt16("Magic1");
                    info.Magic2 = item.ReadByte("Magic2");
                    info.Magic3 = item.ReadByte("Magic3");
                    info.Data = item.ReadInt32("Data");
                    info.MagicAttack = item.ReadUInt16("MagicAttack");
                    info.MagicDefense = item.ReadUInt16("MagicDefense");
                    info.AttackRange = item.ReadUInt16("AttackRange");
                    info.AttackSpeed = item.ReadUInt16("AttackSpeed");
                    info.FrayMode = item.ReadByte("FrayMode");
                    info.RepairMode = item.ReadByte("RepairMode");
                    info.TypeMask = item.ReadByte("TypeMask");
                    info.CPPrice = item.ReadUInt32("EMoneyPrice");
                    info.Unknown1 = item.ReadUInt32("Unknown1");
                    info.Unknown2 = item.ReadUInt32("Unknown2");
                    info.CriticalStrike = item.ReadUInt32("CriticalStrike");
                    info.SkillCriticalStrike = item.ReadUInt32("SkillCriticalStrike");
                    info.Immunity = item.ReadUInt32("Immunity");
                    info.Penetration = item.ReadUInt32("Penetration");
                    info.Block = item.ReadUInt32("Block");
                    info.BreakThrough = item.ReadUInt32("BreakThrough");
                    info.CounterAction = item.ReadUInt32("CounterAction");
                    info.StackLimit = item.ReadUInt32("StackLimit");
                    info.ResistMetal = item.ReadUInt32("ResistMetal");
                    info.ResistWood = item.ReadUInt32("ResistWood");
                    info.ResistWater = item.ReadUInt32("ResistWater");
                    info.ResistFire = item.ReadUInt32("ResistFire");
                    info.ResistEarth = item.ReadUInt32("ResistEarth");
                    info.TypeName = item.ReadString("TypeName");
                    info.Description = item.ReadString("Description");
                    info.NameColor = item.ReadUInt32("NameColor");
                    info.DragonSoulPhase = item.ReadUInt32("DragonSoulPhase");
                    info.DragonSoulRequirements = item.ReadUInt32("DragonSoulRequirements");
                    info.Plus = item.ReadByte("StaticPlus");

                    if (info.IsShield())
                        info.ItemType = Enums.ItemType.Shield;
                    else if (info.IsArmor())
                        info.ItemType = Enums.ItemType.Armor;
                    else if (info.IsHeadgear())
                        info.ItemType = Enums.ItemType.Head;
                    else if (info.IsOneHand())
                        info.ItemType = Enums.ItemType.OneHand;
                    else if (info.IsTwoHand())
                        info.ItemType = Enums.ItemType.TwoHand;
                    else if (info.IsArrow())
                        info.ItemType = Enums.ItemType.Arrow;
                    else if (info.IsBow())
                        info.ItemType = Enums.ItemType.Bow;
                    else if (info.IsNecklace())
                        info.ItemType = Enums.ItemType.Necklace;
                    else if (info.IsRing())
                        info.ItemType = Enums.ItemType.Ring;
                    else if (info.IsBoots())
                        info.ItemType = Enums.ItemType.Boots;
                    else if (info.IsGarment())
                        info.ItemType = Enums.ItemType.Garment;
                    else if (info.IsFan())
                        info.ItemType = Enums.ItemType.Fan;
                    else if (info.IsTower())
                        info.ItemType = Enums.ItemType.Tower;
                    else if (info.IsSteed())
                        info.ItemType = Enums.ItemType.Steed;
                    else if (info.IsBottle())
                        info.ItemType = Enums.ItemType.Bottle;
                    else if (info.IsMountArmor())
                        info.ItemType = Enums.ItemType.SteedArmor;
                    else
                        info.ItemType = Enums.ItemType.Misc;

                    if (Core.Kernel.ItemInfos.Contains(info.Name))
                    {
                        nameduplicates++;
                    }
                    if (!Core.Kernel.ItemInfos.TryAddAndDismiss(info.ItemID, info.Name, info))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\tFailed to load items. [ADD]" + Core.Kernel.ItemInfos.Count);
                        Console.ResetColor();
                        return false;
                    }

                    /*if (!Core.Kernel.SortedItemInfos.Contains(info.ItemID))
                    {
                        if (!Core.Kernel.SortedItemInfos.TryAdd(info.ItemID, info.Name, new System.Collections.Concurrent.ConcurrentDictionary<byte, Data.ItemInfo>()))
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("\tFailed to load items. [SORTED]" + Core.Kernel.ItemInfos.Count);
                            Console.ResetColor();
                            return false;
                        }
                    }

                    if (!Core.Kernel.SortedItemInfos.selectorCollection2[info.Name].TryAdd(info.Quality, info))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("\tFailed to load items. [SORTED : NAME]" + Core.Kernel.ItemInfos.Count);
                        Console.ResetColor();
                        return false;
                    }*/

                    Console.Clear();
                    Console.WriteLine("{0}{1}\tLoaded {2} items... Duplicates so far: {3}", wrt, Environment.NewLine, loaded++, nameduplicates);
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Items... Duplicate names: {1}", Core.Kernel.ItemInfos.Count, nameduplicates);
            return true;
        }
Exemplo n.º 25
0
        /// <summary>
        /// Loads the map info.
        /// </summary>
        /// <returns>Returns true if the maps were loaded.</returns>
        public static bool LoadMaps()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Maps...");
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_MapInfo");
                }
                while (sql.Read())
                {

                    Maps.Map map = new ProjectX_V3_Game.Maps.Map(
                        sql.ReadUInt16("MapID"),
                        sql.ReadString("Name"));

                    if (map.MapID == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load maps. [MAPID]");
                        Console.ResetColor();
                        return false;
                    }
                    map.MapType = (Enums.MapType)Enum.Parse(typeof(Enums.MapType), sql.ReadString("MapType"));
                    ushort dmap = sql.ReadUInt16("DMapInfo");
                    if (dmap > 0)
                        map.DMapInfo = dmap;

                    map.InheritanceMap = sql.ReadUInt16("InheritanceMap");

                    using (var sqlflags = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                    {
                        using (var cmd2 = new SqlCommandBuilder(sqlflags, SqlCommandType.SELECT, true))
                        {
                            cmd2.AddWhereValue("MapID", map.MapID);
                            cmd2.Finish("DB_MapFlags");
                        }
                        while (sqlflags.Read())
                        {
                            Enums.MapTypeFlags flag = (Enums.MapTypeFlags)Enum.Parse(typeof(Enums.MapTypeFlags), sqlflags.ReadString("Flag"));

                            if (!map.Flags.TryAdd((ulong)flag, flag))
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Failed to load maps. [FLAGS] Failed at ID: {0}", map.MapID);
                                Console.ResetColor();
                                return false;
                            }
                        }
                    }

                    if (!Core.Kernel.Maps.TryAdd(map.MapID, map.Name, map))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load maps. [MAP] Failed at ID: {0}", map.MapID);
                        Console.ResetColor();
                        return false;
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Maps...", Core.Kernel.Maps.Count);
            return true;
        }
Exemplo n.º 26
0
 private static bool PlayerExists(int DatabaseID)
 {
     using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
     {
         using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
         {
             cmd.AddWhereValue("PlayerID", DatabaseID);
             cmd.Finish("DB_Players");
         }
         return sql.Read();
     }
 }
Exemplo n.º 27
0
        /// <summary>
        /// Saves the basic information of a client.
        /// </summary>
        /// <param name="client">The client.</param>
        public static void Save(Entities.GameClient client)
        {
            try
            {
                if (!client.LoggedIn || client.IsAIBot)
                    return;

                using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.AddUpdateValue("PlayerMapID", client.Map.MapID);
                        cmd.AddUpdateValue("PlayerLastMapID", client.LastMapID);
                        cmd.AddUpdateValue("PlayerX", client.X);
                        cmd.AddUpdateValue("PlayerY", client.Y);
                        cmd.AddUpdateValue("PlayerSpouseID", client.SpouseDatabaseUID);
                        cmd.AddUpdateValue("TournyKills", client.TournamentInfo.TotalKills);
                        cmd.AddUpdateValue("TournyDeaths", client.TournamentInfo.TotalDeaths);
                        if (client.Guild == null)
                        {
                            cmd.AddUpdateValue("PlayerGuildRank", "None");
                            cmd.AddUpdateValue("PlayerGuild", "");
                            cmd.AddUpdateValue("PlayerGuildDonation", (uint)0);
                            cmd.AddUpdateValue("PlayerGuildCPDonation", (uint)0);
                        }
                        else
                        {
                            cmd.AddUpdateValue("PlayerGuildRank", client.GuildMemberInfo.Rank.ToString());
                            cmd.AddUpdateValue("PlayerGuild", client.Guild.Name);
                            cmd.AddUpdateValue("PlayerGuildDonation", client.GuildMemberInfo.MoneyDonation);
                            cmd.AddUpdateValue("PlayerGuildCPDonation", client.GuildMemberInfo.CPDonation);
                        }
                        cmd.Finish("DB_Players");
                    }
                    sql.Execute();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to save {0}.", client.Name);
                Console.WriteLine(e.ToString());
            }
        }
Exemplo n.º 28
0
        public static void UpdateAuthentication(Client.AuthClient client)
        {
            if (PlayerExists(client.DatabaseUID))
            {
                using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.UPDATE, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.AddUpdateValue("PlayerLastEntityUID", client.EntityUID);
                        cmd.AddUpdateValue("PlayerLoginOK", true);

                        cmd.Finish("DB_Players");
                    }
                    sql.Execute();
                }
            }
            else
            {
                using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.INSERT, false))
                    {
                        cmd.AddInsertValue("PlayerID", client.DatabaseUID);
                        cmd.AddInsertValue("PlayerNew", true);
                        cmd.AddInsertValue("PlayerAccount", client.Account);
                        cmd.AddInsertValue("PlayerLastEntityUID", client.EntityUID);
                        cmd.AddInsertValue("PlayerLoginOK", true);
                        cmd.AddInsertValue("PlayerServer", client.Server);

                        cmd.Finish("DB_Players");
                    }
                    sql.Execute();
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Loads all the spells.
        /// </summary>
        /// <returns></returns>
        public static bool LoadSpells()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading Spells...");

            using (var spellinfo = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(spellinfo, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_SpellInfo");
                }
                while (spellinfo.Read())
                {
                    Data.Spell spell = new ProjectX_V3_Game.Data.Spell();
                    spell.ID = spellinfo.ReadUInt16("SpellID");
                    if (spell.ID == 0)
                    {
                        return false;
                    }
                    spell.SpellID = spellinfo.ReadUInt16("Type");
                    if (spell.SpellID == 0)
                    {
                        return false;
                    }

                    spell.Sort = spellinfo.ReadByte("Sort");
                    spell.Crime = spellinfo.ReadBoolean("Crime");
                    spell.Ground = spellinfo.ReadBoolean("Ground");
                    spell.Multi = spellinfo.ReadBoolean("Multi");
                    spell.Target = spellinfo.ReadByte("Target");
                    spell.Level = spellinfo.ReadByte("SpellLevel");
                    spell.UseMP = spellinfo.ReadUInt16("UseMP");
                    spell.Power = spellinfo.ReadUInt16("Power");
                    if (spell.Power == 0)
                        spell.PowerPercentage = 1;
                    else
                        spell.PowerPercentage = (float)(spell.Power % 1000) / 100;
                    spell.IntoneSpeed = spellinfo.ReadUInt16("IntoneSpeed");
                    spell.Percentage = spellinfo.ReadByte("SpellPercent");
                    spell.Duration = spellinfo.ReadByte("StepSecs");
                    spell.Range = spellinfo.ReadUInt16("Range");
                    spell.Sector = spell.Range * 20;
                    spell.Distance = spellinfo.ReadUInt16("Distance");
                    if (spell.Distance >= 4)
                        spell.Distance--;
                    if (spell.Distance > 17)
                        spell.Distance = 17;
                    spell.Status = spellinfo.ReadUInt64("Status");
                    spell.NeedExp = spellinfo.ReadUInt32("NeedExp");
                    spell.NeedLevel = spellinfo.ReadByte("NeedLevel");
                    spell.UseXP = spellinfo.ReadByte("UseXP");
                    spell.WeaponSubtype = spellinfo.ReadUInt16("WeaponSubtype");
                    spell.UseEP = spellinfo.ReadByte("UseEP");
                    spell.NextMagic = spellinfo.ReadUInt16("NextMagic");
                    spell.UseItem = spellinfo.ReadByte("UseItem");
                    spell.UseItemNum = spellinfo.ReadByte("UseItemNum");

                    if (Core.Kernel.SpellInfos.ContainsKey(spell.SpellID))
                    {
                        Core.Kernel.SpellInfos[spell.SpellID].TryAdd(spell.Level, spell);
                    }
                    else
                    {
                        if (!Core.Kernel.SpellInfos.TryAdd(spell.SpellID))
                            return false;

                        if (!Core.Kernel.SpellInfos[spell.SpellID].TryAdd(spell.Level, spell))
                            return false;
                    }

                    switch (spell.SpellID)
                    {
                        case 5010:
                        case 7020:
                        case 1290:
                        case 1260:
                        case 5030:
                        case 5040:
                        case 7000:
                        case 7010:
                        case 7030:
                        case 7040:
                        case 1250:
                        case 5050:
                        case 5020:
                        case 10490:
                        case 1300:
                            if (spell.Distance >= 3)
                                spell.Distance = 3;
                            if (spell.Range > 3)
                                spell.Range = 3;
                            if (!Core.Kernel.WeaponSpells.ContainsKey(spell.WeaponSubtype))
                            {
                                if (!Core.Kernel.WeaponSpells.TryAdd(spell.WeaponSubtype, spell.SpellID))
                                {
                                    return false;
                                }
                            }
                            break;
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} Spells...", Core.Kernel.SpellInfos.Count);
            return true;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Loads all the npc informations and spawns.
        /// </summary>
        /// <returns>Returns true if the the infos/spawns were loaded.</returns>
        public static bool LoadNPCInfo()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("\tLoading NPCs...");
            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, false))
                {
                    cmd.Finish("DB_NPCInfo");
                }
                while (sql.Read())
                {
                    Entities.NPC npc = new ProjectX_V3_Game.Entities.NPC();
                    npc.EntityUID = sql.ReadUInt32("NPCID");
                    ushort mapid = sql.ReadUInt16("MapID");
                    if (mapid == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load npcs. [MAPID]");
                        Console.ResetColor();
                        return false;
                    }

                    Maps.Map map;
                    Core.Kernel.Maps.TrySelect(mapid, out map);
                    npc.Map = map;
                    if (!npc.Map.EnterMap(npc))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load npcs. [MAP]");
                        Console.ResetColor();
                        return false;
                    }

                    npc.Mesh = sql.ReadUInt16("Mesh");
                    npc.Flag = sql.ReadUInt32("Flag");
                    npc.Name = sql.ReadString("NPCName");
                    npc.X = sql.ReadUInt16("X");
                    npc.Y = sql.ReadUInt16("Y");
                    npc.NPCType = (Enums.NPCType)Enum.Parse(typeof(Enums.NPCType), sql.ReadString("Type"));

                    npc.Avatar = sql.ReadByte("Avatar");

                    if (!Core.Kernel.NPCs.TryAdd(npc.EntityUID, npc))
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Failed to load npcs. [ADD]");
                        Console.ResetColor();
                        return false;
                    }
                }
            }
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\tLoaded {0} NPCs...", Core.Kernel.NPCs.Count);
            return true;
        }