public List<uint> GetJobSpeciaficSkills(MySqlConnection connection, Character target, byte job)
        {
            List<uint> MyList = new List<uint>();
            MySqlDataReader reader = null;
            try
            {
                //LOAD ALL SKILL INFORMATION
                MySqlCommand command = new MySqlCommand(_query_65, connection);
                command.Parameters.AddWithValue("CharId", target.ModelId);

                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                while (reader.Read())
                {
                    Skill skill = new Skill();
                    skill.Id = reader.GetUInt32(0);
                    if (Singleton.SpellManager.TryGetSpell(skill.Id, out skill.info) &&
                        skill.info.requiredJobs[job - 1] == 1)
                        MyList.Add(skill.Id);
                }

                return MyList;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return new List<uint>();
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
            }
        }
        bool LoadSpecialSkillsEx(MySqlConnection connection, IInfoProvider2 dbq, bool continueOnError)
        {
            MySqlDataReader reader = null;
            IDataSpecialSkillCollection collection = dbq.createDatabaseSpecialSkillCollection();

            try
            {
                //LOAD ALL SKILL INFORMATION
                MySqlCommand command = new MySqlCommand(_query_67, connection);
                command.Parameters.AddWithValue("CharId", collection.CharacterId);
                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);

                while (reader.Read())
                {
                    byte[] buffer = new byte[64];
                    if (reader.IsDBNull(0) == false) reader.GetBytes(0, 0, buffer, 0, 64);
                    for (int i = 0; i < 16; i++)
                    {
                        uint skillid = BitConverter.ToUInt32(buffer, i * 4);
                        Skill skill = new Skill();
                        skill.Id = skillid;
                        if (Singleton.SpellManager.spells.TryGetValue(skillid, out skill.info))
                            collection.specialSkillCollection[i] = skill;
                    }

                    return true;
                }

                __dbtracelog.WriteError("Database", "player specialskill-data of player with id {0} is missing", collection.CharacterId);
                return continueOnError;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return false;
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
            }
        }
        //Third generation method special skill information
        bool LoadSkillsEx(MySqlConnection connection, IInfoProvider2 dbq, bool continueOnError)
        {
            MySqlDataReader reader = null;
            IDataSkillCollection collection = dbq.createSkillCollection();

            try
            {
                //LOAD ALL SKILL INFORMATION
                MySqlCommand command = new MySqlCommand(_query_60, connection);
                command.Parameters.AddWithValue("CharId", collection.CharacterId);
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    Skill skill = new Skill();
                    skill.Id = reader.GetUInt32(0);
                    skill.Experience = reader.GetUInt32(1);
                    if (Singleton.SpellManager.TryGetSpell(skill.Id, out skill.info) && skill.info.requiredJobs[collection.Job - 1] == 1 )
                        collection.Skills.Add(skill);

                        return true;
                }

                __dbtracelog.WriteError("Database", "player skill-data of player with id {0} is missing", collection.CharacterId);
                return continueOnError;
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
                return false;
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
            }
        }
        public void LoadSkills(Character character, uint CharId)
        {
            MySqlConnection connection = ConnectionPool.Request();
            MySqlDataReader reader = null;
            try
            {
                //LOAD ALL SKILL INFORMATION
                MySqlCommand command = new MySqlCommand(_query_60, connection);
                command.Parameters.AddWithValue("CharId", CharId);

                reader = command.ExecuteReader(CommandBehavior.SequentialAccess);
                while (reader.Read())
                {
                    Skill skill = new Skill();
                    skill.Id = reader.GetUInt32(0);
                    skill.Experience = reader.GetUInt32(1);
                    if (Singleton.SpellManager.TryGetSpell(skill.Id, out skill.info) && skill.info.requiredJobs[character.job - 1] == 1)
                        character.learnedskills.Add(skill);
                }
            }
            catch (Exception e)
            {
                __dbtracelog.WriteError("Database", e.Message);
            }
            finally
            {
                //ALWAYS CLOSE THE READ RESULT
                if (reader != null) reader.Close();
                ConnectionPool.Release(connection);
            }
        }
