Exemplo n.º 1
0
        protected override async Task Execute(FieldUser sender, BuffCommandOption option)
        {
            var type = (TemporaryStatType)(option.List
                ? await sender.Prompt <int>(target => target.AskMenu(
                                                "These are your current temporary stats",
                                                sender.TemporaryStats
                                                .ToDictionary(
                                                    kv => (int)kv.Key,
                                                    kv => $"{kv.Key}: {kv.Value.Option}"
                                                    )
                                                ))
                : await sender.Prompt <int>(target => target.AskMenu(
                                                "Which temporary stat type?",
                                                Enum.GetValues(typeof(TemporaryStatType))
                                                .Cast <TemporaryStatType>()
                                                .ToDictionary(
                                                    t => (int)t,
                                                    t => t.ToString()
                                                    )
                                                )));

            if (option.List &&
                await sender.Prompt <int>(target => target.AskMenu(
                                              $"What would you like to do with {type}?",
                                              new Dictionary <int, string>
            {
                [0] = "Modify the stat option",
                [1] = "#rRemove the stat"
            }
                                              )) > 0)
            {
                await sender.ModifyTemporaryStats(s => s.Reset(type));

                return;
            }

            var options = await sender.Prompt <int>(target => target.AskNumber(
                                                        "What option?",
                                                        1,
                                                        1
                                                        ));

            var templateID = await sender.Prompt <int>(target => target.AskNumber(
                                                           "What template ID?",
                                                           (int)Skill.CitizenCristalThrow
                                                           ));

            await sender.ModifyTemporaryStats(s =>
                                              s.Set(
                                                  type,
                                                  templateID,
                                                  options
                                                  ));
        }
        public override async Task Handle(
            RecvPacketOperations operation,
            IPacket packet,
            FieldUser user,
            StatChangeItemTemplate template,
            ItemSlot item
            )
        {
            var stats = template.GetTemporaryStats();

            if (stats.Count > 0)
            {
                await user.ModifyTemporaryStats(ts =>
                {
                    if (template.Time > 0)
                    {
                        var expire = DateTime.Now.AddSeconds(template.Time);
                        stats.ForEach(t => ts.Set(t.Key, -template.ID, t.Value, expire));
                    }
                    else
                    {
                        stats.ForEach(t => ts.Set(t.Key, -template.ID, t.Value));
                    }
                });
            }

            if (!stats.ContainsKey(TemporaryStatType.Morph))
            {
                var incHP = 0;
                var incMP = 0;

                incHP += template.HP;
                incMP += template.MP;
                incHP += user.BasicStat.MaxHP * (template.HPr / 100);
                incMP += user.BasicStat.MaxMP * (template.MPr / 100);

                if (incHP > 0 || incMP > 0)
                {
                    await user.ModifyStats(s =>
                    {
                        s.HP += incHP;
                        s.MP += incMP;
                    });
                }
            }

            await user.ModifyInventory(i => i.Remove(item, 1), true);
        }
        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);
            var skillLevel = user.Character.GetSkillLevel(templateID);

            if (template == null)
            {
                return;
            }
            if (skillLevel <= 0)
            {
                return;
            }

            var level = template.LevelData[skillLevel];
            var stats = level.GetTemporaryStats();

            if (stats.Count > 0)
            {
                await user.ModifyTemporaryStats(ts =>
                {
                    if (level.Time > 0)
                    {
                        var expire = DateTime.Now.AddSeconds(level.Time);
                        stats.ForEach(t => ts.Set(t.Key, templateID, t.Value, expire));
                    }
                    else
                    {
                        stats.ForEach(t => ts.Set(t.Key, templateID, t.Value));
                    }
                });
            }
            // TODO: party/map buffs

            await user.Effect(new SkillUseEffect(templateID, (byte)skillLevel), local : false, remote : true);

            await user.ModifyStats(exclRequest : true);
        }
        public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user)
        {
            var templateID = packet.Decode <int>();
            var template   = user.Service.TemplateManager.Get <SkillTemplate>(templateID);

            if (template == null)
            {
                return;
            }
            if (SkillConstants.IsKeydownSkill(templateID))
            {
                using var p = new Packet(SendPacketOperations.UserSkillCancel);
                p.Encode <int>(user.ID);
                p.Encode <int>(templateID);

                await user.Field.BroadcastPacket(user, p);
            }
            else
            {
                await user.ModifyTemporaryStats(ts => ts.Reset(templateID));
            }
        }