@@ -229,18 +229,7 @@ public List<HideoutProduction> GetRewardProductionMatch(Reward craftUnlockReward
229229 // "TraderId" holds area ID that will be used to craft unlocked item
230230 var desiredHideoutAreaType = ( HideoutAreas ) int . Parse ( craftUnlockReward . TraderId . ToString ( ) ) ;
231231
232- var matchingProductions = GetMatchingProductions ( desiredHideoutAreaType , questId , craftUnlockReward ) ;
233-
234- // More/less than single match, above filtering wasn't strict enough
235- if ( matchingProductions . Count != 1 )
236- // Multiple matches were found, last ditch attempt to match by questid (value we add manually to production.json via `gen:productionquests` command)
237- {
238- matchingProductions = matchingProductions
239- . Where ( prod => prod . Requirements . Any ( requirement => requirement . QuestId == questId ) )
240- . ToList ( ) ;
241- }
242-
243- return matchingProductions ;
232+ return GetMatchingProductions ( desiredHideoutAreaType , questId , craftUnlockReward ) ;
244233 }
245234
246235 /// <summary>
@@ -252,20 +241,35 @@ public List<HideoutProduction> GetRewardProductionMatch(Reward craftUnlockReward
252241 /// <returns>Hideout crafts that match input parameters</returns>
253242 protected List < HideoutProduction > GetMatchingProductions ( HideoutAreas desiredHideoutAreaType , MongoId questId , Reward craftUnlockReward )
254243 {
255- var rewardItemTpl = craftUnlockReward . Items . FirstOrDefault ( ) ? . Template ;
244+ var rewardItemTpl = craftUnlockReward . Items ? . FirstOrDefault ( ) ? . Template ;
245+ if ( rewardItemTpl is null )
246+ {
247+ logger . Warning ( "Unable to get matching hideout craft as reward item tpl is missing" ) ;
256248
257- var craftingRecipes = databaseService . GetHideout ( ) . Production . Recipes ;
258- return craftingRecipes
249+ return [ ] ;
250+ }
251+
252+ var craftingRecipesDb = databaseService . GetHideout ( ) . Production . Recipes ;
253+ var result = craftingRecipesDb
259254 . Where ( production =>
260- // Some crafts have the questId, easy match
255+ // Attempt to match by questId (value we add manually to production.json via `gen:productionquests` command)
261256 production . Requirements . Any ( req => req . QuestId == questId )
262- ||
263- // Couldn't get craft by questId, get the closest match based on information we know
257+ )
258+ . ToList ( ) ;
259+ if ( result . Count == 1 )
260+ {
261+ // One result, good match
262+ return result ;
263+ }
264+
265+ // Found more than or less than 1 craft by questId, try to get closest match based on information we know
266+ return craftingRecipesDb
267+ . Where ( production =>
264268 (
265- rewardItemTpl is not null
266- && production . AreaType == desiredHideoutAreaType
269+ production . AreaType == desiredHideoutAreaType
267270 && production . EndProduct == rewardItemTpl . Value
268271 && production . Requirements . Any ( req => req . Type is "QuestComplete" )
272+ && production . Locked . GetValueOrDefault ( false ) // Craft would be locked if we're unlocking it
269273 && production . Requirements . Any ( req => req . RequiredLevel == craftUnlockReward . LoyaltyLevel )
270274 )
271275 )
0 commit comments