Beispiel #1
0
        public static void EncodeStats(this Character c, IPacket p)
        {
            p.Encode <int>(c.ID);
            p.EncodeFixedString(c.Name, 13);

            p.Encode <byte>(c.Gender);
            p.Encode <byte>(c.Skin);
            p.Encode <int>(c.Face);
            p.Encode <int>(c.Hair);

            c.Pets.ForEach(sn => p.Encode <long>(sn));

            p.Encode <byte>(c.Level);
            p.Encode(c.Job);
            p.Encode <short>(c.STR);
            p.Encode <short>(c.DEX);
            p.Encode <short>(c.INT);
            p.Encode <short>(c.LUK);
            p.Encode <int>(c.HP);
            p.Encode <int>(c.MaxHP);
            p.Encode <int>(c.MP);
            p.Encode <int>(c.MaxMP);

            p.Encode <short>(c.AP);
            if (SkillConstants.IsExtendSPJob(c.Job))
            {
                c.EncodeExtendSP(p);
            }
            else
            {
                p.Encode <short>(c.SP);
            }

            p.Encode <int>(c.EXP);
            p.Encode <short>(c.POP);

            p.Encode <int>(c.TempEXP);
            p.Encode <int>(c.FieldID);
            p.Encode <byte>(c.FieldPortal);
            p.Encode <int>(c.PlayTime);
            p.Encode <short>(c.SubJob);
        }
        public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user)
        {
            packet.Decode <int>();
            var templateID = packet.Decode <int>();
            var template   = user.Service.TemplateManager.Get <SkillTemplate>(templateID);

            Console.WriteLine(template);

            if (template == null)
            {
                return;
            }

            var job      = template.ID / 10000;
            var jobLevel = (byte)SkillConstants.GetJobLevel(job);

            if (jobLevel == 0)
            {
                var sp = Math.Min(user.Character.Level - 1, job == 3000 ? 9 : 6);
                for (var i = 0; i < 3; i++)
                {
                    sp -= user.Character.GetSkillLevel(job * 1000 + 1000 + i);
                }
                if (sp > 0)
                {
                    await user.ModifySkills(s => s.Add(templateID), true);
                }
                return;
            }

            if (SkillConstants.IsExtendSPJob(job) && user.Character.GetExtendSP(jobLevel) <= 0)
            {
                return;
            }
            if (!SkillConstants.IsExtendSPJob(job) && user.Character.SP <= 0)
            {
                return;
            }

            var maxLevel = template.MaxLevel;

            if (SkillConstants.IsSkillNeedMasterLevel(templateID))
            {
                maxLevel = (short)user.Character.GetSkillMasterLevel(templateID);
            }

            if (user.Character.GetSkillLevel(templateID) >= maxLevel)
            {
                return;
            }

            await user.ModifyStats(s =>
            {
                if (SkillConstants.IsExtendSPJob(job))
                {
                    s.SetExtendSP(jobLevel, (byte)(s.GetExtendSP(jobLevel) - 1));
                }
                else
                {
                    s.SP--;
                }
            });

            await user.ModifySkills(s => s.Add(templateID), true);
        }