From 952544f5d3227c0afa263466ec54d10d8a1e7d64 Mon Sep 17 00:00:00 2001 From: Chomp Date: Tue, 24 Dec 2024 19:09:51 +0000 Subject: [PATCH] Revert "Improved ability for modders to adjust active seasonal events - Active events can be set via pre-db load event" This reverts commit 4cd868aeb302515b879ed204397b567c73d2fcd2. --- project/src/services/SeasonalEventService.ts | 57 +++++++------------- 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index a7c6014f..c3bee4f7 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -33,7 +33,7 @@ export class SeasonalEventService { protected christmasEventActive?: boolean = undefined; /** All events active at this point in time */ - protected currentlyActiveEvents: ISeasonalEvent[] = null; + protected currentlyActiveEvents: ISeasonalEvent[] = []; constructor( @inject("PrimaryLogger") protected logger: ILogger, @@ -50,6 +50,8 @@ export class SeasonalEventService { this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP); this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER); this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION); + + this.cacheActiveEvents(); } protected get christmasEventItems(): string[] { @@ -83,30 +85,6 @@ export class SeasonalEventService { ]; } - protected getActiveEvents(): ISeasonalEvent[] { - if (this.currentlyActiveEvents === null) { - this.cacheActiveEvents(); - } - - return this.currentlyActiveEvents; - } - - /** - * Sets the currently active events - * @param activeEvents Array of active events - * @param halloweenEventActive Halloween event - * @param christmasEventActive Christmas event - */ - public setActiveEvents( - activeEvents: ISeasonalEvent[], - halloweenEventActive: boolean, - christmasEventActive: boolean, - ) { - this.currentlyActiveEvents = activeEvents; - this.halloweenEventActive = halloweenEventActive; - this.christmasEventActive = christmasEventActive; - } - /** * Get an array of christmas items found in bots inventories as loot * @returns array @@ -236,9 +214,11 @@ export class SeasonalEventService { * Handle activating seasonal events */ public enableSeasonalEvents(): void { - const globalConfig = this.databaseService.getGlobals().config; - for (const event of this.getActiveEvents()) { - this.updateGlobalEvents(globalConfig, event); + if (this.currentlyActiveEvents) { + const globalConfig = this.databaseService.getGlobals().config; + for (const event of this.currentlyActiveEvents) { + this.updateGlobalEvents(globalConfig, event); + } } } @@ -256,11 +236,10 @@ export class SeasonalEventService { /** * Store active events inside class array property `currentlyActiveEvents` + set class properties: christmasEventActive/halloweenEventActive */ - protected cacheActiveEvents(): void { + public cacheActiveEvents(): void { const currentDate = new Date(); const seasonalEvents = this.getEventDetails(); - this.currentlyActiveEvents = []; for (const event of seasonalEvents) { const eventStartDate = new Date(currentDate.getFullYear(), event.startMonth - 1, event.startDay); const eventEndDate = new Date(currentDate.getFullYear(), event.endMonth - 1, event.endDay); @@ -476,14 +455,16 @@ export class SeasonalEventService { } public givePlayerSeasonalGifts(sessionId: string): void { - for (const event of this.getActiveEvents()) { - switch (event.type.toLowerCase()) { - case SeasonalEventType.CHRISTMAS.toLowerCase(): - this.giveGift(sessionId, "Christmas2022"); - break; - case SeasonalEventType.NEW_YEARS.toLowerCase(): - this.giveGift(sessionId, "NewYear2023"); - break; + if (this.currentlyActiveEvents) { + for (const event of this.currentlyActiveEvents) { + switch (event.type.toLowerCase()) { + case SeasonalEventType.CHRISTMAS.toLowerCase(): + this.giveGift(sessionId, "Christmas2022"); + break; + case SeasonalEventType.NEW_YEARS.toLowerCase(): + this.giveGift(sessionId, "NewYear2023"); + break; + } } } }