/// <summary> /// Tries to parse the <see cref="QuestID"/> from a string. /// </summary> /// <param name="parser">The <see cref="Parser"/> to use.</param> /// <param name="value">The string to parse.</param> /// <param name="outValue">If this method returns true, contains the parsed <see cref="QuestID"/>.</param> /// <returns>True if the parsing was successfully; otherwise false.</returns> public static bool TryParse(this Parser parser, string value, out QuestID outValue) { ushort tmp; var ret = parser.TryParse(value, out tmp); outValue = new QuestID(tmp); return(ret); }
/// <summary> /// Sets whether or not we have the requirements for a quest. /// </summary> /// <param name="questID">The ID of the quest.</param> /// <param name="hasRequirements">True if we have the requirements for the quest; false if we do not.</param> public void SetRequirementsStatus(QuestID questID, bool hasRequirements) { if (!_statuses.ContainsKey(questID)) { _statuses.Add(questID, hasRequirements); } else { _statuses[questID] = hasRequirements; } }
/// <summary> /// Starts getting the status for the given <paramref name="quest"/> if the value is not already acquired. /// </summary> /// <param name="quest">The quest to get the status for.</param> public void Prepare(QuestID quest) { if (_statuses.ContainsKey(quest)) { return; } _statuses.Add(quest, null); _sendRequest(quest); }
/// <summary> /// Gets the <see cref="IQuestDescription"/> for a quest. /// </summary> /// <param name="questID">The ID of the quest to get the <see cref="IQuestDescription"/> for.</param> /// <returns>The <see cref="IQuestDescription"/> for the given <see cref="QuestID"/>.</returns> public IQuestDescription this[QuestID questID] { get { if (!_questDescriptions.CanGet(questID.GetRawValue())) { return(null); } return(_questDescriptions[questID.GetRawValue()]); } }
/// <summary> /// Forces a quest in this collection to be reloaded from the database. /// Note that reloading an object will create a new object, not update the existing object. As a result, anything referencing /// the old object will continue to reference the old values instead of the newly loaded values. /// </summary> /// <param name="questID">The ID of the quest to force to reload.</param> public virtual void Reload(QuestID questID) { // Check for a valid ID range if (questID < 0 || questID > _quests.Length) { return; } // Try to load the quest var q = LoadQuest(questID); _quests[questID.GetRawValue()] = q; }
/// <summary> /// Gets if the user has the requirements for the given quest. /// </summary> /// <param name="quest">The ID of the quest to check for the requirements of.</param> /// <returns>True if the user has the requirements for the given <paramref name="quest"/>, false if they /// do not have the requirements, or null if the status is currently unknown.</returns> public bool?HasRequirements(QuestID quest) { bool?value; // Try to get the cached value if (!_statuses.TryGetValue(quest, out value)) { // Value was not in the cache, so make the request, and return null for now value = null; Prepare(quest); } return(value); }
/// <summary> /// Gets the <see cref="IQuestDescription"/> for a quest, or an empty description if the quest /// description could not be found for the specified <paramref name="questID"/>. /// </summary> /// <param name="questID">The ID of the quest to get the <see cref="IQuestDescription"/> for.</param> /// <returns>The <see cref="IQuestDescription"/> for a quest, or an empty description if the quest /// description could not be found for the specified <paramref name="questID"/>.</returns> public IQuestDescription GetOrDefault(QuestID questID) { var ret = this[questID]; if (ret == null) { return(new QuestDescription { Name = "[Unknown Quest: " + questID + "]", Description = "No description for this quest could be found.", QuestID = questID }); } else { return(ret); } }
/// <summary> /// Forces a quest in this collection to be reloaded from the database. /// Note that reloading an object will create a new object, not update the existing object. As a result, anything referencing /// the old object will continue to reference the old values instead of the newly loaded values. /// </summary> /// <param name="questID">The ID of the quest to force to reload.</param> public virtual void Reload(QuestID questID) { // Check for a valid ID range if (questID < 0) { return; } // Resize the array if needed if (questID.GetRawValue() >= _quests.Length) { Array.Resize(ref _quests, questID.GetRawValue() + 1); } // Try to load the quest var q = LoadQuest(questID); _quests[questID.GetRawValue()] = q; }
/// <summary> /// When overridden in the derived class, allows for handling the /// <see cref="UserQuestInformation.ActiveQuestRemoved"/> event. /// </summary> /// <param name="questID">The ID of the quest that was removed.</param> protected virtual void OnActiveQuestRemoved(QuestID questID) { }
/// <summary> /// Reads the <see cref="QuestID"/> from a <see cref="BitStream"/>. /// </summary> /// <param name="bitStream"><see cref="BitStream"/> to read the <see cref="QuestID"/> from.</param> /// <returns>The <see cref="QuestID"/> read from the <see cref="BitStream"/>.</returns> public static QuestID ReadQuestID(this BitStream bitStream) { return(QuestID.Read(bitStream)); }
/// <summary> /// Reads the <see cref="QuestID"/> from an IValueReader. /// </summary> /// <param name="valueReader"><see cref="IValueReader"/> to read the <see cref="QuestID"/> from.</param> /// <param name="name">The unique name of the value to read.</param> /// <returns>The <see cref="QuestID"/> read from the IValueReader.</returns> public static QuestID ReadQuestID(this IValueReader valueReader, string name) { return(QuestID.Read(valueReader, name)); }
/// <summary> /// Reads the <see cref="QuestID"/> from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="QuestID"/> from.</param> /// <param name="i">The field index to read.</param> /// <returns>The <see cref="QuestID"/> read from the <see cref="IDataRecord"/>.</returns> public static QuestID GetQuestID(this IDataRecord r, int i) { return(QuestID.Read(r, i)); }
/// <summary> /// Reads the <see cref="QuestID"/> from an <see cref="IDataRecord"/>. /// </summary> /// <param name="r"><see cref="IDataRecord"/> to read the <see cref="QuestID"/> from.</param> /// <param name="name">The name of the field to read the value from.</param> /// <returns>The <see cref="QuestID"/> read from the <see cref="IDataRecord"/>.</returns> public static QuestID GetQuestID(this IDataRecord r, string name) { return(QuestID.Read(r, name)); }
/// <summary> /// When overridden in the derived class, allows for handling the /// <see cref="UserQuestInformation.RepeatableQuestAdded"/> event. /// </summary> /// <param name="questID">The ID of the quest that was added.</param> protected virtual void OnRepeatableQuestAdded(QuestID questID) { }
/// <summary> /// Tries to get the value in the <paramref name="dict"/> entry at the given <paramref name="key"/> as a /// <see cref="QuestID"/>. /// </summary> /// <typeparam name="T">The key Type.</typeparam> /// <param name="dict">The <see cref="IDictionary{TKey, TValue}"/>.</param> /// <param name="key">The key for the value to get.</param> /// <param name="defaultValue">The value to use if the value at the <paramref name="key"/> could not be parsed.</param> /// <returns>The value at the given <paramref name="key"/> parsed as an int, or the /// <paramref name="defaultValue"/> if the <paramref name="key"/> did not exist in the <paramref name="dict"/> /// or the value at the given <paramref name="key"/> could not be parsed.</returns> public static QuestID AsQuestID <T>(this IDictionary <T, string> dict, T key, QuestID defaultValue) { string value; if (!dict.TryGetValue(key, out value)) { return(defaultValue); } QuestID parsed; if (!Parser.Invariant.TryParse(value, out parsed)) { return(defaultValue); } return(parsed); }
/// <summary> /// Gets the quest for the given <see cref="QuestID"/>. /// </summary> /// <param name="id">The <see cref="QuestID"/> to get.</param> /// <returns>The quest for the given <paramref name="id"/>, or null if the <paramref name="id"/> is invalid.</returns> public IQuest <TCharacter> this[QuestID id] { get { return(GetQuest(id)); } }
/// <summary> /// When overridden in the derived class, loads the quest with the specified <see cref="QuestID"/>. /// </summary> /// <param name="questID">The ID of the quest to load.</param> /// <returns>The <see cref="IQuest{TCharacter}"/> for the <paramref name="questID"/>.</returns> protected abstract IQuest <TCharacter> LoadQuest(QuestID questID);
/// <summary> /// Gets if the user has the requirements to finish the given quest. /// </summary> /// <param name="questID">The ID of the quest to finish.</param> /// <returns>True if the user has the requirements to finish the quest with the given <paramref name="questID"/>; /// otherwise false.</returns> protected virtual bool HasFinishQuestReqs(QuestID questID) { return(_hasFinishQuestReqs(questID)); }
/// <summary> /// Appends a message to a <see cref="BitStream"/> for synchronizing the client's quest information for when /// a quest is repeatable. /// The message is then read and handled by the receiver using <see cref="UserQuestInformation.Read"/>. /// </summary> /// <param name="bs">The <see cref="BitStream"/> to append the message to.</param> /// <param name="questID">The ID of the repeatable quest.</param> public static void WriteAddRepeatableQuest(BitStream bs, QuestID questID) { bs.WriteEnum(QuestInfoMessages.AddRepeatableQuest); bs.Write(questID); }
/// <summary> /// Writes a <see cref="QuestID"/> to a <see cref="BitStream"/>. /// </summary> /// <param name="bitStream"><see cref="BitStream"/> to write to.</param> /// <param name="value"><see cref="QuestID"/> to write.</param> public static void Write(this BitStream bitStream, QuestID value) { value.Write(bitStream); }
/// <summary> /// When overridden in the derived class, allows for handling the /// <see cref="UserQuestInformation.ActiveQuestAdded"/> event. /// </summary> /// <param name="questID">The ID of the quest that was added.</param> protected virtual void OnActiveQuestAdded(QuestID questID) { }
/// <summary> /// Appends a message to a <see cref="BitStream"/> for synchronizing the client's quest information for when /// a quest is removed from the active quests. /// The message is then read and handled by the receiver using <see cref="UserQuestInformation.Read"/>. /// </summary> /// <param name="bs">The <see cref="BitStream"/> to append the message to.</param> /// <param name="questID">The ID of the removed active quest.</param> public static void WriteRemoveActiveQuest(BitStream bs, QuestID questID) { bs.WriteEnum(QuestInfoMessages.RemoveActiveQuest); bs.Write(questID); }
/// <summary> /// Appends a message to a <see cref="BitStream"/> for synchronizing the client's quest information for when /// a quest is completed. /// The message is then read and handled by the receiver using <see cref="UserQuestInformation.Read"/>. /// </summary> /// <param name="bs">The <see cref="BitStream"/> to append the message to.</param> /// <param name="questID">The ID of the completed quest.</param> public static void WriteAddCompletedQuest(BitStream bs, QuestID questID) { bs.WriteEnum(QuestInfoMessages.AddCompletedQuest); bs.Write(questID); }
/// <summary> /// Updates the status for the given <paramref name="quest"/>. /// </summary> /// <param name="quest">The quest to get the status for.</param> public void Update(QuestID quest) { _sendRequest(quest); }
/// <summary> /// Writes a <see cref="QuestID"/> to a <see cref="IValueWriter"/>. /// </summary> /// <param name="valueWriter"><see cref="IValueWriter"/> to write to.</param> /// <param name="name">Unique name of the <see cref="QuestID"/> that will be used to distinguish it /// from other values when reading.</param> /// <param name="value"><see cref="QuestID"/> to write.</param> public static void Write(this IValueWriter valueWriter, string name, QuestID value) { value.Write(valueWriter, name); }
/// <summary> /// When overridden in the derived class, allows for handling the /// <see cref="UserQuestInformation.CompletedQuestAdded"/> event. /// </summary> /// <param name="questID">The ID of the quest that was added.</param> protected virtual void OnCompletedQuestAdded(QuestID questID) { }
/// <summary> /// Gets if the user has the requirements to start the given quest. /// </summary> /// <param name="questID">The ID of the quest to start.</param> /// <returns>True if the user has the requirements to start the quest with the given <paramref name="questID"/>; /// otherwise false.</returns> protected virtual bool HasStartQuestReqs(QuestID questID) { return(_hasStartQuestReqs(questID)); }
/// <summary> /// Gets the <see cref="IQuest{TCharacter}"/> for a given <see cref="QuestID"/>. /// </summary> /// <param name="questID">The ID of the quest.</param> /// <returns>The <see cref="IQuest{TCharacter}"/> for the given <paramref name="questID"/>.</returns> public IQuest <TCharacter> GetQuest(QuestID questID) { return(_quests[questID.GetRawValue()]); }