Ejemplo n.º 1
0
        public static void EncodeData(this Character c, IPacket p, DbChar flags = DbChar.All)
        {
            p.Encode <long>((long)flags);
            p.Encode <byte>(0);
            p.Encode <byte>(0);

            if (flags.HasFlag(DbChar.Character))
            {
                EncodeStats(c, p);
                p.Encode <byte>(250); // nFriendMax
                p.Encode <bool>(false);
            }

            if (flags.HasFlag(DbChar.Money))
            {
                p.Encode <int>(c.Money);
            }

            if (flags.HasFlag(DbChar.InventorySize))
            {
                if (flags.HasFlag(DbChar.ItemSlotEquip))
                {
                    p.Encode <byte>((byte)c.Inventories[ItemInventoryType.Equip].SlotMax);
                }
                if (flags.HasFlag(DbChar.ItemSlotConsume))
                {
                    p.Encode <byte>((byte)c.Inventories[ItemInventoryType.Consume].SlotMax);
                }
                if (flags.HasFlag(DbChar.ItemSlotInstall))
                {
                    p.Encode <byte>((byte)c.Inventories[ItemInventoryType.Install].SlotMax);
                }
                if (flags.HasFlag(DbChar.ItemSlotEtc))
                {
                    p.Encode <byte>((byte)c.Inventories[ItemInventoryType.Etc].SlotMax);
                }
                if (flags.HasFlag(DbChar.ItemSlotCash))
                {
                    p.Encode <byte>((byte)c.Inventories[ItemInventoryType.Cash].SlotMax);
                }
            }

            if (flags.HasFlag(DbChar.AdminShopCount))
            {
                p.Encode <int>(0);
                p.Encode <int>(0);
            }

            if (flags.HasFlag(DbChar.ItemSlotEquip))
            {
                var inventory        = c.Inventories[ItemInventoryType.Equip].Items;
                var equip            = inventory.Where(kv => kv.Key >= 0);
                var equipped         = inventory.Where(kv => kv.Key >= -100 && kv.Key < 0);
                var equipped2        = inventory.Where(kv => kv.Key >= -1000 && kv.Key < -100);
                var dragonEquipped   = inventory.Where(kv => kv.Key >= -1100 && kv.Key < -1000);
                var mechanicEquipped = inventory.Where(kv => kv.Key >= -1200 && kv.Key < -1100);

                new List <IEnumerable <KeyValuePair <short, ItemSlot> > >
                {
                    equipped, equipped2, equip, dragonEquipped, mechanicEquipped
                }
                .ForEach(e =>
                {
                    e.ForEach(kv =>
                    {
                        p.Encode <short>((short)(Math.Abs(kv.Key) % 100));
                        kv.Value.Encode(p);
                    });
                    p.Encode <short>(0);
                });
            }

            new List <(DbChar, ItemInventoryType)>
            {
                (DbChar.ItemSlotConsume, ItemInventoryType.Consume),
                (DbChar.ItemSlotInstall, ItemInventoryType.Install),
                (DbChar.ItemSlotEtc, ItemInventoryType.Etc),
                (DbChar.ItemSlotCash, ItemInventoryType.Cash)
            }
            .Where(t => flags.HasFlag(t.Item1))
            .ForEach(t =>
            {
                var inventory = c.Inventories[t.Item2].Items;

                inventory.ForEach(kv =>
                {
                    p.Encode <byte>((byte)kv.Key);
                    kv.Value.Encode(p);
                });
                p.Encode <byte>(0);
            });

            if (flags.HasFlag(DbChar.SkillRecord))
            {
                p.Encode <short>((short)c.SkillRecord.Count);
                c.SkillRecord.ForEach(kv =>
                {
                    p.Encode <int>(kv.Key);
                    p.Encode <int>(kv.Value.Level);
                    p.Encode <DateTime>(kv.Value.DateExpire ?? ItemConstants.Permanent);

                    if (SkillConstants.IsSkillNeedMasterLevel(kv.Key))
                    {
                        p.Encode <int>(kv.Value.MasterLevel);
                    }
                });
            }

            if (flags.HasFlag(DbChar.SkillCooltime))
            {
                p.Encode <short>(0);
            }

            if (flags.HasFlag(DbChar.QuestRecord))
            {
                p.Encode <short>((short)c.QuestRecord.Count);
                c.QuestRecord.ForEach(q =>
                {
                    p.Encode <short>(q.Key);
                    p.Encode <string>(q.Value);
                });
            }

            if (flags.HasFlag(DbChar.QuestComplete))
            {
                p.Encode <short>((short)c.QuestComplete.Count);
                c.QuestComplete.ForEach(q =>
                {
                    p.Encode <short>(q.Key);
                    p.Encode <DateTime>(q.Value);
                });
            }

            if (flags.HasFlag(DbChar.MinigameRecord))
            {
                p.Encode <short>(0);
            }

            if (flags.HasFlag(DbChar.CoupleRecord))
            {
                p.Encode <short>(0); // Couple
                p.Encode <short>(0); // Friend
                p.Encode <short>(0); // Marriage
            }

            if (flags.HasFlag(DbChar.MapTransfer))
            {
                for (var i = 0; i < 5; i++)
                {
                    p.Encode <int>(0);
                }
                for (var i = 0; i < 10; i++)
                {
                    p.Encode <int>(0);
                }
            }

            if (flags.HasFlag(DbChar.NewYearCard))
            {
                p.Encode <short>(0);
            }

            if (flags.HasFlag(DbChar.QuestRecordEx))
            {
                p.Encode <short>((short)c.QuestRecordEx.Count);
                c.QuestRecordEx.ForEach(q =>
                {
                    p.Encode <short>(q.Key);
                    p.Encode <string>(q.Value);
                });
            }

            if (flags.HasFlag(DbChar.WildHunterInfo))
            {
                if (c.Job / 100 == 33)
                {
                    p.Encode <byte>(0);
                    for (var i = 0; i < 5; i++)
                    {
                        p.Encode <int>(0);
                    }
                }
            }

            if (flags.HasFlag(DbChar.QuestCompleteOld))
            {
                p.Encode <short>(0);
            }

            if (flags.HasFlag(DbChar.VisitorLog))
            {
                p.Encode <short>(0);
            }
        }
        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);
        }