From 91fc7f842def025b1086323052311fc88cccf0a7 Mon Sep 17 00:00:00 2001 From: Chomp Date: Thu, 23 Jan 2025 15:58:18 +0000 Subject: [PATCH] Fixed `GetQuestFromDb` failing when accepting a repeatable quest --- Libraries/Core/Helpers/QuestHelper.cs | 18 +++++++----------- SptCommon/Extensions/ObjectExtensions.cs | 13 ++++++------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/Libraries/Core/Helpers/QuestHelper.cs b/Libraries/Core/Helpers/QuestHelper.cs index e1b8689e..eda5a469 100644 --- a/Libraries/Core/Helpers/QuestHelper.cs +++ b/Libraries/Core/Helpers/QuestHelper.cs @@ -659,20 +659,16 @@ public class QuestHelper( */ public Quest GetQuestFromDb(string questId, PmcData pmcData) { - // May be a repeatable quest - var quest = _databaseService.GetQuests()[questId]; - if (quest == null) + // Maybe a repeatable quest? + if (_databaseService.GetQuests().TryGetValue(questId, out var quest)) { - // Check daily/weekly objects - foreach (var repeatableQuest in pmcData.RepeatableQuests) - { - quest = repeatableQuest.ActiveQuests.FirstOrDefault(r => r.Id == questId); - if (quest != null) - break; - } + return quest; } - return quest; + // Check daily/weekly objects + return pmcData.RepeatableQuests + .SelectMany(x => x.ActiveQuests) + .FirstOrDefault(x => x.Id == questId); } /// diff --git a/SptCommon/Extensions/ObjectExtensions.cs b/SptCommon/Extensions/ObjectExtensions.cs index 60fff118..a481be01 100644 --- a/SptCommon/Extensions/ObjectExtensions.cs +++ b/SptCommon/Extensions/ObjectExtensions.cs @@ -50,30 +50,29 @@ namespace SptCommon.Extensions return (T?)cachedProperty.GetValue(obj); } - public static List GetAllPropValuesAsList(this object? obj) + public static List GetAllPropValuesAsList(this object? obj) { ArgumentNullException.ThrowIfNull(obj); var list = obj.GetType().GetProperties(); - var result = new List(); + var result = new List(); foreach (var prop in list) { - result.Add((T?)prop.GetValue(obj)); + result.Add(prop.GetValue(obj)); } return result; } - public static Dictionary GetAllPropsAsDict(this object? obj) + public static Dictionary GetAllPropsAsDict(this object? obj) { - var result = new Dictionary(); - + var result = new Dictionary(); var props = obj.GetType().GetProperties(); foreach (var prop in props) { - result.Add(prop.Name, (T?)prop.GetValue(obj)); + result.Add(prop.Name, prop.GetValue(obj)); } return result;