Add trader service requirement support & LKS Service requirements (!235)
Add LightKeeper trader service requirements Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/235 Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com> Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
parent
40b31e1fe0
commit
1deb6d9488
@ -4,6 +4,11 @@
|
||||
"itemsToPay": {
|
||||
"62a0a16d0b9d3c46de5b6e97": 3,
|
||||
"5696686a4bdc2da3298b456a": 2000
|
||||
},
|
||||
"requirements": {
|
||||
"completedQuests": [
|
||||
"6396701b9113f06a7c3b2379"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -11,6 +16,11 @@
|
||||
"itemsToPay": {
|
||||
"6389c8c5dbfd5e4b95197e6b": 1,
|
||||
"569668774bdc2da2298b4568": 2500
|
||||
},
|
||||
"requirements": {
|
||||
"completedQuests": [
|
||||
"63966ff54c3ef01b6f3ffad8"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -21,6 +31,14 @@
|
||||
},
|
||||
"itemsToReceive": [
|
||||
"64d0b40fbe2eed70e254e2d4"
|
||||
]
|
||||
],
|
||||
"requirements": {
|
||||
"completedQuests": [
|
||||
"63966fccac6f8f3c677b9d89"
|
||||
],
|
||||
"standings": {
|
||||
"638f541a29ffd1183d187f57": 0.04
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
@ -603,7 +603,7 @@ export class InraidController
|
||||
*/
|
||||
public getTraderServices(sessionId: string, traderId: string): ITraderServiceModel[]
|
||||
{
|
||||
return this.traderServicesService.getTraderServices(traderId);
|
||||
return this.traderServicesService.getTraderServices(sessionId, traderId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,4 +6,11 @@ export interface ITraderServiceModel
|
||||
itemsToPay?: {[key: string]: number};
|
||||
itemsToReceive?: string[];
|
||||
subServices?: {[key: string]: number};
|
||||
requirements?: ITraderServiceRequirementsModel;
|
||||
}
|
||||
|
||||
export interface ITraderServiceRequirementsModel
|
||||
{
|
||||
completedQuests?: string[];
|
||||
standings?: {[key: string]: number};
|
||||
}
|
@ -1,20 +1,64 @@
|
||||
import { ITraderServiceModel } from "@spt-aki/models/spt/services/ITraderServiceModel";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
||||
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
||||
import { inject, injectable } from "tsyringe";
|
||||
import { QuestStatus } from "@spt-aki/models/enums/QuestStatus";
|
||||
|
||||
@injectable()
|
||||
export class TraderServicesService
|
||||
{
|
||||
constructor(
|
||||
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
||||
)
|
||||
{}
|
||||
|
||||
public getTraderServices(traderId: string): ITraderServiceModel[]
|
||||
public getTraderServices(sessionId: string, traderId: string): ITraderServiceModel[]
|
||||
{
|
||||
const traderServices = this.databaseServer.getTables().traders[traderId]?.services;
|
||||
return traderServices ?? [];
|
||||
const pmcData = this.profileHelper.getPmcProfile(sessionId);
|
||||
let traderServices = this.jsonUtil.clone(this.databaseServer.getTables().traders[traderId]?.services);
|
||||
if (!traderServices)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
// Filter out any service the user doesn't meet the conditions for
|
||||
const servicesToDelete = [];
|
||||
for (const service of traderServices)
|
||||
{
|
||||
if (service.requirements?.standings)
|
||||
{
|
||||
for (const [standingTrader, standing] of Object.entries(service.requirements.standings))
|
||||
{
|
||||
if (pmcData.TradersInfo[standingTrader].standing < standing)
|
||||
{
|
||||
servicesToDelete.push(service.serviceType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (service.requirements?.completedQuests)
|
||||
{
|
||||
for (const questId of service.requirements.completedQuests)
|
||||
{
|
||||
const quest = pmcData.Quests.find((x) => x.qid === questId);
|
||||
if (!quest || quest.status != QuestStatus.Success)
|
||||
{
|
||||
servicesToDelete.push(service.serviceType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clear any unavailable services from the list
|
||||
traderServices = traderServices.filter(x => !servicesToDelete.includes(x.serviceType));
|
||||
|
||||
return traderServices;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user