Fixed seasonal event items not appearing on flea during event

Don't rely on globals event value for event check, store event bools on SeasonaleventService class construction

Remove dupe function `getSeasonalEventItemsToBlock(), rely on `getAllSeasonalEventItems()`
This commit is contained in:
Dev 2023-10-14 16:52:48 +01:00
parent 11b885539d
commit 5a0e16634e
6 changed files with 38 additions and 40 deletions

View File

@ -211,7 +211,7 @@ export class GameController
if (this.seasonalEventService.isAutomaticEventDetectionEnabled())
{
this.seasonalEventService.checkForAndEnableSeasonalEvents(sessionID);
this.seasonalEventService.enableSeasonalEvents(sessionID);
}
if (pmcProfile?.Skills?.Common)

View File

@ -38,7 +38,7 @@ export class FenceBaseAssortGenerator
*/
public generateFenceBaseAssorts(): void
{
const blockedSeasonalItems = this.seasonalEventService.getSeasonalEventItemsToBlock();
const blockedSeasonalItems = this.seasonalEventService.getAllSeasonalEventItems();
const baseFenceAssort = this.databaseServer.getTables().traders[Traders.FENCE].assort;

View File

@ -436,7 +436,7 @@ export class LocationGenerator
protected getPossibleLootItemsForContainer(containerTypeId: string, staticLootDist: Record<string, IStaticLootDetails>): ProbabilityObjectArray<string, number>
{
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock();
const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems();
const itemDistribution = new ProbabilityObjectArray<string>(this.mathUtil, this.jsonUtil);
for (const icd of staticLootDist[containerTypeId].itemDistribution)
@ -535,7 +535,7 @@ export class LocationGenerator
// Iterate over spawnpoints
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock();
const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems();
for (const spawnPoint of chosenSpawnpoints)
{
const itemArray = new ProbabilityObjectArray<string>(this.mathUtil, this.jsonUtil);
@ -611,7 +611,7 @@ export class LocationGenerator
}
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock();
const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems();
// Add remaining forced loot to array
for (const forcedLootItem of forcedSpawnPoints)
{

View File

@ -53,7 +53,7 @@ export class PMCLootGenerator
if (!this.seasonalEventService.seasonalEventEnabled())
{
// Blacklist seasonal items
itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock());
itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems());
}
const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent)
@ -89,7 +89,7 @@ export class PMCLootGenerator
if (!this.seasonalEventService.seasonalEventEnabled())
{
// Blacklist seasonal items
itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock());
itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems());
}
const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent)
@ -134,7 +134,7 @@ export class PMCLootGenerator
if (!this.seasonalEventService.seasonalEventEnabled())
{
// Blacklist seasonal items
itemBlacklist.push(...this.seasonalEventService.getSeasonalEventItemsToBlock());
itemBlacklist.push(...this.seasonalEventService.getAllSeasonalEventItems());
}
const itemsToAdd = Object.values(items).filter(item => allowedItemTypes.includes(item._parent)

View File

@ -76,7 +76,7 @@ export class RagfairAssortGenerator
];
const seasonalEventActive = this.seasonalEventService.seasonalEventEnabled();
const seasonalItemTplBlacklist = this.seasonalEventService.getSeasonalEventItemsToBlock();
const seasonalItemTplBlacklist = this.seasonalEventService.getAllSeasonalEventItems();
for (const item of items)
{
if (!this.itemHelper.isValidItem(item._id, ragfairItemInvalidBaseTypes))

View File

@ -24,6 +24,9 @@ export class SeasonalEventService
protected questConfig: IQuestConfig;
protected httpConfig: IHttpConfig;
protected halloweenEventActive = undefined;
protected christmasEventActive = undefined;
constructor(
@inject("WinstonLogger") protected logger: ILogger,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@ -38,6 +41,8 @@ export class SeasonalEventService
this.seasonalEventConfig = this.configServer.getConfig(ConfigTypes.SEASONAL_EVENT);
this.questConfig = this.configServer.getConfig(ConfigTypes.QUEST);
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
this.cacheActiveEvents();
}
protected get christmasEventItems(): string[]
@ -107,28 +112,6 @@ export class SeasonalEventService
public getAllSeasonalEventItems(): string[]
{
const items = [];
if (!this.christmasEventEnabled())
{
items.push(...this.christmasEventItems);
}
if (!this.halloweenEventEnabled())
{
items.push(...this.halloweenEventItems);
}
return items;
}
/**
* Get an array of seasonal items that should be blocked as season is not currently active
* @returns Array of tpl strings
*/
public getSeasonalEventItemsToBlock(): string[]
{
const items = [];
if (!this.christmasEventEnabled())
{
items.push(...this.christmasEventItems);
@ -148,26 +131,25 @@ export class SeasonalEventService
*/
public seasonalEventEnabled(): boolean
{
return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.CHRISTMAS) ||
this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.HALLOWEEN);
return this.christmasEventEnabled() || this.halloweenEventEnabled();
}
/**
* Is christmas event active (Globals eventtype array contains even name)
* Is christmas event active
* @returns true if active
*/
public christmasEventEnabled(): boolean
{
return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.CHRISTMAS);
return this.christmasEventActive;
}
/**
* is halloween event active (Globals eventtype array contains even name)
* is halloween event active
* @returns true if active
*/
public halloweenEventEnabled(): boolean
{
return this.databaseServer.getTables().globals.config.EventType.includes(SeasonalEventType.HALLOWEEN);
return this.halloweenEventActive;
}
/**
@ -216,12 +198,25 @@ export class SeasonalEventService
}
/**
* Check if current date falls inside any of the seasons events pased in, if so, handle them
* Handle seasonal events
* @param sessionId Players id
*/
public checkForAndEnableSeasonalEvents(sessionId: string): void
public enableSeasonalEvents(sessionId: string): void
{
const globalConfig = this.databaseServer.getTables().globals.config;
if (this.christmasEventActive)
{
this.updateGlobalEvents(sessionId, globalConfig, SeasonalEventType.CHRISTMAS);
}
if (this.halloweenEventActive)
{
this.updateGlobalEvents(sessionId, globalConfig, SeasonalEventType.HALLOWEEN);
}
}
protected cacheActiveEvents(): void
{
const currentDate = new Date();
const seasonalEvents = this.getEventDetails();
@ -234,7 +229,8 @@ export class SeasonalEventService
if (currentDate >= eventStartDate
&& currentDate <= eventEndDate)
{
this.updateGlobalEvents(sessionId, globalConfig, event.type);
this.christmasEventActive = (SeasonalEventType[event.type] === SeasonalEventType.CHRISTMAS);
this.halloweenEventActive = (SeasonalEventType[event.type] === SeasonalEventType.HALLOWEEN);
}
}
}
@ -395,6 +391,8 @@ export class SeasonalEventService
assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b");
}
/**