mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
Refactored seasonal and event date checking code into one function
Capitalised and localised `Event is active` text
This commit is contained in:
parent
1e486c867b
commit
02832a1c53
@ -659,6 +659,7 @@
|
||||
"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",
|
||||
"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",
|
||||
|
@ -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
|
||||
if (
|
||||
this.dateIsBetweenTwoDates(
|
||||
currentDate,
|
||||
seasonRange.startMonth,
|
||||
seasonRange.startDay,
|
||||
);
|
||||
const eventEndDate = new Date(
|
||||
currentDate.getFullYear(),
|
||||
seasonRange.endMonth - 1,
|
||||
seasonRange.endMonth,
|
||||
seasonRange.endDay,
|
||||
23,
|
||||
59,
|
||||
);
|
||||
|
||||
// Does todays date fit inside the above range
|
||||
if (currentDate >= eventStartDate && currentDate <= eventEndDate) {
|
||||
)
|
||||
) {
|
||||
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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user