Server/project/src/helpers/QuestConditionHelper.ts
2023-03-03 15:23:46 +00:00

40 lines
1.4 KiB
TypeScript

import { injectable } from "tsyringe";
import { AvailableForConditions } from "../models/eft/common/tables/IQuest";
@injectable()
export class QuestConditionHelper
{
public getQuestConditions(q: AvailableForConditions[], furtherFilter: (a: AvailableForConditions) => AvailableForConditions[] = null): AvailableForConditions[]
{
return this.filterConditions(q, "Quest", furtherFilter);
}
public getLevelConditions(q: AvailableForConditions[], furtherFilter: (a: AvailableForConditions) => AvailableForConditions[] = null): AvailableForConditions[]
{
return this.filterConditions(q, "Level", furtherFilter);
}
public getLoyaltyConditions(q: AvailableForConditions[], furtherFilter: (a: AvailableForConditions) => AvailableForConditions[] = null): AvailableForConditions[]
{
return this.filterConditions(q, "TraderLoyalty", furtherFilter);
}
protected filterConditions(q: AvailableForConditions[], questType: string, furtherFilter: (a: AvailableForConditions) => AvailableForConditions[] = null): AvailableForConditions[]
{
const filteredQuests = q.filter(c =>
{
if (c._parent === questType)
{
if (furtherFilter)
{
return furtherFilter(c);
}
return true;
}
return false;
});
return filteredQuests;
}
}