/// <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> public void Complete(uint player, uint questSource, IQuestReward selectedReward) { if (!GetIsPC(player) || GetIsDM(player)) { return; } if (!CanComplete(player)) { return; } var playerId = GetObjectUUID(player); var dbPlayer = DB.Get <Player>(playerId); var quest = dbPlayer.Quests.ContainsKey(QuestId) ? dbPlayer.Quests[QuestId] : new PlayerQuest(); // Mark player as being on the last state of the quest. quest.CurrentState = GetStates().Count(); quest.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); } quest.ItemProgresses.Clear(); quest.KillProgresses.Clear(); quest.DateLastCompleted = DateTime.UtcNow; dbPlayer.Quests[QuestId] = quest; DB.Set(playerId, dbPlayer); foreach (var action in OnCompleteActions) { action.Invoke(player, questSource); } SendMessageToPC(player, "Quest '" + Name + "' complete!"); RemoveJournalQuestEntry(QuestId, player, false); Events.SignalEvent("FFO_COMPLETE_QUEST", player); }
/// <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)); }
public void Complete(NWPlayer player, NWObject questSource, IQuestReward selectedReward) { if (!player.IsPlayer) { return; } if (!CanComplete(player)) { return; } PCQuestStatus pcState = DataService.PCQuestStatus.GetByPlayerAndQuestID(player.GlobalID, QuestID); // Mark player as being on the last state of the quest. pcState.QuestState = GetStates().Count(); pcState.CompletionDate = DateTime.UtcNow; 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); } DataService.SubmitDataChange(pcState, DatabaseActionType.Update); _onComplete?.Invoke(player, questSource); player.SendMessage("Quest '" + Name + "' complete!"); RemoveJournalQuestEntry(JournalTag, player, false); MessageHub.Instance.Publish(new OnQuestCompleted(player, QuestID)); }