Example #5
0
        /// <summary>
        /// Learns a new skill from a skillbook
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_SKILLS_LEARNFROMSKILLBOOK(CMSG_SKILLLEARN cpkt)
        {
            byte result = 1;
            try
            {
                Saga.Factory.Spells.Info spellinfo;
                Rag2Item item = character.container[cpkt.Index];
                if (item != null)
                {
                    //Helpers predicates
                    Predicate<Skill> FindSkill = delegate(Skill skill)
                    {
                        return skill.Id == item.info.skill;
                    };

                    Predicate<Skill> FindPreviousSkill = delegate(Skill skill)
                    {
                        return skill.Id == item.info.skill - 1;
                    };

                    //HELPER VARIABLES
                    uint baseskill = (item.info.skill / 100) * 100 + 1;
                    int newLength = character.container[cpkt.Index].count - 1;
                    List<Skill> learnedSpells = this.character.learnedskills;
                    Singleton.SpellManager.TryGetSpell(item.info.skill, out spellinfo);
                    Skill CurrentSkill = learnedSpells.FindLast(FindSkill);
                    Skill PreviousSkill = learnedSpells.FindLast(FindPreviousSkill);
                    bool IsBaseSkill = item.info.skill == baseskill;

                    //CHECK IF THE CURRENT JOB CAN LEARN THE SPELL
                    if (item.info.JobRequirement[this.character.job - 1] > this.character.jlvl)
                    {
                        result = (byte)Generalerror.ConditionsNotMet;
                    }
                    //CHECK IF WE ALREADY LEARNED THE SPELL
                    else if (CurrentSkill != null)
                    {
                        result = (byte)Generalerror.AlreadyLearntSkill;
                    }
                    //CHECK IF A PREVIOUS SKILL WAS FOUND
                    else if (!IsBaseSkill && PreviousSkill == null)
                    {
                        result = (byte)Generalerror.PreviousSkillNotFound;
                    }
                    //CHECK SKILL EXP
                    else if (PreviousSkill != null && PreviousSkill.Experience < PreviousSkill.info.maximumexperience)
                    {
                        result = (byte)Generalerror.NotEnoughSkillExperience;
                    }
                    else
                    {
                        //ADD A NEW SKILL
                        if (IsBaseSkill)
                        {
                            //Passive skill
                            bool canUse = Singleton.SpellManager.CanUse(this.character, spellinfo);
                            if (spellinfo.skilltype == 2 && canUse)
                            {
                                Singleton.Additions.ApplyAddition(spellinfo.addition, this.character);

                                int ActiveWeaponIndex = (this.character.weapons.ActiveWeaponIndex == 1) ? this.character.weapons.SeconairyWeaponIndex : this.character.weapons.PrimaryWeaponIndex;
                                if (ActiveWeaponIndex < this.character.weapons.UnlockedWeaponSlots)
                                {
                                    Weapon weapon = this.character.weapons[ActiveWeaponIndex];
                                    if ((baseskill - 1) == weapon.Info.weapon_skill)
                                    {
                                        BattleStatus status = character._status;
                                        status.MaxWMAttack += (ushort)weapon.Info.max_magic_attack;
                                        status.MinWMAttack += (ushort)weapon.Info.min_magic_attack;
                                        status.MaxWPAttack += (ushort)weapon.Info.max_short_attack;
                                        status.MinWPAttack += (ushort)weapon.Info.min_short_attack;
                                        status.MaxWRAttack += (ushort)weapon.Info.max_range_attack;
                                        status.MinWRAttack += (ushort)weapon.Info.min_range_attack;
                                        status.Updates |= 2;
                                    }
                                }
                            }

                            Singleton.Database.InsertNewSkill(this.character, item.info.skill, spellinfo.maximumexperience);
                            CurrentSkill = new Skill();
                            CurrentSkill.info = spellinfo;
                            CurrentSkill.Id = item.info.skill;
                            CurrentSkill.Experience = spellinfo.maximumexperience;
                            learnedSpells.Add(CurrentSkill);
                        }
                        //UPDATE A OLD SKILL
                        else
                        {
                            //Passive skill
                            if (spellinfo.skilltype == 2)
                            {
                                Saga.Factory.Spells.Info oldSpellinfo;
                                Singleton.SpellManager.TryGetSpell(PreviousSkill.info.skillid, out oldSpellinfo);

                                bool canUseOld = Singleton.SpellManager.CanUse(this.character, oldSpellinfo);
                                bool canUseNew = Singleton.SpellManager.CanUse(this.character, spellinfo);

                                if (canUseOld)
                                {
                                    Singleton.Additions.DeapplyAddition(oldSpellinfo.addition, this.character);
                                }

                                if (canUseNew)
                                {
                                    Singleton.Additions.ApplyAddition(spellinfo.addition, this.character);
                                }
                            }

                            Singleton.Database.UpgradeSkill(this.character, PreviousSkill.info.skillid,
                                item.info.skill, spellinfo.maximumexperience);
                            PreviousSkill.info = spellinfo;
                            PreviousSkill.Id = item.info.skill;
                            PreviousSkill.Experience = spellinfo.maximumexperience;
                        }

                        SMSG_SKILLADD spkt2 = new SMSG_SKILLADD();
                        spkt2.Slot = 0;
                        spkt2.SkillId = item.info.skill;
                        spkt2.SessionId = this.character.id;
                        this.Send((byte[])spkt2);

                        if (newLength > 0)
                        {
                            this.character.container[cpkt.Index].count = newLength;
                            SMSG_UPDATEITEM spkt = new SMSG_UPDATEITEM();
                            spkt.Amount = (byte)newLength;
                            spkt.UpdateReason = 8;
                            spkt.UpdateType = 4;
                            spkt.Container = 2;
                            spkt.SessionId = this.character.id;
                            spkt.Index = cpkt.Index;
                            this.Send((byte[])spkt);
                        }
                        else
                        {
                            this.character.container.RemoveAt(cpkt.Index);
                            SMSG_DELETEITEM spkt = new SMSG_DELETEITEM();
                            spkt.UpdateReason = 8;
                            spkt.Container = 2;
                            spkt.Index = cpkt.Index;
                            spkt.SessionId = this.character.id;
                            this.Send((byte[])spkt);
                        }

                        Common.Internal.CheckWeaponary(this.character);
                        Tasks.LifeCycle.Update(this.character);
                        result = 0;
                    }
                }
            }
            finally
            {
                //OUTPUT THE RESULT
                SMSG_SKILLLEARN spkt = new SMSG_SKILLLEARN();
                spkt.Result = result;
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);
            }
        }
