Example #1
0
        public void Add(int templateID, short quantity = 1, ItemVariationType type = ItemVariationType.None)
        {
            var template = _fieldUser.Service.TemplateManager
                           .Get <ItemTemplate>(templateID);

            _fieldUser.ModifyInventory(i => i.Add(template, quantity)).Wait();
            _fieldUser.Effect(new QuestEffect(templateID, quantity)).Wait();
        }
Example #2
0
        public static async Task <QuestResult> Act(this QuestTemplate template, QuestState state, FieldUser user)
        {
            var act = template.Act[state];

            if (!user.Character.HasSlotFor(act.Items
                                           .Select(i =>
            {
                var item = user.Service.TemplateManager.Get <ItemTemplate>(i.TemplateID);
                var slot = item.ToItemSlot();

                if (slot is ItemSlotBundle bundle)
                {
                    bundle.Number = (short)i.Quantity;
                }

                return(slot);
            })
                                           .ToList()))
            {
                return(QuestResult.ActFailedInventory);
            }

            if (act.EXP != 0)
            {
                await user.ModifyStats(s => s.EXP += act.EXP);

                await user.Message(new IncEXPMessage
                {
                    EXP     = act.EXP,
                    OnQuest = true
                });
            }

            if (act.Items.Any())
            {
                await user.ModifyInventory(i =>
                                           act.Items.ForEach(ii =>
                {
                    if (ii.Quantity > 0)
                    {
                        i.Add(
                            user.Service.TemplateManager.Get <ItemTemplate>(ii.TemplateID),
                            (short)ii.Quantity
                            );
                    }
                    else
                    {
                        i.Remove(ii.TemplateID, (short)ii.Quantity);
                    }
                }
                                                             ));

                await user.Effect(new QuestEffect(act.Items
                                                  .Select(i => Tuple.Create(i.TemplateID, i.Quantity))
                                                  .ToList()));
            }

            return(QuestResult.ActSuccess);
        }
        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);
        }