Exemple #1
0
        /// <summary>
        /// Retrieves the requested quest step.
        /// </summary>
        /// <param name="questStepKey">Unique identifier of the quest step.</param>
        /// <returns>An awaitable task that returns the requested <see cref="QuestStepDto"/>.</returns>
        public async Task <QuestStepDto> GetQuestStepAsync(Guid questStepKey)
        {
            // Get quest step
            var questStep = await questRepository.GetQuestStepAsync(questStepKey);

            // Get quest progression
            var hasQuestProgression = await questRepository.HasQuestProgresssionAsync(questStep.QuestKey);

            // Add progression to dto
            var retval = questStep.ToDto();

            retval.CanReorder = !hasQuestProgression;
            return(retval);
        }
        /// <summary>
        /// Adds a new progress entry to the quest step for the given account.
        /// </summary>
        /// <param name="questStepProgressionDto">Contains the quest step progression data.</param>
        /// <returns>An awaitable task that returns true if the quest step progression has been added.</returns>
        public async Task <bool> ProgressAsync(QuestStepProgressionDto questStepProgressionDto)
        {
            // Get quest steps
            var questStep = await questRepository.GetQuestStepAsync(questStepProgressionDto.QuestStepKey);

            if (questStep == null)
            {
                return(false);
            }

            var existingQuestStepProgression = await questStepProgressionRepository.GetQuestStepProgressionAsync(questStepProgressionDto.QuestStepKey, questStepProgressionDto.Username);

            if (existingQuestStepProgression != null)
            {
                return(false);
            }

            // Check if previous quest step is done
            if (questStep.SortOrder > 0)
            {
                var previousQuestStepDone = await questStepProgressionRepository.IsPreviousQuestStepDone(questStep.QuestKey, questStepProgressionDto.Username, questStep.SortOrder - 1);

                if (!previousQuestStepDone)
                {
                    return(false);
                }
            }

            // Add new quest step progression
            var questStepProgression = new QuestStepProgression
            {
                Username                = questStepProgressionDto.Username,
                QuestStepKey            = questStep.QuestStepKey,
                QuestStepProgressionKey = Guid.NewGuid(),
                ResolvedOn              = DateTime.Now
            };

            questStepProgressionRepository.Save(questStepProgression, ctx => ctx.QuestStepProgression, qsp => qsp.QuestStepProgressionKey == questStepProgression.QuestStepProgressionKey);

            return(true);
        }