Skip to content

Commit

Permalink
Updated LootGenerator to blacklist seasonal items outside of their …
Browse files Browse the repository at this point in the history
…active season
  • Loading branch information
Chomp committed Feb 14, 2025
1 parent a89d097 commit d148ca9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
18 changes: 14 additions & 4 deletions project/assets/configs/airdrop.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
}
},
"armorLevelWhitelist": [0, 4, 5, 6],
"allowBossItems": false
"allowBossItems": false,
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true
},
"weaponArmor": {
"icon": "Weapon",
Expand Down Expand Up @@ -180,7 +182,9 @@
}
},
"armorLevelWhitelist": [0, 3, 4, 5, 6],
"allowBossItems": false
"allowBossItems": false,
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true
},
"foodMedical": {
"icon": "Medical",
Expand Down Expand Up @@ -261,7 +265,9 @@
}
},
"armorLevelWhitelist": [0],
"allowBossItems": false
"allowBossItems": false,
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true
},
"barter": {
"icon": "Supply",
Expand Down Expand Up @@ -343,7 +349,9 @@
}
},
"armorLevelWhitelist": [0],
"allowBossItems": false
"allowBossItems": false,
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true
},
"radar": {
"icon": "Supply",
Expand All @@ -369,6 +377,8 @@
"itemStackLimits": {},
"armorLevelWhitelist": [],
"allowBossItems": false,
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true,
"useForcedLoot": true,
"forcedLoot": {
"66d9f7256916142b3b02276e": { "min": 2, "max": 4 }
Expand Down
3 changes: 2 additions & 1 deletion project/assets/configs/trader.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
}
},
"allowBossItems": false,
"useRewardItemBlacklist": true
"useRewardItemBlacklist": true,
"blockSeasonalItemsOutOfSeason": true
},
"btrDeliveryExpireHours": 240,
"playerRepMin": -7,
Expand Down
13 changes: 12 additions & 1 deletion project/src/generators/LootGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DatabaseService } from "@spt/services/DatabaseService";
import { ItemFilterService } from "@spt/services/ItemFilterService";
import { LocalisationService } from "@spt/services/LocalisationService";
import { RagfairLinkedItemService } from "@spt/services/RagfairLinkedItemService";
import { SeasonalEventService } from "@spt/services/SeasonalEventService";
import { HashUtil } from "@spt/utils/HashUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { inject, injectable } from "tsyringe";
Expand All @@ -32,6 +33,7 @@ export class LootGenerator {
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
@inject("WeightedRandomHelper") protected weightedRandomHelper: WeightedRandomHelper,
@inject("LocalisationService") protected localisationService: LocalisationService,
@inject("SeasonalEventService") protected seasonalEventService: SeasonalEventService,
@inject("RagfairLinkedItemService") protected ragfairLinkedItemService: RagfairLinkedItemService,
@inject("ItemFilterService") protected itemFilterService: ItemFilterService,
) {}
Expand Down Expand Up @@ -77,6 +79,7 @@ export class LootGenerator {
options.itemTypeWhitelist,
options.useRewardItemBlacklist,
options.allowBossItems,
options.blockSeasonalItemsOutOfSeason,
);

// Pool has items we could add as loot, proceed
Expand Down Expand Up @@ -192,13 +195,15 @@ export class LootGenerator {
* @param itemTypeWhitelist Only allow these items
* @param useRewardItemBlacklist Should item.json reward item config be used
* @param allowBossItems Should boss items be allowed in result
* @param blockSeasonalItemsOutOfSeason Prevent seasonal items appearing outside their defined season
* @returns results of filtering + blacklist used
*/
protected getItemRewardPool(
itemTplBlacklist: string[],
itemTypeWhitelist: string[],
useRewardItemBlacklist: boolean,
allowBossItems: boolean,
blockSeasonalItemsOutOfSeason: boolean,
): { itemPool: [string, ITemplateItem][]; blacklist: Set<string> } {
const itemsDb = this.databaseService.getItems();
let itemBlacklist = new Set<string>([...this.itemFilterService.getBlacklistedItems(), ...itemTplBlacklist]);
Expand All @@ -221,6 +226,12 @@ export class LootGenerator {
}
}

if (blockSeasonalItemsOutOfSeason) {
for (const seasonalItem of this.seasonalEventService.getInactiveSeasonalEventItems()) {
itemBlacklist.add(seasonalItem);
}
}

const items = Object.entries(itemsDb).filter(
(item) =>
!itemBlacklist.has(item[1]._id) &&
Expand Down Expand Up @@ -628,7 +639,7 @@ export class LootGenerator {
}

return this.randomUtil.getArrayValue(
this.getItemRewardPool([], rewardContainerDetails.rewardTypePool, true, true).itemPool.map(
this.getItemRewardPool([], rewardContainerDetails.rewardTypePool, true, true, false).itemPool.map(
(item) => item[1]._id,
),
);
Expand Down
2 changes: 2 additions & 0 deletions project/src/models/spt/config/IAirdropConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ export interface IAirdropLoot {
allowBossItems: boolean;
useForcedLoot?: boolean;
forcedLoot?: Record<string, MinMax>;
useRewardItemBlacklist?: boolean;
blockSeasonalItemsOutOfSeason?: boolean;
}
2 changes: 2 additions & 0 deletions project/src/models/spt/services/ILootRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface ILootRequest {
useForcedLoot?: boolean;
/** Item tpls + count of items to force include */
forcedLoot?: Record<string, MinMax>;
/** Should seasonal items appear when its not the season for them */
blockSeasonalItemsOutOfSeason: boolean;
}

export interface IAirdropLootRequest extends ILootRequest {
Expand Down
2 changes: 2 additions & 0 deletions project/src/services/AirdropService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ export class AirdropService {
allowBossItems: lootSettingsByType.allowBossItems,
useForcedLoot: lootSettingsByType.useForcedLoot,
forcedLoot: lootSettingsByType.forcedLoot,
useRewardItemBlacklist: lootSettingsByType.useRewardItemBlacklist,
blockSeasonalItemsOutOfSeason: lootSettingsByType.blockSeasonalItemsOutOfSeason,
};
}
}

0 comments on commit d148ca9

Please sign in to comment.