Пример #1
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;
 }
Пример #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
        }
Пример #3
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;
        }
Пример #4
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;
        }
Пример #5
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;
            }
        }
Пример #6
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");
                }
            }
        }
Пример #7
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");
         }
     }
 }
Пример #8
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;
        }
Пример #9
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;
        }
Пример #10
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;
        }
Пример #11
0
        /// <summary>
        /// Loads all the data of a character.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="newchar">[out] if true then the character is not yet made.</param>
        /// <returns>Returns true.</returns>
        public static bool LoadCharacter(Entities.GameClient client, out bool newchar)
        {
            newchar = false;

            try
            {
                client.CharDB = new CharacterDatabase(client.DatabaseUID);

                #region Load Stats ; Loads all the main stats of the character (name, level, coordinates etc.)
                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_Players");
                    }

                    if (!sql.Read())
                        return false;

                    if (sql.ReadBoolean("PlayerNew"))
                    {
                        newchar = true;
                        return false;
                    }
                    client.Name = sql.ReadString("PlayerName");
                    if (string.IsNullOrEmpty(client.Name) || string.IsNullOrWhiteSpace(client.Name))
                        return false;

                    client.Permission = (Enums.PlayerPermission)Enum.Parse(typeof(Enums.PlayerPermission), sql.ReadString("PlayerPermission"));
                    client.Faction = (Enums.Faction)Enum.Parse(typeof(Enums.Faction), sql.ReadString("PlayerFaction"));
                    client.Avatar = sql.ReadUInt16("PlayerAvatar");
                    client.Model = sql.ReadUInt16("PlayerModel");
                    client.HairStyle = sql.ReadUInt16("PlayerHairStyle");
                    client.Money = sql.ReadUInt32("PlayerMoney");
                    client.WarehouseMoney = sql.ReadUInt32("PlayerWarehouseMoney");
                    client.CPs = sql.ReadUInt32("PlayerCPs");
                    client.BoundCPs = sql.ReadUInt32("PlayerBoundCPs");
                    client.Strength = sql.ReadUInt16("PlayerStrength");
                    client.Agility = sql.ReadUInt16("PlayerAgility");
                    client.Vitality = sql.ReadUInt16("PlayerVitality");
                    client.Spirit = sql.ReadUInt16("PlayerSpirit");
                    client.AttributePoints = sql.ReadUInt16("PlayerAttributePoints");
                    client.MaxHP = sql.ReadInt32("PlayerMaxHP");
                    client.HP = sql.ReadInt32("PlayerHP");
                    if (client.HP <= 0)
                        client.HP = 1;
                    client.MaxMP = sql.ReadInt32("PlayerMaxMP");
                    client.MP = sql.ReadInt32("PlayerMP");
                    client.PKPoints = sql.ReadInt16("PlayerPKPoints");
                    client.Level = sql.ReadByte("PlayerLevel");
                    client.Experience = sql.ReadUInt64("PlayerExperience");
                    client.Class = (Enums.Class)Enum.Parse(typeof(Enums.Class), sql.ReadString("PlayerClass"));
                    client.PlayerTitle = (Enums.PlayerTitle)Enum.Parse(typeof(Enums.PlayerTitle), sql.ReadString("PlayerTitle"));
                    client.Account = sql.ReadString("PlayerAccount");
                    client.Reborns = sql.ReadByte("PlayerReborns");
                    client.SpouseDatabaseUID = sql.ReadInt32("PlayerSpouseID");
                    client.QuestPoints = sql.ReadUInt32("PlayerQuestPoints");
                    /*string n = sql.ReadObject("PlayerCurrentQuest").ToString();
                    if (!string.IsNullOrWhiteSpace(n))
                        client.CurrentQuest = client.Quests[n];*/
                    Maps.MapPoint startmap = Maps.MapTools.GetStartMap(
                        sql.ReadUInt16("PlayerMapID"),
                        sql.ReadUInt16("PlayerX"),
                        sql.ReadUInt16("PlayerY"),
                        sql.ReadUInt16("PlayerLastMapID"));

                    client.Map = startmap.Map;
                    client.LastMapID = client.Map.MapID;
                    client.X = startmap.X;
                    client.Y = startmap.Y;
                    client.LastMapX = client.X;
                    client.LastMapY = client.Y;
                    client.LastX = client.X;
                    client.LastY = client.Y;
                    uint entityuid;
                    Maps.IMapObject rObject;
                    if (client.Map.ContainsClientByName(client.Name, out entityuid))
                        client.Map.MapObjects.TryRemove(entityuid, out rObject);

                    if (!client.Map.EnterMap(client))
                        return false;
                }
                #endregion

                #region Load Inventory ; Loads the inventory of the character.
                IniFile itemfile = client.CharDB.ItemFiles[0];
                if (itemfile.Exists())
                {
                    string[] sections = itemfile.GetSectionNames(255);
                    if (sections.Length > 0)
                    {
                        int[] positions;
                        sections.ConverToInt32(out positions);

                        for (int i = 0; i < 40; i++)
                        {
                            if (positions.Contains(i))
                            {
                                itemfile.SetSection(i.ToString());
                                uint itemid = itemfile.ReadUInt32("ItemID", 0);
                                if (itemid == 0)
                                    return false;

                                Data.ItemInfo item;
                                Data.ItemInfo original;
                                if (!Core.Kernel.ItemInfos.TrySelect(itemid, out original))
                                    return false;
                                item = original.Copy();

                                item.Plus = itemfile.ReadByte("Plus", 0);
                                item.Bless = itemfile.ReadByte("Bless", 0);
                                item.Enchant = itemfile.ReadByte("Enchant", 0);
                                item.Gem1 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), itemfile.ReadString("Gem1", "NoSocket"));
                                item.Gem2 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), itemfile.ReadString("Gem2", "NoSocket"));
                                item.Location = Enums.ItemLocation.Inventory;
                                item.CurrentDura = itemfile.ReadInt16("CurrentDura", 0);
                                item.MaxDura = itemfile.ReadInt16("MaxDura", 0);
                                item.Color = (Enums.ItemColor)Enum.Parse(typeof(Enums.ItemColor), itemfile.ReadString("Color", "Orange"));
                                item.SocketAndRGB = itemfile.ReadUInt32("SocketProgress", 0);

            //							// other data
            //							public uint SocketAndRGB = 0;
            //							public ushort CurrentDura = 100;
            //							public ushort MaxDura = 100;
            //							public ushort RebornEffect = 0;
            //							public bool Free = false;
            //							public uint GreenText = 0;
            //							public uint INS = 0;
            //							public bool Suspicious = false;
            //							public bool Locked = false;
            //							public uint Composition = 0;
            //							public uint LockedTime = 0;
            //							public ushort Amount = 0;
            //							public byte Color = 0;

                                if (!client.Inventory.AddItem(item, (byte)i))
                                    return false;
                            }
                        }
                    }
                }
                #endregion

                #region Load Equipments ; Loads the equipments of the character.
                IniFile equipfile = client.CharDB.ItemFiles[1];
                if (equipfile.Exists())
                {
                    for (byte i = 1; i <= 32; i++)
                    {
                        equipfile.SetSection(i.ToString());
                        uint itemid = equipfile.ReadUInt32("ID", 0);
                        if (itemid > 0)
                        {
                            Data.ItemInfo item;
                            Data.ItemInfo original;
                            if (!Core.Kernel.ItemInfos.TrySelect(itemid, out original))
                                return false;
                            item = original.Copy();

                            item.Plus = equipfile.ReadByte("Plus", 0);
                            item.Bless = equipfile.ReadByte("Bless", 0);
                            item.Enchant = equipfile.ReadByte("Enchant", 0);
                            item.Gem1 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), equipfile.ReadString("Gem1", "NoSocket"));
                            item.Gem2 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), equipfile.ReadString("Gem2", "NoSocket"));
                            item.CurrentDura = equipfile.ReadInt16("CurrentDura", 0);
                            item.MaxDura = equipfile.ReadInt16("MaxDura", 0);
                            item.Color = (Enums.ItemColor)Enum.Parse(typeof(Enums.ItemColor), equipfile.ReadString("Color", "Orange"));
                            item.SocketAndRGB = equipfile.ReadUInt32("SocketProgress", 0);

                            // FIX REMOVE!!
                            client.Equipments.Equip(item, (Enums.ItemLocation)i, false);
                        }
                    }
                }
                #endregion

                #region Load Prof ; Loads the prof-skills of the character.
                using (var prof = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(prof, SqlCommandType.SELECT, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.Finish("DB_PlayerProfs");
                    }
                    while (prof.Read())
                    {
                        Data.SpellInfo profinfo = new ProjectX_V3_Game.Data.SpellInfo();
                        profinfo.ID = prof.ReadUInt16("Prof");
                        profinfo.Level = prof.ReadUInt16("ProfLevel");
                        profinfo.Experience = prof.ReadUInt32("ProfExperience");
                        client.SpellData.AddProf(profinfo);
                    }
                }
                #endregion

                #region Load Skills ; Loads the skills of the character.
                using (var spell = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(spell, SqlCommandType.SELECT, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.Finish("DB_PlayerSpells");
                    }
                    while (spell.Read())
                    {
                        Data.SpellInfo spellinfo = new ProjectX_V3_Game.Data.SpellInfo();
                        spellinfo.ID = spell.ReadUInt16("SpellSkillID");
                        spellinfo.Level = spell.ReadUInt16("SpellLevel");
                        spellinfo.Experience = spell.ReadUInt32("SpellExperience");
                        client.SpellData.AddSpell(spellinfo);
                    }
                }
                #endregion

                #region Load Banks ; Loads the warehouses of the character.
                foreach (ushort WhID in whids)
                {
                    IniFile warehousefile = client.CharDB.WarehouseFiles[WhID];
                    if (warehousefile.Exists())
                    {
                        string[] sections = warehousefile.GetSectionNames(255);
                        if (sections.Length > 0)
                        {
                            int[] positions;
                            sections.ConverToInt32(out positions);

                            for (int i = 0; i < 40; i++)
                            {
                                if (positions.Contains(i))
                                {
                                    warehousefile.SetSection(i.ToString());
                                    uint itemid = warehousefile.ReadUInt32("ItemID", 0);
                                    if (itemid == 0)
                                        return false;

                                    Data.ItemInfo item;
                                    Data.ItemInfo original;
                                    if (!Core.Kernel.ItemInfos.TrySelect(itemid, out original))
                                        return false;
                                    item = original.Copy();

                                    item.Plus = warehousefile.ReadByte("Plus", 0);
                                    item.Bless = warehousefile.ReadByte("Bless", 0);
                                    item.Enchant = warehousefile.ReadByte("Enchant", 0);
                                    item.Gem1 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), warehousefile.ReadString("Gem1", "NoSocket"));
                                    item.Gem2 = (Enums.SocketGem)Enum.Parse(typeof(Enums.SocketGem), warehousefile.ReadString("Gem2", "NoSocket"));
                                    item.Location = Enums.ItemLocation.Inventory;
                                    item.CurrentDura = warehousefile.ReadInt16("CurrentDura", 0);
                                    item.MaxDura = warehousefile.ReadInt16("MaxDura", 0);
                                    item.Color = (Enums.ItemColor)Enum.Parse(typeof(Enums.ItemColor), warehousefile.ReadString("Color", "Orange"));
                                    item.SocketAndRGB = warehousefile.ReadUInt32("SocketProgress", 0);

            //							// other data
            //							public uint SocketAndRGB = 0;
            //							public ushort CurrentDura = 100;
            //							public ushort MaxDura = 100;
            //							public ushort RebornEffect = 0;
            //							public bool Free = false;
            //							public uint GreenText = 0;
            //							public uint INS = 0;
            //							public bool Suspicious = false;
            //							public bool Locked = false;
            //							public uint Composition = 0;
            //							public uint LockedTime = 0;
            //							public ushort Amount = 0;
            //							public byte Color = 0;

                                    if (!client.Warehouses[WhID].AddItem(item, (byte)i))
                                        return false;
                                }
                            }
                        }
                    }
                }
                #endregion

                #region Load Guild ; Loads the guild of the character.
                // Look Packets.GeneralData.GetSynAttr.cs
                #endregion

                #region Load Association ; Loads the character associations.
                #endregion

                #region Load Quests ; Loads the quests of the character.
                /*using (var quest = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
                {
                    using (var cmd = new SqlCommandBuilder(quest, SqlCommandType.SELECT, true))
                    {
                        cmd.AddWhereValue("PlayerID", client.DatabaseUID);
                        cmd.Finish("DB_Quests");
                    }
                    while (quest.Read())
                    {
                        string Name = quest.ReadString("QuestName");
                        int Progress = quest.ReadInt32("QuestProgress");

                        if (Progress == -1)
                            client.Quests[Name].Finished = true;
                        else
                        {
                            client.Quests[Name].QuestProgress = (ushort)Progress;
                            client.Quests[Name].LoadInfoString(quest.ReadString("QuestInfo"));
                        }
                    }
                }*/
                #endregion

                client.BaseEntity.SetBaseStats();
                client.BaseEntity.CalculateBaseStats();

                UpdateSpouse(client);
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return false;
            }
        }
Пример #12
0
        public static void UpdateSpouse(Entities.GameClient client)
        {
            if (client.SpouseDatabaseUID == 0)
                return;

            using (var sql = new SqlHandler(Program.Config.ReadString("GameConnectionString")))
            {
                using (var cmd = new SqlCommandBuilder(sql, SqlCommandType.SELECT, true))
                {
                    cmd.AddWhereValue("PlayerID", client.SpouseDatabaseUID);
                    cmd.Finish("DB_Players");
                }

                if (!sql.Read())
                {
                    RemoveSpouse(client);
                }
                else if (sql.ReadInt32("PlayerSpouseID") != client.DatabaseUID)
                {
                    RemoveSpouse(client);
                }
            }
        }