private void questDataReturned(SignedResponse <QuestStateCollection> data) { if (clubPenguinClient.GameServer.CurrentRoom() == null) { PendingQuestUpdateEvent item = default(PendingQuestUpdateEvent); item.eventType = EventType.SYNC_WITH_GAME_SERVER; item.syncData = data; requests.Enqueue(item); processingRequest = false; return; } clubPenguinClient.GameServer.QuestSetQuestState(data); QuestStateCollection questStateCollection = new QuestStateCollection(); questStateCollection.AddRange(data.Data); QuestStateCollection questStateCollection2 = new QuestStateCollection(); foreach (PendingQuestUpdateEvent request in requests) { PendingQuestUpdateEvent current = request; switch (current.eventType) { case EventType.STATUS_UPDATE: for (int i = 0; i < questStateCollection.Count; i++) { if (questStateCollection[i].questId == current.questId) { questStateCollection[i].status = current.status; if (current.status == QuestStatus.COMPLETED) { questStateCollection2.Add(questStateCollection[i]); } } } break; case EventType.PROGRESS_UPDATE: for (int i = 0; i < questStateCollection.Count; i++) { if (questStateCollection[i].status == QuestStatus.ACTIVE) { if (questStateCollection[i].completedObjectives == null) { questStateCollection[i].completedObjectives = new QuestObjectives(); } questStateCollection[i].completedObjectives.Add(current.objective); break; } } break; } } for (int i = 0; i < questStateCollection2.Count; i++) { questStateCollection.Remove(questStateCollection2[i]); } Service.Get <EventDispatcher>().DispatchEvent(new QuestServiceEvents.QuestStatesRecieved(questStateCollection)); }
private void setCurrentQuest(QuestStateCollection quests) { foreach (QuestState quest in quests) { if (quest.status == QuestStatus.ACTIVE) { currentQuest = quest.questId; } } }
public static QuestStateCollection GetQuestStateCollection(QuestStates states, IOfflineDefinitionLoader offlineDefinitions, bool includeComplete) { QuestStateCollection questStateCollection = new QuestStateCollection(); QuestStateCollection questStateCollection2 = new QuestStateCollection(); foreach (QuestStates.QuestState quest in states.Quests) { questStateCollection2.Add(quest); if (includeComplete || quest.status != QuestStatus.COMPLETED) { questStateCollection.Add(quest); } } foreach (QuestState item in offlineDefinitions.AvailableQuests(questStateCollection2)) { questStateCollection.Add(item); } return(questStateCollection); }
public List <QuestState> AvailableQuests(QuestStateCollection quests) { HashSet <string> hashSet = new HashSet <string>(); foreach (QuestState quest in quests) { hashSet.Add(quest.questId); } ClubPenguin.Net.Offline.PlayerAssets playerAssets = offlineDatabase.Read <ClubPenguin.Net.Offline.PlayerAssets>(); List <QuestState> list = new List <QuestState>(); Dictionary <string, QuestDefinition> knownQuests = Service.Get <QuestService>().knownQuests; foreach (KeyValuePair <string, QuestDefinition> item in knownQuests) { if (hashSet.Contains(item.Key)) { continue; } DateTime?dateTime = questAvailableDate(item.Value, playerAssets.Assets.mascotXP); if (dateTime.HasValue) { QuestState questState = new QuestState(); questState.questId = item.Key; questState.completedObjectives = new QuestObjectives(); if (dateTime <= DateTime.UtcNow) { questState.status = QuestStatus.AVAILABLE; } else { questState.status = QuestStatus.LOCKED; questState.unlockTime = dateTime.Value.GetTimeInMilliseconds(); } list.Add(questState); } } return(list); }
public QuestStatesRecieved(QuestStateCollection questStates) { QuestStates = questStates; }
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); }