From 5a0e16634e12943586639a85e14af61b20e93051 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 14 Oct 2023 16:52:48 +0100 Subject: [PATCH] Fixed seasonal event items not appearing on flea during event Don't rely on globals event value for event check, store event bools on SeasonaleventService class construction Remove dupe function `getSeasonalEventItemsToBlock(), rely on `getAllSeasonalEventItems()` --- project/src/controllers/GameController.ts | 2 +- .../generators/FenceBaseAssortGenerator.ts | 2 +- project/src/generators/LocationGenerator.ts | 6 +- project/src/generators/PMCLootGenerator.ts | 6 +- .../src/generators/RagfairAssortGenerator.ts | 2 +- project/src/services/SeasonalEventService.ts | 60 +++++++++---------- 6 files changed, 38 insertions(+), 40 deletions(-) diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index ae55894f..ebaaf869 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -211,7 +211,7 @@ export class GameController if (this.seasonalEventService.isAutomaticEventDetectionEnabled()) { - this.seasonalEventService.checkForAndEnableSeasonalEvents(sessionID); + this.seasonalEventService.enableSeasonalEvents(sessionID); } if (pmcProfile?.Skills?.Common) diff --git a/project/src/generators/FenceBaseAssortGenerator.ts b/project/src/generators/FenceBaseAssortGenerator.ts index 15eea71f..dc3aca38 100644 --- a/project/src/generators/FenceBaseAssortGenerator.ts +++ b/project/src/generators/FenceBaseAssortGenerator.ts @@ -38,7 +38,7 @@ export class FenceBaseAssortGenerator */ public generateFenceBaseAssorts(): void { - const blockedSeasonalItems = this.seasonalEventService.getSeasonalEventItemsToBlock(); + const blockedSeasonalItems = this.seasonalEventService.getAllSeasonalEventItems(); const baseFenceAssort = this.databaseServer.getTables().traders[Traders.FENCE].assort; diff --git a/project/src/generators/LocationGenerator.ts b/project/src/generators/LocationGenerator.ts index 1c3ebd89..67687f9e 100644 --- a/project/src/generators/LocationGenerator.ts +++ b/project/src/generators/LocationGenerator.ts @@ -436,7 +436,7 @@ export class LocationGenerator protected getPossibleLootItemsForContainer(containerTypeId: string, staticLootDist: Record): ProbabilityObjectArray { const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); - const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock(); + const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems(); const itemDistribution = new ProbabilityObjectArray(this.mathUtil, this.jsonUtil); for (const icd of staticLootDist[containerTypeId].itemDistribution) @@ -535,7 +535,7 @@ export class LocationGenerator // Iterate over spawnpoints const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); - const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock(); + const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems(); for (const spawnPoint of chosenSpawnpoints) { const itemArray = new ProbabilityObjectArray(this.mathUtil, this.jsonUtil); @@ -611,7 +611,7 @@ export class LocationGenerator } const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); - const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock(); + const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems(); // Add remaining forced loot to array for (const forcedLootItem of forcedSpawnPoints) { diff --git a/project/src/generators/PMCLootGenerator.ts b/project/src/generators/PMCLootGenerator.ts index 5666acee..e02e89ec 100644 --- a/project/src/generators/PMCLootGenerator.ts +++ b/project/src/generators/PMCLootGenerator.ts @@ -53,7 +53,7 @@ export class PMCLootGenerator if (!this.seasonalEventService.seasonalEventEnabled()) { // Blacklist seasonal items - itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock()); + itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems()); } const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent) @@ -89,7 +89,7 @@ export class PMCLootGenerator if (!this.seasonalEventService.seasonalEventEnabled()) { // Blacklist seasonal items - itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock()); + itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems()); } const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent) @@ -134,7 +134,7 @@ export class PMCLootGenerator if (!this.seasonalEventService.seasonalEventEnabled()) { // Blacklist seasonal items - itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock()); + itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems()); } const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent) diff --git a/project/src/generators/RagfairAssortGenerator.ts b/project/src/generators/RagfairAssortGenerator.ts index 8353c3da..873babb7 100644 --- a/project/src/generators/RagfairAssortGenerator.ts +++ b/project/src/generators/RagfairAssortGenerator.ts @@ -76,7 +76,7 @@ export class RagfairAssortGenerator ]; const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled(); - const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock(); + const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems(); for (const item of items) { if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes)) diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index 9f6f9b6b..57d44350 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -24,6 +24,9 @@ export class SeasonalEventService protected questConfig: IQuestConfig; protected httpConfig: IHttpConfig; + protected halloweenEventActive = undefined; + protected christmasEventActive = undefined; + constructor( @inject("WinstonLogger") protected logger: ILogger, @inject("DatabaseServer") protected databaseServer: DatabaseServer, @@ -38,6 +41,8 @@ export class SeasonalEventService this.seasonalEventConfig = this.configServer.getConfig(ConfigTypes.SEASONAL_EVENT); this.questConfig = this.configServer.getConfig(ConfigTypes.QUEST); this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP); + + this.cacheActiveEvents(); } protected get christmasEventItems(): string[] @@ -107,28 +112,6 @@ export class SeasonalEventService public getAllSeasonalEventItems(): string[] { const items = []; - - if (!this.christmasEventEnabled()) - { - items.push(...this.christmasEventItems); - } - - if (!this.halloweenEventEnabled()) - { - items.push(...this.halloweenEventItems); - } - - return items; - } - - /** - * Get an array of seasonal items that should be blocked as season is not currently active - * @returns Array of tpl strings - */ - public getSeasonalEventItemsToBlock(): string[] - { - const items = []; - if (!this.christmasEventEnabled()) { items.push(...this.christmasEventItems); @@ -148,26 +131,25 @@ export class SeasonalEventService */ public seasonalEventEnabled(): boolean { - return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.CHRISTMAS) || - this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.HALLOWEEN); + return this.christmasEventEnabled() || this.halloweenEventEnabled(); } /** - * Is christmas event active (Globals eventtype array contains even name) + * Is christmas event active * @returns true if active */ public christmasEventEnabled(): boolean { - return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.CHRISTMAS); + return this.christmasEventActive; } /** - * is halloween event active (Globals eventtype array contains even name) + * is halloween event active * @returns true if active */ public halloweenEventEnabled(): boolean { - return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.HALLOWEEN); + return this.halloweenEventActive; } /** @@ -216,12 +198,25 @@ export class SeasonalEventService } /** - * Check if current date falls inside any of the seasons events pased in, if so, handle them + * Handle seasonal events * @param sessionId Players id */ - public checkForAndEnableSeasonalEvents(sessionId: string): void + public enableSeasonalEvents(sessionId: string): void { const globalConfig = this.databaseServer.getTables().globals.config; + if (this.christmasEventActive) + { + this.updateGlobalEvents(sessionId, globalConfig, SeasonalEventType.CHRISTMAS); + } + + if (this.halloweenEventActive) + { + this.updateGlobalEvents(sessionId, globalConfig, SeasonalEventType.HALLOWEEN); + } + } + + protected cacheActiveEvents(): void + { const currentDate = new Date(); const seasonalEvents = this.getEventDetails(); @@ -234,7 +229,8 @@ export class SeasonalEventService if (currentDate >= eventStartDate && currentDate <= eventEndDate) { - this.updateGlobalEvents(sessionId, globalConfig, event.type); + this.christmasEventActive = (SeasonalEventType[event.type] === SeasonalEventType.CHRISTMAS); + this.halloweenEventActive = (SeasonalEventType[event.type] === SeasonalEventType.HALLOWEEN); } } } @@ -395,6 +391,8 @@ export class SeasonalEventService assaultBackpack.push("634959225289190e5e773b3b"); assaultBackpack.push("634959225289190e5e773b3b"); assaultBackpack.push("634959225289190e5e773b3b"); + assaultBackpack.push("634959225289190e5e773b3b"); + assaultBackpack.push("634959225289190e5e773b3b"); } /**