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,7 +659,8 @@
|
|||||||
"scav-unable_to_add_item_to_player_scav": "Unable to add: %s to player scav, not an item",
|
"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.",
|
"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-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}}",
|
"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_running": "Server is running, do not close while playing SPT",
|
||||||
"server_start_meme_1": "Live laugh love",
|
"server_start_meme_1": "Live laugh love",
|
||||||
|
@ -251,11 +251,9 @@ export class SeasonalEventService {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventStartDate = new Date(currentDate.getFullYear(), event.startMonth - 1, event.startDay);
|
if (
|
||||||
const eventEndDate = new Date(currentDate.getFullYear(), event.endMonth - 1, event.endDay, 23, 59);
|
this.dateIsBetweenTwoDates(currentDate, event.startMonth, event.startDay, event.endMonth, event.endDay)
|
||||||
|
) {
|
||||||
// Current date is between start/end dates
|
|
||||||
if (currentDate >= eventStartDate && currentDate <= eventEndDate) {
|
|
||||||
this.currentlyActiveEvents.push(event);
|
this.currentlyActiveEvents.push(event);
|
||||||
|
|
||||||
if (SeasonalEventType[event.type] === SeasonalEventType.CHRISTMAS) {
|
if (SeasonalEventType[event.type] === SeasonalEventType.CHRISTMAS) {
|
||||||
@ -280,22 +278,15 @@ export class SeasonalEventService {
|
|||||||
|
|
||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
for (const seasonRange of this.weatherConfig.seasonDates) {
|
for (const seasonRange of this.weatherConfig.seasonDates) {
|
||||||
// Figure out start and end dates to get range of season
|
if (
|
||||||
const eventStartDate = new Date(
|
this.dateIsBetweenTwoDates(
|
||||||
currentDate.getFullYear(),
|
currentDate,
|
||||||
seasonRange.startMonth - 1, // Month value starts at 0
|
seasonRange.startMonth,
|
||||||
seasonRange.startDay,
|
seasonRange.startDay,
|
||||||
);
|
seasonRange.endMonth,
|
||||||
const eventEndDate = new Date(
|
seasonRange.endDay,
|
||||||
currentDate.getFullYear(),
|
)
|
||||||
seasonRange.endMonth - 1,
|
) {
|
||||||
seasonRange.endDay,
|
|
||||||
23,
|
|
||||||
59,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Does todays date fit inside the above range
|
|
||||||
if (currentDate >= eventStartDate && currentDate <= eventEndDate) {
|
|
||||||
return seasonRange.seasonType;
|
return seasonRange.seasonType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,6 +296,30 @@ export class SeasonalEventService {
|
|||||||
return Season.SUMMER;
|
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)
|
* Iterate through bots inventory and loot to find and remove christmas items (as defined in SeasonalEventService)
|
||||||
* @param botInventory Bots inventory to iterate over
|
* @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
|
* @param eventName Name of the event to enable. e.g. Christmas
|
||||||
*/
|
*/
|
||||||
protected updateGlobalEvents(globalConfig: IConfig, event: ISeasonalEvent): void {
|
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()) {
|
switch (event.type.toLowerCase()) {
|
||||||
case SeasonalEventType.HALLOWEEN.toLowerCase():
|
case SeasonalEventType.HALLOWEEN.toLowerCase():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user