public void Initialize(NWGameObject player, string questID) { var playerID = GetGlobalID(player); var status = QuestProgressRepo.Get(playerID, questID); var progress = new QuestProgress.KillProgress { NPCGroupID = _group, Remaining = _amount }; status.KillProgresses.Add(progress); QuestProgressRepo.Set(playerID, status); }
public void Initialize(NWGameObject player, string questID) { var playerID = GetGlobalID(player); var status = QuestProgressRepo.Get(playerID, questID); var itemProgress = new QuestProgress.ItemProgress { Resref = _resref, Remaining = _quantity }; status.ItemProgresses.Add(itemProgress); QuestProgressRepo.Set(playerID, status); }
/// <summary> /// Completes a quest for a player. If a reward is selected, that reward will be given to the player. /// Otherwise, all rewards configured for this quest will be given to the player. /// </summary> /// <param name="player">The player completing the quest.</param> /// <param name="questSource">The source of the quest completion</param> /// <param name="selectedReward">The reward selected by the player</param> internal void Complete(NWGameObject player, NWGameObject questSource, IQuestReward selectedReward) { if (!GetIsPlayer(player)) { return; } if (!CanComplete(player)) { return; } var playerID = GetGlobalID(player); var pcState = QuestProgressRepo.Get(playerID, QuestID); // Mark player as being on the last state of the quest. pcState.CurrentState = GetStates().Count(); pcState.TimesCompleted++; // No selected reward, simply give all available rewards to the player. if (selectedReward == null) { foreach (var reward in Rewards) { reward.GiveReward(player); } } // There is a selected reward. Give that reward and any rewards which are not selectable to the player. else { // Non-selectable rewards (gold, GP, etc) are granted to the player. foreach (var reward in Rewards.Where(x => !x.IsSelectable)) { reward.GiveReward(player); } selectedReward.GiveReward(player); } QuestProgressRepo.Set(playerID, pcState); foreach (var action in _onCompleteActions) { action.Invoke(player, questSource); } SendMessageToPC(player, "Quest '" + Name + "' complete!"); RemoveJournalQuestEntry(JournalTag, player, false); Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestCompleted(player, QuestID)); }
/// <summary> /// Accepts a quest using the configured settings. /// </summary> /// <param name="player">The player accepting the quest.</param> /// <param name="questSource">The source of the quest giver</param> internal void Accept(NWGameObject player, NWGameObject questSource) { if (!GetIsPlayer(player)) { return; } if (!CanAccept(player)) { return; } var playerID = GetGlobalID(player); // By this point, it's assumed the player will accept the quest. var status = QuestProgressRepo.Get(playerID, QuestID); // Retrieve the first quest state for this quest. status.CurrentState = 1; status.QuestID = QuestID; // Insert or update player's quest status. QuestProgressRepo.Set(playerID, status); var state = GetState(1); foreach (var objective in state.GetObjectives()) { objective.Initialize(player, QuestID); } // Add the journal entry to the player. AddJournalQuestEntry(JournalTag, 1, player, false); // Notify them that they've accepted a quest. SendMessageToPC(player, "Quest '" + Name + "' accepted. Refer to your journal for more information on this quest."); // Run any quest-specific code. foreach (var action in _onAcceptActions) { action.Invoke(player, questSource); } // Notify to subscribers that a quest has just been accepted. Publish.CustomEvent(player, QuestEventPrefix.OnQuestAccepted, new QuestAccepted(player, QuestID)); }
/// <summary> /// Advances the player to the next quest state. /// </summary> /// <param name="player">The player advancing to the next quest state</param> /// <param name="questSource">The source of quest advancement</param> internal void Advance(NWGameObject player, NWGameObject questSource) { if (!GetIsPlayer(player)) { return; } // Retrieve the player's current quest state. var playerID = GetGlobalID(player); var questStatus = QuestProgressRepo.Get(playerID, QuestID); // Can't find a state? Notify the player they haven't accepted the quest. if (questStatus.CurrentState <= 0) { SendMessageToPC(player, "You have not accepted this quest yet."); return; } // If this quest has already been completed, exit early. // This is used in case a module builder incorrectly configures a quest. // We don't want to risk giving duplicate rewards. if (questStatus.TimesCompleted > 0 && !IsRepeatable) { return; } var currentState = GetState(questStatus.CurrentState); var lastState = GetStates().Last(); // If this is the last state, the assumption is that it's time to complete the quest. if (currentState == lastState) { RequestRewardSelectionFromPC(player, questSource); } else { // Progress player's quest status to the next state. questStatus.CurrentState++; var nextState = GetState(questStatus.CurrentState); // Update the player's journal AddJournalQuestEntry(JournalTag, questStatus.CurrentState, player, false); // Notify the player they've progressed. SendMessageToPC(player, "Objective for quest '" + Name + "' complete! Check your journal for information on the next objective."); // Submit all of these changes to the cache/DB. QuestProgressRepo.Set(playerID, questStatus); // Create any extended data entries for the next state of the quest. foreach (var objective in nextState.GetObjectives()) { objective.Initialize(player, QuestID); } // Run any quest-specific code. foreach (var action in _onAdvanceActions) { action.Invoke(player, questSource, questStatus.CurrentState); } // Notify to subscribers that the player has advanced to the next state of the quest. Publish.CustomEvent(player, QuestEventPrefix.OnQuestAdvanced, new QuestAdvanced(player, QuestID, questStatus.CurrentState)); } }