0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 16:10:43 -05:00

Improved ability for modders to adjust active seasonal events - Active events can be set via pre-db load event

This commit is contained in:
Chomp 2024-12-24 18:54:12 +00:00
parent 4317c3c273
commit 4cd868aeb3

View File

@ -33,7 +33,7 @@ export class SeasonalEventService {
protected christmasEventActive?: boolean = undefined; protected christmasEventActive?: boolean = undefined;
/** All events active at this point in time */ /** All events active at this point in time */
protected currentlyActiveEvents: ISeasonalEvent[] = []; protected currentlyActiveEvents: ISeasonalEvent[] = null;
constructor( constructor(
@inject("PrimaryLogger") protected logger: ILogger, @inject("PrimaryLogger") protected logger: ILogger,
@ -50,8 +50,6 @@ export class SeasonalEventService {
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP); this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER); this.weatherConfig = this.configServer.getConfig(ConfigTypes.WEATHER);
this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION); this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION);
this.cacheActiveEvents();
} }
protected get christmasEventItems(): string[] { protected get christmasEventItems(): string[] {
@ -85,6 +83,30 @@ 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 * Get an array of christmas items found in bots inventories as loot
* @returns array * @returns array
@ -214,11 +236,9 @@ export class SeasonalEventService {
* Handle activating seasonal events * Handle activating seasonal events
*/ */
public enableSeasonalEvents(): void { public enableSeasonalEvents(): void {
if (this.currentlyActiveEvents) { const globalConfig = this.databaseService.getGlobals().config;
const globalConfig = this.databaseService.getGlobals().config; for (const event of this.getActiveEvents()) {
for (const event of this.currentlyActiveEvents) { this.updateGlobalEvents(globalConfig, event);
this.updateGlobalEvents(globalConfig, event);
}
} }
} }
@ -236,10 +256,11 @@ export class SeasonalEventService {
/** /**
* Store active events inside class array property `currentlyActiveEvents` + set class properties: christmasEventActive/halloweenEventActive * Store active events inside class array property `currentlyActiveEvents` + set class properties: christmasEventActive/halloweenEventActive
*/ */
public cacheActiveEvents(): void { protected cacheActiveEvents(): void {
const currentDate = new Date(); const currentDate = new Date();
const seasonalEvents = this.getEventDetails(); const seasonalEvents = this.getEventDetails();
this.currentlyActiveEvents = [];
for (const event of seasonalEvents) { for (const event of seasonalEvents) {
const eventStartDate = new Date(currentDate.getFullYear(), event.startMonth - 1, event.startDay); const eventStartDate = new Date(currentDate.getFullYear(), event.startMonth - 1, event.startDay);
const eventEndDate = new Date(currentDate.getFullYear(), event.endMonth - 1, event.endDay); const eventEndDate = new Date(currentDate.getFullYear(), event.endMonth - 1, event.endDay);
@ -455,16 +476,14 @@ export class SeasonalEventService {
} }
public givePlayerSeasonalGifts(sessionId: string): void { public givePlayerSeasonalGifts(sessionId: string): void {
if (this.currentlyActiveEvents) { for (const event of this.getActiveEvents()) {
for (const event of this.currentlyActiveEvents) { switch (event.type.toLowerCase()) {
switch (event.type.toLowerCase()) { case SeasonalEventType.CHRISTMAS.toLowerCase():
case SeasonalEventType.CHRISTMAS.toLowerCase(): this.giveGift(sessionId, "Christmas2022");
this.giveGift(sessionId, "Christmas2022"); break;
break; case SeasonalEventType.NEW_YEARS.toLowerCase():
case SeasonalEventType.NEW_YEARS.toLowerCase(): this.giveGift(sessionId, "NewYear2023");
this.giveGift(sessionId, "NewYear2023"); break;
break;
}
} }
} }
} }