public static QuestChangeResponse SetProgress(QuestObjectives objectives, OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions)
        {
            QuestStates.QuestState questState          = null;
            QuestStates            questStates         = offlineDatabase.Read <QuestStates>();
            QuestChangeResponse    questChangeResponse = new QuestChangeResponse();

            foreach (QuestStates.QuestState quest in questStates.Quests)
            {
                if (quest.status == QuestStatus.ACTIVE)
                {
                    questState = quest;
                    break;
                }
            }
            if (questState == null)
            {
                return(questChangeResponse);
            }
            if (questState.completedObjectives == null)
            {
                questState.completedObjectives = new QuestObjectives();
            }
            Reward reward = null;

            if (questState.timesCompleted == 0)
            {
                Dictionary <string, Reward> objectiveRewards = offlineDefinitions.QuestRewards(questState.questId).ObjectiveRewards;
                foreach (string objective in objectives)
                {
                    if (!questState.completedObjectives.Contains(objective) && objectiveRewards.ContainsKey(objective))
                    {
                        if (reward == null)
                        {
                            reward = new Reward();
                        }
                        reward.AddReward(objectiveRewards[objective]);
                    }
                }
            }
            if (reward != null)
            {
                offlineDefinitions.AddReward(reward, questChangeResponse);
            }
            questState.completedObjectives = objectives;
            offlineDatabase.Write(questStates);
            questChangeResponse.questId = questState.questId;
            questChangeResponse.questStateCollection = new SignedResponse <QuestStateCollection>
            {
                Data = GetQuestStateCollection(questStates, offlineDefinitions, includeComplete: false)
            };
            if (reward != null)
            {
                JsonService jsonService = Service.Get <JsonService>();
                questChangeResponse.reward = jsonService.Deserialize <RewardJsonReader>(jsonService.Serialize(RewardJsonWritter.FromReward(reward)));
            }
            return(questChangeResponse);
        }
        public static void SetOfflineQuestStateCollection(OfflineDatabase offlineDatabase, QuestStateCollection quests)
        {
            QuestStates value = offlineDatabase.Read <QuestStates>();

            foreach (QuestState quest in quests)
            {
                bool flag = false;
                foreach (QuestStates.QuestState quest2 in value.Quests)
                {
                    if (quest2.questId == quest.questId)
                    {
                        quest2.completedObjectives = quest.completedObjectives;
                        quest2.unlockTime          = quest.unlockTime;
                        quest2.status         = quest.status;
                        quest2.timesCompleted = quest.timesCompleted;
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    QuestStates.QuestState questState = new QuestStates.QuestState();
                    questState.questId             = quest.questId;
                    questState.completedObjectives = quest.completedObjectives;
                    questState.timesCompleted      = quest.timesCompleted;
                    questState.status     = quest.status;
                    questState.unlockTime = quest.unlockTime;
                    QuestStates.QuestState current2 = questState;
                    if (current2.status == QuestStatus.COMPLETED)
                    {
                        current2.completedTime = DateTime.UtcNow;
                    }
                    value.Quests.Add(current2);
                }
            }
            offlineDatabase.Write(value);
        }
        public static QuestChangeResponse SetStatus(QuestStatus status, string questId, OfflineDatabase offlineDatabase, IOfflineDefinitionLoader offlineDefinitions)
        {
            QuestChangeResponse questChangeResponse = new QuestChangeResponse();
            QuestStates         questStates         = offlineDatabase.Read <QuestStates>();

            QuestStates.QuestState questState = null;
            int num = -1;

            for (int i = 0; i < questStates.Quests.Count; i++)
            {
                if (questStates.Quests[i].questId == questId)
                {
                    questState = questStates.Quests[i];
                    num        = i;
                    break;
                }
            }
            QuestRewardsCollection questRewardsCollection = offlineDefinitions.QuestRewards(questId);
            Reward reward = null;

            if (questState == null)
            {
                reward = questRewardsCollection.StartReward;
                if (reward != null)
                {
                    if (reward.isEmpty())
                    {
                        reward = null;
                    }
                    else
                    {
                        offlineDefinitions.AddReward(reward, questChangeResponse);
                    }
                }
                questState         = new QuestStates.QuestState();
                questState.questId = questId;
            }
            if (status == QuestStatus.ACTIVE)
            {
                for (int i = 0; i < questStates.Quests.Count; i++)
                {
                    if (questStates.Quests[i].status == QuestStatus.ACTIVE)
                    {
                        questStates.Quests[i].status = QuestStatus.SUSPENDED;
                    }
                }
                if (questState.status == QuestStatus.COMPLETED)
                {
                    questState.completedObjectives.Clear();
                }
            }
            if (status == QuestStatus.COMPLETED)
            {
                int timesCompleted = questState.timesCompleted;
                if (timesCompleted == 0)
                {
                    questState.completedTime = DateTime.UtcNow;
                    reward = questRewardsCollection.CompleteReward;
                    if (reward != null)
                    {
                        if (reward.isEmpty())
                        {
                            reward = null;
                        }
                        else
                        {
                            offlineDefinitions.AddReward(reward, questChangeResponse);
                        }
                    }
                }
                questState.timesCompleted = timesCompleted + 1;
            }
            questState.status = status;
            if (num >= 0)
            {
                questStates.Quests[num] = questState;
            }
            else
            {
                questStates.Quests.Add(questState);
            }
            offlineDatabase.Write(questStates);
            JsonService jsonService = Service.Get <JsonService>();

            if (reward != null)
            {
                questChangeResponse.reward = jsonService.Deserialize <RewardJsonReader>(jsonService.Serialize(RewardJsonWritter.FromReward(reward)));
            }
            questChangeResponse.questId = questId;
            questChangeResponse.questStateCollection = new SignedResponse <QuestStateCollection>
            {
                Data = SetProgressOperation.GetQuestStateCollection(questStates, offlineDefinitions, includeComplete: false)
            };
            return(questChangeResponse);
        }