Filter down hideout areas prior to processing them in UpdateAreasWithResources

Updated hideout area "type" property to not be nullable
This commit is contained in:
Chomp
2025-08-13 17:15:52 +01:00
parent b061200803
commit c3a4bb448c
3 changed files with 16 additions and 4 deletions
@@ -467,7 +467,7 @@ public class HideoutController(
}
// Handle areas that have resources that can be placed in/taken out of slots from the area
if (_areasWithResources.Contains(hideoutArea.Type ?? HideoutAreas.NotSet))
if (_areasWithResources.Contains(hideoutArea.Type))
{
var response = RemoveResourceFromArea(sessionID, pmcData, request, output, hideoutArea);
@@ -606,7 +606,8 @@ public class HideoutHelper(
throw new HideoutHelperException(message);
}
foreach (var area in pmcData.Hideout.Areas ?? [])
var areas = GetAreasWithResourceUse(pmcData.Hideout.Areas ?? []);
foreach (var area in areas)
{
switch (area.Type)
{
@@ -628,13 +629,24 @@ public class HideoutHelper(
default:
if (logger.IsLogEnabled(LogLevel.Debug))
{
logger.Debug($"Unhandled area type {area.Type} when trying to update areas with resources");
logger.Debug($"Unhandled area type: {area.Type} when trying to update areas with resources");
}
break;
}
}
}
/// <summary>
/// Get Hideout areas that consume resources
/// </summary>
/// <param name="hideoutAreas">Areas to filter</param>
/// <returns>Collection of hideout areas</returns>
protected IEnumerable<BotHideoutArea> GetAreasWithResourceUse(List<BotHideoutArea> hideoutAreas)
{
HashSet<HideoutAreas> resourceUseAreas = [HideoutAreas.Generator, HideoutAreas.WaterCollector, HideoutAreas.AirFilteringUnit];
return hideoutAreas.Where(area => resourceUseAreas.Contains(area.Type));
}
/// <summary>
/// Decrease fuel from generator slots based on amount of time since last time this occurred
/// </summary>
@@ -926,7 +926,7 @@ public record BotHideoutArea
public Dictionary<string, object>? ExtensionData { get; set; }
[JsonPropertyName("type")]
public HideoutAreas? Type { get; set; }
public HideoutAreas Type { get; set; }
[JsonPropertyName("level")]
public int? Level { get; set; }