Server/project/src/helpers/QuestConditionHelper.ts

62 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-03-03 16:23:46 +01:00
import { injectable } from "tsyringe";
import { IQuestCondition } from "@spt-aki/models/eft/common/tables/IQuest";
2023-03-03 16:23:46 +01:00
@injectable()
export class QuestConditionHelper
{
2023-11-16 02:35:05 +01:00
public getQuestConditions(
q: IQuestCondition[],
furtherFilter: (a: IQuestCondition) => IQuestCondition[] = null,
): IQuestCondition[]
2023-03-03 16:23:46 +01:00
{
return this.filterConditions(q, "Quest", furtherFilter);
}
2023-11-16 02:35:05 +01:00
public getLevelConditions(
q: IQuestCondition[],
furtherFilter: (a: IQuestCondition) => IQuestCondition[] = null,
): IQuestCondition[]
2023-03-03 16:23:46 +01:00
{
return this.filterConditions(q, "Level", furtherFilter);
}
2023-11-16 02:35:05 +01:00
public getLoyaltyConditions(
q: IQuestCondition[],
furtherFilter: (a: IQuestCondition) => IQuestCondition[] = null,
): IQuestCondition[]
2023-03-03 16:23:46 +01:00
{
return this.filterConditions(q, "TraderLoyalty", furtherFilter);
}
2023-11-16 02:35:05 +01:00
public getStandingConditions(
q: IQuestCondition[],
furtherFilter: (a: IQuestCondition) => IQuestCondition[] = null,
): IQuestCondition[]
{
return this.filterConditions(q, "TraderStanding", furtherFilter);
}
2023-11-16 02:35:05 +01:00
protected filterConditions(
q: IQuestCondition[],
2023-11-16 02:35:05 +01:00
questType: string,
furtherFilter: (a: IQuestCondition) => IQuestCondition[] = null,
): IQuestCondition[]
2023-03-03 16:23:46 +01:00
{
2023-11-16 02:35:05 +01:00
const filteredQuests = q.filter((c) =>
2023-03-03 16:23:46 +01:00
{
if (c.conditionType === questType)
2023-03-03 16:23:46 +01:00
{
if (furtherFilter)
{
return furtherFilter(c);
}
return true;
}
return false;
});
return filteredQuests;
}
2023-11-16 02:35:05 +01:00
}