diff --git a/project/assets/database/locales/server/en.json b/project/assets/database/locales/server/en.json index 729525d1..69eb574f 100644 --- a/project/assets/database/locales/server/en.json +++ b/project/assets/database/locales/server/en.json @@ -659,7 +659,8 @@ "scav-unable_to_add_item_to_player_scav": "Unable to add: %s to player scav, not an item", "scheduled_event_failed_to_run": "Scheduled event: '%s' failed to run successfully.", "season-no_matching_season_found_for_date": "Unable to find a season using the current date, defaulting to Summer", - "seasonal-missing_equipment_slot_on_bot": "Unable to remove christmas equipment from slot: {{equipmentSlot}} as it cannot be found on bot: {{botRole}}", + "season-event_is_active": "Event: %s is active", + "seasonal-missing_equipment_slot_on_bot": "Unable to remove christmas equipment from slot: {{equipmentSlot}} as it cannot be found on bot: {{botRole}}", "seasonal-missing_loot_container_slot_on_bot": "Unable to remove christmas loot from slot: {{lootContainer}} as it cannot be found on bot: {{botRole}}", "server_running": "Server is running, do not close while playing SPT", "server_start_meme_1": "Live laugh love", diff --git a/project/src/services/SeasonalEventService.ts b/project/src/services/SeasonalEventService.ts index 18cc86e5..98f57b89 100644 --- a/project/src/services/SeasonalEventService.ts +++ b/project/src/services/SeasonalEventService.ts @@ -251,11 +251,9 @@ export class SeasonalEventService { continue; } - const eventStartDate = new Date(currentDate.getFullYear(), event.startMonth - 1, event.startDay); - const eventEndDate = new Date(currentDate.getFullYear(), event.endMonth - 1, event.endDay, 23, 59); - - // Current date is between start/end dates - if (currentDate >= eventStartDate && currentDate <= eventEndDate) { + if ( + this.dateIsBetweenTwoDates(currentDate, event.startMonth, event.startDay, event.endMonth, event.endDay) + ) { this.currentlyActiveEvents.push(event); if (SeasonalEventType[event.type] === SeasonalEventType.CHRISTMAS) { @@ -280,22 +278,15 @@ export class SeasonalEventService { const currentDate = new Date(); for (const seasonRange of this.weatherConfig.seasonDates) { - // Figure out start and end dates to get range of season - const eventStartDate = new Date( - currentDate.getFullYear(), - seasonRange.startMonth - 1, // Month value starts at 0 - seasonRange.startDay, - ); - const eventEndDate = new Date( - currentDate.getFullYear(), - seasonRange.endMonth - 1, - seasonRange.endDay, - 23, - 59, - ); - - // Does todays date fit inside the above range - if (currentDate >= eventStartDate && currentDate <= eventEndDate) { + if ( + this.dateIsBetweenTwoDates( + currentDate, + seasonRange.startMonth, + seasonRange.startDay, + seasonRange.endMonth, + seasonRange.endDay, + ) + ) { return seasonRange.seasonType; } } @@ -305,6 +296,30 @@ export class SeasonalEventService { return Season.SUMMER; } + /** + * Does the provided date fit between the two defined dates? + * Excludes year + * Inclusive of end date upto 23 hours 59 minutes + * @param dateToCheck Date to check is between 2 dates + * @param startMonth Lower bound for month + * @param startDay Lower bound for day + * @param endMonth Upper bound for month + * @param endDay Upper bound for day + * @returns True when inside date range + */ + protected dateIsBetweenTwoDates( + dateToCheck: Date, + startMonth: number, + startDay: number, + endMonth: number, + endDay: number, + ): boolean { + const eventStartDate = new Date(dateToCheck.getFullYear(), startMonth - 1, startDay); + const eventEndDate = new Date(dateToCheck.getFullYear(), endMonth - 1, endDay, 23, 59); + + return dateToCheck >= eventStartDate && dateToCheck <= eventEndDate; + } + /** * Iterate through bots inventory and loot to find and remove christmas items (as defined in SeasonalEventService) * @param botInventory Bots inventory to iterate over @@ -377,7 +392,7 @@ export class SeasonalEventService { * @param eventName Name of the event to enable. e.g. Christmas */ protected updateGlobalEvents(globalConfig: IConfig, event: ISeasonalEvent): void { - this.logger.success(`event: ${event.type} is active`); + this.logger.success(this.localisationService.getText("season-event_is_active", event.type)); switch (event.type.toLowerCase()) { case SeasonalEventType.HALLOWEEN.toLowerCase():