From 3b1f8c81efbfb8a982d11b1fc24e5db5562fa237 Mon Sep 17 00:00:00 2001 From: Chomp Date: Fri, 14 Feb 2025 17:33:29 +0000 Subject: [PATCH] Updated loot generator to block seasonal items when out of season --- Libraries/Core/Generators/LootGenerator.cs | 24 ++++++++++++------- .../Core/Models/Spt/Config/AirdropConfig.cs | 14 +++++++++++ .../Core/Models/Spt/Services/LootRequest.cs | 7 ++++++ Libraries/Core/Services/AirdropService.cs | 4 +++- .../SptAssets/Assets/configs/airdrop.json | 18 ++++++++++---- .../SptAssets/Assets/configs/trader.json | 3 ++- 6 files changed, 56 insertions(+), 14 deletions(-) diff --git a/Libraries/Core/Generators/LootGenerator.cs b/Libraries/Core/Generators/LootGenerator.cs index 6f774503..8d53fa79 100644 --- a/Libraries/Core/Generators/LootGenerator.cs +++ b/Libraries/Core/Generators/LootGenerator.cs @@ -27,6 +27,7 @@ public class LootGenerator( LocalisationService _localisationService, WeightedRandomHelper _weightedRandomHelper, RagfairLinkedItemService _ragfairLinkedItemService, + SeasonalEventService _seasonalEventService, ICloner _cloner ) { @@ -78,7 +79,8 @@ public class LootGenerator( options.ItemBlacklist, options.ItemTypeWhitelist, options.UseRewardItemBlacklist.GetValueOrDefault(false), - options.AllowBossItems.GetValueOrDefault(false) + options.AllowBossItems.GetValueOrDefault(false), + options.BlockSeasonalItemsOutOfSeason.GetValueOrDefault(false) ); // Pool has items we could add as loot, proceed @@ -214,10 +216,14 @@ public class LootGenerator( /// Only allow these items /// Should item.json reward item config be used /// Should boss items be allowed in result + /// Prevent seasonal items appearing outside their defined season /// results of filtering + blacklist used - protected ItemRewardPoolResults GetItemRewardPool(List itemTplBlacklist, List itemTypeWhitelist, + protected ItemRewardPoolResults GetItemRewardPool( + List itemTplBlacklist, + List itemTypeWhitelist, bool useRewardItemBlacklist, - bool allowBossItems) + bool allowBossItems, + bool blockSeasonalItemsOutOfSeason) { var itemsDb = _databaseService.GetItems().Values; var itemBlacklist = new HashSet(); @@ -243,10 +249,12 @@ public class LootGenerator( if (!allowBossItems) { - foreach (var bossItem in _itemFilterService.GetBossItems()) - { - itemBlacklist.Add(bossItem); - } + itemBlacklist.UnionWith(_itemFilterService.GetBossItems()); + } + + if (blockSeasonalItemsOutOfSeason) + { + itemBlacklist.UnionWith(_seasonalEventService.GetInactiveSeasonalEventItems()); } var items = itemsDb.Where( @@ -748,7 +756,7 @@ public class LootGenerator( } return _randomUtil.GetArrayValue( - GetItemRewardPool([], rewardContainerDetails.RewardTypePool, true, true) + GetItemRewardPool([], rewardContainerDetails.RewardTypePool, true, true, false) .ItemPool.Select( item => item.Id ) diff --git a/Libraries/Core/Models/Spt/Config/AirdropConfig.cs b/Libraries/Core/Models/Spt/Config/AirdropConfig.cs index 348f45fc..a61cff40 100644 --- a/Libraries/Core/Models/Spt/Config/AirdropConfig.cs +++ b/Libraries/Core/Models/Spt/Config/AirdropConfig.cs @@ -226,4 +226,18 @@ public record AirdropLoot get; set; } + + [JsonPropertyName("useRewardItemBlacklist")] + public bool? UseRewardItemBlacklist + { + get; + set; + } + + [JsonPropertyName("blockSeasonalItemsOutOfSeason")] + public bool? BlockSeasonalItemsOutOfSeason + { + get; + set; + } } diff --git a/Libraries/Core/Models/Spt/Services/LootRequest.cs b/Libraries/Core/Models/Spt/Services/LootRequest.cs index 5b1ddf04..9550b0e7 100644 --- a/Libraries/Core/Models/Spt/Services/LootRequest.cs +++ b/Libraries/Core/Models/Spt/Services/LootRequest.cs @@ -132,6 +132,13 @@ public record LootRequest get; set; } + + [JsonPropertyName("blockSeasonalItemsOutOfSeason")] + public bool? BlockSeasonalItemsOutOfSeason + { + get; + set; + } } public record AirdropLootRequest : LootRequest diff --git a/Libraries/Core/Services/AirdropService.cs b/Libraries/Core/Services/AirdropService.cs index 483226c9..d9c76e8a 100644 --- a/Libraries/Core/Services/AirdropService.cs +++ b/Libraries/Core/Services/AirdropService.cs @@ -192,7 +192,9 @@ public class AirdropService( ArmorLevelWhitelist = lootSettingsByType.ArmorLevelWhitelist, AllowBossItems = lootSettingsByType.AllowBossItems, UseForcedLoot = lootSettingsByType.UseForcedLoot, - ForcedLoot = lootSettingsByType.ForcedLoot + ForcedLoot = lootSettingsByType.ForcedLoot, + UseRewardItemBlacklist = lootSettingsByType.UseRewardItemBlacklist, + BlockSeasonalItemsOutOfSeason = lootSettingsByType.BlockSeasonalItemsOutOfSeason }; } } diff --git a/Libraries/SptAssets/Assets/configs/airdrop.json b/Libraries/SptAssets/Assets/configs/airdrop.json index 2f20859a..3b8d56ab 100644 --- a/Libraries/SptAssets/Assets/configs/airdrop.json +++ b/Libraries/SptAssets/Assets/configs/airdrop.json @@ -107,7 +107,9 @@ } }, "armorLevelWhitelist": [0, 4, 5, 6], - "allowBossItems": false + "allowBossItems": false, + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true }, "weaponArmor": { "icon": "Weapon", @@ -180,7 +182,9 @@ } }, "armorLevelWhitelist": [0, 3, 4, 5, 6], - "allowBossItems": false + "allowBossItems": false, + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true }, "foodMedical": { "icon": "Medical", @@ -261,7 +265,9 @@ } }, "armorLevelWhitelist": [0], - "allowBossItems": false + "allowBossItems": false, + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true }, "barter": { "icon": "Supply", @@ -343,7 +349,9 @@ } }, "armorLevelWhitelist": [0], - "allowBossItems": false + "allowBossItems": false, + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true }, "radar": { "icon": "Supply", @@ -369,6 +377,8 @@ "itemStackLimits": {}, "armorLevelWhitelist": [], "allowBossItems": false, + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true, "useForcedLoot": true, "forcedLoot": { "66d9f7256916142b3b02276e": { "min": 2, "max": 4 } diff --git a/Libraries/SptAssets/Assets/configs/trader.json b/Libraries/SptAssets/Assets/configs/trader.json index 90958b73..1161233f 100644 --- a/Libraries/SptAssets/Assets/configs/trader.json +++ b/Libraries/SptAssets/Assets/configs/trader.json @@ -437,7 +437,8 @@ } }, "allowBossItems": false, - "useRewardItemBlacklist": true + "useRewardItemBlacklist": true, + "blockSeasonalItemsOutOfSeason": true }, "btrDeliveryExpireHours": 240, "playerRepMin": -7,