Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
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;
            }
        }