0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-12 15:50:42 -05:00

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

This reverts commit 4cd868aeb302515b879ed204397b567c73d2fcd2.
This commit is contained in:
Chomp 2024-12-24 19:09:51 +00:00
parent 4cd868aeb3
commit 952544f5d3

View File

@ -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;
}
}
}
}