Exemplo n.º 1
0
        public override async Task Handle(RecvPacketOperations operation, IPacket packet, FieldUser user)
        {
            var action     = (QuestRequest)packet.Decode <byte>();
            var templateID = packet.Decode <short>();
            var template   = user.Service.TemplateManager.Get <QuestTemplate>(templateID);

            if (template == null)
            {
                return;
            }

            var state = user.Character.GetQuestState(templateID);

            if (state == QuestState.Perform &&
                action == QuestRequest.ResignQuest
                )
            {
                await user.ModifyQuests(q => q.Resign(templateID));

                return;
            }

            // TODO: repeatable quests
            if (state != QuestState.Perform &&
                action == QuestRequest.CompleteQuest ||
                state != QuestState.None &&
                action == QuestRequest.AcceptQuest
                )
            {
                return;
            }

            var result = await template.Check(state, user);

            if (result == QuestResult.ActSuccess)
            {
                result = await template.Act(state, user);
            }

            if (result != QuestResult.ActSuccess)
            {
                using (var p = new Packet(SendPacketOperations.UserQuestResult))
                {
                    p.Encode <byte>((byte)result);
                    p.Encode <short>(templateID);
                    await user.SendPacket(p);
                }

                return;
            }

            await(action switch {
                QuestRequest.AcceptQuest => user.ModifyQuests(q => q.Accept(templateID)),
                QuestRequest.CompleteQuest => user.ModifyQuests(q => q.Complete(templateID)),
                _ => Task.CompletedTask
            });
Exemplo n.º 2
0
        protected override async Task ExecuteAfter(FieldUser sender, QuestTemplate template, QuestCommandOption option)
        {
            await sender.ModifyQuests(q =>
            {
                switch (option.State)
                {
                default:
                case QuestState.No:
                    q.Resign((short)template.ID);
                    break;

                case QuestState.Perform:
                    q.Accept((short)template.ID);
                    break;

                case QuestState.Complete:
                    q.Complete((short)template.ID);
                    break;
                }
            });

            await sender.Message($"Successfully set quest {template.ID} to {option.State}");
        }
Exemplo n.º 3
0
        protected override async Task Execute(FieldUser sender, object option)
        {
            var records = _ex ? sender.Character.QuestRecordEx : sender.Character.QuestRecord;

            if (!records.Any())
            {
                await sender.Prompt(target => target.Say("You don't have any quest records."));

                return;
            }

            var templateID = await sender.Prompt <int>(target => target.AskMenu(
                                                           $"Here are your quest records",
                                                           records.ToDictionary(
                                                               r => (int)r.Key,
                                                               r => $"{r.Key}: {r.Value}"
                                                               )
                                                           ));

            var record = await sender.Prompt <string>(target => target.AskText(
                                                          "What record would you like to set?",
                                                          records[(short)templateID]
                                                          ));

            await sender.ModifyQuests(q =>
            {
                if (_ex)
                {
                    q.UpdateEx((short)templateID, record);
                }
                else
                {
                    q.Update((short)templateID, record);
                }
            });
        }