diff --git a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs index e8704e6..c8543f7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/Cultivation/CultivationService.cs @@ -129,6 +129,7 @@ internal sealed partial class CultivationService : ICultivationService token.ThrowIfCancellationRequested(); Dictionary resultItems = []; Guid projectId = cultivateProject.InnerId; + Dictionary inventoryCounts = []; foreach (ref readonly CultivateEntry entry in cultivationRepository.GetCultivateEntryImmutableArrayByProjectId(projectId).AsSpan()) { @@ -153,6 +154,7 @@ internal sealed partial class CultivationService : ICultivationService foreach (ref readonly InventoryItem inventoryItem in inventoryRepository.GetInventoryItemImmutableArrayByProjectId(projectId).AsSpan()) { token.ThrowIfCancellationRequested(); + inventoryCounts[inventoryItem.ItemId] = inventoryItem.Count; ref StatisticsCultivateItem existedItem = ref CollectionsMarshal.GetValueRefOrNullRef(resultItems, inventoryItem.ItemId); if (!Unsafe.IsNullRef(in existedItem)) { @@ -160,6 +162,13 @@ internal sealed partial class CultivationService : ICultivationService } } + AddWeeklyBossGroupInventoryDonors( + resultItems, + inventoryCounts, + context, + cultivateProject.ServerTimeZoneOffset, + mergeOptions.WeeklyBossMaterialInterchange); + CultivationStatisticsSurplusMerge.Apply(resultItems, context, mergeOptions); CultivationStatisticsWeeklyBossInterchange.Apply( resultItems, @@ -171,6 +180,55 @@ internal sealed partial class CultivationService : ICultivationService } } + private static void AddWeeklyBossGroupInventoryDonors( + Dictionary items, + Dictionary inventoryCounts, + ICultivationMetadataContext context, + TimeSpan offset, + bool enabled) + { + if (!enabled || context.WeeklyBossMaterialInterchangeGroups.IsDefaultOrEmpty) + { + return; + } + + foreach (ImmutableArray group in context.WeeklyBossMaterialInterchangeGroups) + { + bool anyPlannedInGroup = false; + foreach (MaterialId mid in group) + { + if (items.ContainsKey(mid)) + { + anyPlannedInGroup = true; + break; + } + } + + if (!anyPlannedInGroup) + { + continue; + } + + foreach (MaterialId mid in group) + { + uint id = mid; + if (items.ContainsKey(id)) + { + continue; + } + + if (!inventoryCounts.TryGetValue(id, out uint inv) || inv is 0U) + { + continue; + } + + StatisticsCultivateItem donor = StatisticsCultivateItem.Create(context.GetMaterial(id), offset); + donor.Current = inv; + items[id] = donor; + } + } + } + public ValueTask GetResinStatisticsAsync(StatisticsCultivateItemCollection statisticsCultivateItems, CancellationToken token) { return cultivationResinStatisticsService.GetResinStatisticsAsync(statisticsCultivateItems, token);