From 74cc1ac300abc82833318d4974184ab6c562742e Mon Sep 17 00:00:00 2001 From: Cj <161484149+CJ-SPT@users.noreply.github.com> Date: Thu, 29 May 2025 14:56:14 -0400 Subject: [PATCH] Move repeatable quest code into repeatable controller --- .../Callbacks/QuestCallbacks.cs | 2 +- .../Controllers/QuestController.cs | 78 +------------------ .../Controllers/RepeatableQuestController.cs | 75 ++++++++++++++++++ 3 files changed, 77 insertions(+), 78 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Callbacks/QuestCallbacks.cs b/Libraries/SPTarkov.Server.Core/Callbacks/QuestCallbacks.cs index e4827db4..950f517b 100644 --- a/Libraries/SPTarkov.Server.Core/Callbacks/QuestCallbacks.cs +++ b/Libraries/SPTarkov.Server.Core/Callbacks/QuestCallbacks.cs @@ -37,7 +37,7 @@ public class QuestCallbacks( { if (info.Type == "repeatable") { - return _questController.AcceptRepeatableQuest(pmcData, info, sessionID); + return _repeatableQuestController.AcceptRepeatableQuest(pmcData, info, sessionID); } return _questController.AcceptQuest(pmcData, info, sessionID); diff --git a/Libraries/SPTarkov.Server.Core/Controllers/QuestController.cs b/Libraries/SPTarkov.Server.Core/Controllers/QuestController.cs index 170f9d4a..7713f2df 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/QuestController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/QuestController.cs @@ -39,7 +39,6 @@ public class QuestController( ICloner _cloner ) { - protected static readonly List _questTypes = ["PickUp", "Exploration", "Elimination"]; protected QuestConfig _questConfig = _configServer.GetConfig(); /// @@ -97,7 +96,7 @@ public class QuestController( pmcData, acceptedQuest.QuestId); } - + // Get messageId of text to send to player as text message in game var messageId = _questHelper.GetMessageIdForQuestStart( @@ -169,81 +168,6 @@ public class QuestController( } } - /// - /// TODO: Move this code into RepeatableQuestController - /// Handle the client accepting a repeatable quest and starting it - /// Send starting rewards if any to player and - /// Send start notification if any to player - /// - /// Players PMC profile - /// Repeatable quest accepted - /// Session/Player id - /// ItemEventRouterResponse - public ItemEventRouterResponse AcceptRepeatableQuest(PmcData pmcData, AcceptQuestRequestData acceptedQuest, string sessionID) - { - // Create and store quest status object inside player profile - var newRepeatableQuest = _questHelper.GetQuestReadyForProfile( - pmcData, - QuestStatusEnum.Started, - acceptedQuest - ); - pmcData.Quests.Add(newRepeatableQuest); - - // Look for the generated quest cache in profile.RepeatableQuests - var repeatableQuestProfile = GetRepeatableQuestFromProfile(pmcData, acceptedQuest.QuestId); - if (repeatableQuestProfile is null) - { - _logger.Error( - _localisationService.GetText( - "repeatable-accepted_repeatable_quest_not_found_in_active_quests", - acceptedQuest.QuestId - ) - ); - - throw new Exception(_localisationService.GetText("repeatable-unable_to_accept_quest_see_log")); - } - - // Some scav quests need to be added to scav profile for them to show up in-raid - if (repeatableQuestProfile.Side == "Scav" && _questTypes.Contains(repeatableQuestProfile.Type.ToString())) - { - var fullProfile = _profileHelper.GetFullProfile(sessionID); - - fullProfile.CharacterData.ScavData.Quests ??= []; - fullProfile.CharacterData.ScavData.Quests.Add(newRepeatableQuest); - } - - var response = _eventOutputHolder.GetOutput(sessionID); - - return response; - } - - /// - /// Look for an accepted quest inside player profile, return quest that matches - /// - /// Players PMC profile - /// Quest id to return - /// RepeatableQuest - protected RepeatableQuest GetRepeatableQuestFromProfile(PmcData pmcData, string questId) - { - foreach (var repeatableQuest in pmcData.RepeatableQuests) - { - var matchingQuest = repeatableQuest.ActiveQuests.FirstOrDefault(x => x.Id == questId); - if (matchingQuest is not null) - { - if (_logger.IsLogEnabled(LogLevel.Debug)) - { - _logger.Debug($"Accepted repeatable quest: {questId} from: {repeatableQuest.Name}"); - } - - matchingQuest.SptRepatableGroupName = repeatableQuest.Name; - - return matchingQuest; - } - } - - return null; - } - /// /// Handle QuestComplete event /// Update completed quest in profile diff --git a/Libraries/SPTarkov.Server.Core/Controllers/RepeatableQuestController.cs b/Libraries/SPTarkov.Server.Core/Controllers/RepeatableQuestController.cs index 9f52100a..a0ef4bb2 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/RepeatableQuestController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/RepeatableQuestController.cs @@ -41,8 +41,56 @@ public class RepeatableQuestController( ICloner _cloner ) { + protected static readonly List _questTypes = ["PickUp", "Exploration", "Elimination"]; protected QuestConfig _questConfig = _configServer.GetConfig(); + /// + /// Handle the client accepting a repeatable quest and starting it + /// Send starting rewards if any to player and + /// Send start notification if any to player + /// + /// Players PMC profile + /// Repeatable quest accepted + /// Session/Player id + /// ItemEventRouterResponse + public ItemEventRouterResponse AcceptRepeatableQuest(PmcData pmcData, AcceptQuestRequestData acceptedQuest, string sessionID) + { + // Create and store quest status object inside player profile + var newRepeatableQuest = _questHelper.GetQuestReadyForProfile( + pmcData, + QuestStatusEnum.Started, + acceptedQuest + ); + pmcData.Quests.Add(newRepeatableQuest); + + // Look for the generated quest cache in profile.RepeatableQuests + var repeatableQuestProfile = GetRepeatableQuestFromProfile(pmcData, acceptedQuest.QuestId); + if (repeatableQuestProfile is null) + { + _logger.Error( + _localisationService.GetText( + "repeatable-accepted_repeatable_quest_not_found_in_active_quests", + acceptedQuest.QuestId + ) + ); + + throw new Exception(_localisationService.GetText("repeatable-unable_to_accept_quest_see_log")); + } + + // Some scav quests need to be added to scav profile for them to show up in-raid + if (repeatableQuestProfile.Side == "Scav" && _questTypes.Contains(repeatableQuestProfile.Type.ToString())) + { + var fullProfile = _profileHelper.GetFullProfile(sessionID); + + fullProfile.CharacterData.ScavData.Quests ??= []; + fullProfile.CharacterData.ScavData.Quests.Add(newRepeatableQuest); + } + + var response = _eventOutputHolder.GetOutput(sessionID); + + return response; + } + /// /// Handle RepeatableQuestChange event /// @@ -180,6 +228,33 @@ public class RepeatableQuestController( return output; } + /// + /// Look for an accepted quest inside player profile, return quest that matches + /// + /// Players PMC profile + /// Quest id to return + /// RepeatableQuest + protected RepeatableQuest? GetRepeatableQuestFromProfile(PmcData pmcData, string questId) + { + foreach (var repeatableQuest in pmcData.RepeatableQuests) + { + var matchingQuest = repeatableQuest.ActiveQuests.FirstOrDefault(x => x.Id == questId); + if (matchingQuest is not null) + { + if (_logger.IsLogEnabled(LogLevel.Debug)) + { + _logger.Debug($"Accepted repeatable quest: {questId} from: {repeatableQuest.Name}"); + } + + matchingQuest.SptRepatableGroupName = repeatableQuest.Name; + + return matchingQuest; + } + } + + return null; + } + /// /// Some accounts have access to free repeatable quest refreshes /// Track the usage of them inside players profile