Beispiel #1
0
        /// <summary>
        /// Adds prof exp.
        /// </summary>
        /// <param name="ID">The prof id.</param>
        /// <param name="amount">The amount of exp to add.</param>
        public void AddProfExp(ushort ID, uint amount, bool second = false)
        {
            Data.SpellInfo prof = null;
            if (SpellData.ContainsProf(ID))
                prof = SpellData.GetProf(ID);
            else
            {
                prof = new ProjectX_V3_Game.Data.SpellInfo();
                prof.Experience = 0;
                prof.Level = 0;
                prof.ID = ID;
                SpellData.AddProf(prof);
            }

            if (prof.Level >= 20)
                return;

            amount *= Core.NumericConst.ProfRate;
            prof.Experience += amount;

            if (LoggedIn && !second)
            {
                using (var msg = Packets.Message.MessageCore.CreateSystem2(Name, string.Format(Core.MessageConst.GAIN_PROF_EXP, amount)))
                {
                    Send(msg);
                }
            }

            uint required = Calculations.LevelCalculations.GetProfExperience((byte)prof.Level);
            if (prof.Experience >= required)
            {
                prof.Level++;
                prof.Experience = 0;
            }
            if (this.LoggedIn)
            {
                Database.CharacterDatabase.SaveProf(this, prof);
                using (var spell = new Packets.SendProfPacket())
                {
                    spell.ID = prof.ID;
                    spell.Level = prof.Level;
                    spell.Experience = prof.Experience;
                    Send(spell);
                }
            }
        }
        /// <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;
            }
        }