From 4b29aaf9d6bc1a8746980d9b44cea44260367691 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sun, 22 Jun 2025 12:47:34 +0100 Subject: [PATCH] Fixed hideout area upgrades softlocking client when upgrading areas with containers Removed unused injections Renamed field to `_areasWithResources` and converted into hashset --- .../Controllers/HideoutController.cs | 65 +++++-------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs b/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs index 8784ea09..d5e6bb1c 100644 --- a/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs +++ b/Libraries/SPTarkov.Server.Core/Controllers/HideoutController.cs @@ -25,11 +25,9 @@ public class HideoutController( HashUtil _hashUtil, TimeUtil _timeUtil, DatabaseService _databaseService, - RandomUtil _randomUtil, InventoryHelper _inventoryHelper, ItemHelper _itemHelper, SaveServer _saveServer, - PlayerService _playerService, PresetHelper _presetHelper, PaymentHelper _paymentHelper, EventOutputHolder _eventOutputHolder, @@ -47,7 +45,7 @@ public class HideoutController( { public const string NameTaskConditionCountersCraftingId = "673f5d6fdd6ed700c703afdc"; - protected List _hideoutAreas = + protected readonly HashSet _areasWithResources = [ HideoutAreas.AirFilteringUnit, HideoutAreas.WaterCollector, @@ -55,7 +53,7 @@ public class HideoutController( HideoutAreas.BitcoinFarm, ]; - protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); + protected readonly HideoutConfig _hideoutConfig = _configServer.GetConfig(); /// /// Handle HideoutUpgrade event @@ -155,7 +153,7 @@ public class HideoutController( var timestamp = _timeUtil.GetTimeStamp(); - profileHideoutArea.CompleteTime = (int)Math.Round(timestamp + ctime.Value); + profileHideoutArea.CompleteTime = (int) Math.Round(timestamp + ctime.Value); profileHideoutArea.Constructing = true; } } @@ -303,7 +301,7 @@ public class HideoutController( { // Add key/value to `hideoutAreaStashes` dictionary - used to link hideout area to inventory stash by its id // Key is the enums value stored as a string, e.g. "27" for cultist circle - var keyForHideoutAreaStash = ((int)dbHideoutArea.Type).ToString(); + var keyForHideoutAreaStash = ((int) dbHideoutArea.Type).ToString(); if (!pmcData.Inventory.HideoutAreaStashes.ContainsKey(keyForHideoutAreaStash)) { if ( @@ -333,24 +331,13 @@ public class HideoutController( ); } - // Don't inform client when upgraded area is hall of fame or equipment stand, BSG doesn't inform client this specific upgrade has occurred - // will break client if sent - - if ( - ShouldAddContainerUpgradeToClientResponse( - dbHideoutArea, - profileParentHideoutArea.Level.GetValueOrDefault(1) - ) - ) - { - AddContainerUpgradeToClientOutput( - sessionId, - keyForHideoutAreaStash, - dbHideoutArea, - hideoutStage, - output - ); - } + AddContainerUpgradeToClientOutput( + sessionId, + keyForHideoutAreaStash, + dbHideoutArea, + hideoutStage, + output + ); // Some hideout areas (Gun stand) have child areas linked to it var childDbArea = _databaseService @@ -363,7 +350,7 @@ public class HideoutController( } // Add key/value to `hideoutAreaStashes` dictionary - used to link hideout area to inventory stash by its id - var childAreaTypeKey = ((int)childDbArea.Type).ToString(); + var childAreaTypeKey = ((int) childDbArea.Type).ToString(); if (pmcData.Inventory.HideoutAreaStashes.GetValueOrDefault(childAreaTypeKey) is null) { pmcData.Inventory.HideoutAreaStashes[childAreaTypeKey] = childDbArea.Id; @@ -403,22 +390,6 @@ public class HideoutController( ); } - /// - /// Should the newly completed hideout area container upgrade/addition be included in client response - /// Deny when: area is place of fame + we're upgrading to level 1 - /// - /// Hideout area upgraded - /// Level of area upgraded to - /// True = it should be included - private bool ShouldAddContainerUpgradeToClientResponse(HideoutArea dbHideoutArea, int areaLevel) - { - HashSet areaBlacklist = [HideoutAreas.PlaceOfFame]; - var isOnAreaBlacklist = areaBlacklist.Contains(dbHideoutArea.Type ?? HideoutAreas.NotSet); - var isFirstStage = areaLevel == 1; - - return isOnAreaBlacklist && !isFirstStage; - } - /// /// Add an inventory item to profile from a hideout area stage data /// @@ -605,7 +576,7 @@ public class HideoutController( } // Handle areas that have resources that can be placed in/taken out of slots from the area - if (_hideoutAreas.Contains(hideoutArea.Type ?? HideoutAreas.NotSet)) + if (_areasWithResources.Contains(hideoutArea.Type ?? HideoutAreas.NotSet)) { var response = RemoveResourceFromArea(sessionID, pmcData, request, output, hideoutArea); @@ -778,7 +749,7 @@ public class HideoutController( // Tools don't have a count if (requirement.Type != "Tool") { - requirement.Count -= (int)itemToDelete.Count; + requirement.Count -= (int) itemToDelete.Count; } } @@ -863,7 +834,7 @@ public class HideoutController( pmcData.Hideout.Production[request.RecipeId] = _hideoutHelper.InitProduction( request.RecipeId, - (int)(_profileHelper.IsDeveloperAccount(sessionID) ? 40 : modifiedScavCaseTime), + (int) (_profileHelper.IsDeveloperAccount(sessionID) ? 40 : modifiedScavCaseTime), false ); pmcData.Hideout.Production[request.RecipeId].SptIsScavCase = true; @@ -1091,7 +1062,7 @@ public class HideoutController( var multiplierCrafting = Math.Floor( hoursCrafting.Value / _hideoutConfig.HoursForSkillCrafting ); - craftingExpAmount += (int)(1 * multiplierCrafting); + craftingExpAmount += (int) (1 * multiplierCrafting); hoursCrafting -= _hideoutConfig.HoursForSkillCrafting * multiplierCrafting; } @@ -1160,7 +1131,7 @@ public class HideoutController( { _profileHelper.AddSkillPointsToPlayer(pmcData, SkillTypes.Crafting, craftingExpAmount); - var intellectAmountToGive = 0.5 * Math.Round((double)(craftingExpAmount / 15)); + var intellectAmountToGive = 0.5 * Math.Round((double) (craftingExpAmount / 15)); if (intellectAmountToGive > 0) { _profileHelper.AddSkillPointsToPlayer( @@ -1587,7 +1558,7 @@ public class HideoutController( var improvementDetails = new HideoutImprovement { Completed = false, - ImproveCompleteTimestamp = (long)(timestamp + improvement.ImprovementTime), + ImproveCompleteTimestamp = (long) (timestamp + improvement.ImprovementTime), }; output.ProfileChanges[sessionId].Improvements[improvement.Id] = improvementDetails;