Example #6
0
        /// <summary>
        /// Tries to add the selected skill
        /// </summary>
        /// <param name="cpkt"></param>
        private void CM_SKILLS_ADDSPECIAL(CMSG_SETSPECIALSKILL cpkt)
        {
            byte result = 1;
            try
            {
                byte slot = cpkt.Slot;
                byte NearestSlot = (byte)((slot - (slot % 4)) + 4);
                Saga.Factory.Spells.Info info;

                if (Singleton.SpellManager.TryGetSpell(cpkt.SkillID, out info))
                {
                    //Generate skill
                    Skill skill = new Skill();
                    skill.info = info;
                    skill.Id = cpkt.SkillID;

                    //Skill must be a special skill
                    if (info.special == 0) return;

                    //Check if slots don't overlap
                    if (slot + info.special > NearestSlot) return;

                    //Check if slot isn't taken yet
                    for (int i = 0; i < info.special; i++)
                        if (this.character.SpecialSkills[slot + i] != null)
                            return;

                    //Set the bytes
                    for (int i = 0; i < info.special; i++)
                        this.character.SpecialSkills[slot + i] = skill;

                    //Set the result to okay

                    Common.Internal.CheckWeaponary(this.character);
                    result = 0;
                }
            }
            finally
            {
                SMSG_SETSPECIALSKILL spkt = new SMSG_SETSPECIALSKILL();
                spkt.Result = result;
                spkt.SkillID = cpkt.SkillID;
                spkt.Slot = cpkt.Slot;
                spkt.SessionId = this.character.id;
                this.Send((byte[])spkt);
            }
        }