Implement magazine template saving

This commit is contained in:
Dev 2023-12-28 12:02:37 +00:00
parent 2f3b2590d6
commit 8dc322180f
7 changed files with 55 additions and 10 deletions

View File

@ -1,4 +1,5 @@
import { BuildController } from "@spt-aki/controllers/BuildController";
import { ISetMagazineRequest } from "@spt-aki/models/eft/builds/ISetMagazineRequest";
import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData";
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
import { IUserBuilds } from "@spt-aki/models/eft/profile/IAkiProfile";
@ -27,9 +28,11 @@ export class BuildsCallbacks
* Handle client/builds/magazine/save
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public setMagazine(url: string, info: IEmptyRequestData, sessionID: string): any
public createMagazineTemplate(url: string, request: ISetMagazineRequest, sessionID: string): IGetBodyResponseData<string>
{
throw new Error("Not implemented");
this.buildController.createMagazineTemplate(sessionID, request)
return this.httpResponse.emptyResponse();
}
/**

View File

@ -1,11 +1,13 @@
import { inject, injectable } from "tsyringe";
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
import { ISetMagazineRequest } from "@spt-aki/models/eft/builds/ISetMagazineRequest";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { IPresetBuildActionRequestData } from "@spt-aki/models/eft/presetBuild/IPresetBuildActionRequestData";
import { IRemoveBuildRequestData } from "@spt-aki/models/eft/presetBuild/IRemoveBuildRequestData";
import { IUserBuilds, IWeaponBuild } from "@spt-aki/models/eft/profile/IAkiProfile";
import { IMagazineBuild, IUserBuilds, IWeaponBuild } from "@spt-aki/models/eft/profile/IAkiProfile";
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder";
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
@ -22,6 +24,7 @@ export class BuildController
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
@inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("ItemHelper") protected itemHelper: ItemHelper,
@inject("SaveServer") protected saveServer: SaveServer,
)
@ -226,4 +229,20 @@ export class BuildController
return this.eventOutputHolder.getOutput(sessionID);
}
public createMagazineTemplate(sessionId: string, request: ISetMagazineRequest): void
{
const result: IMagazineBuild = {
Id: request.Id,
Name: request.Name,
Caliber: request.Caliber,
TopCount: request.TopCount,
BottomCount: request.BottomCount,
Items: request.items,
type: "magazine"
};
const profile = this.profileHelper.getFullProfile(sessionId);
profile.userbuilds.magazineBuilds.push(result);
}
}

View File

@ -7,7 +7,7 @@ import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
import { QuestHelper } from "@spt-aki/helpers/QuestHelper";
import { TraderHelper } from "@spt-aki/helpers/TraderHelper";
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
import { TemplateSide } from "@spt-aki/models/eft/common/tables/IProfileTemplate";
import { ITemplateSide } from "@spt-aki/models/eft/common/tables/IProfileTemplate";
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
import { IMiniProfile } from "@spt-aki/models/eft/launcher/IMiniProfile";
import { GetProfileStatusResponseData } from "@spt-aki/models/eft/profile/GetProfileStatusResponseData";
@ -127,7 +127,7 @@ export class ProfileController
public createProfile(info: IProfileCreateRequestData, sessionID: string): string
{
const account = this.saveServer.getProfile(sessionID).info;
const profile: TemplateSide =
const profile: ITemplateSide =
this.databaseServer.getTables().templates.profiles[account.edition][info.side.toLowerCase()];
const pmcData = profile.character;

View File

@ -0,0 +1,11 @@
import { IMagazineTemplateAmmoItem } from "../profile/IAkiProfile"
export interface ISetMagazineRequest
{
Id: string
Name: string
Caliber: string
items: IMagazineTemplateAmmoItem[]
TopCount: number
BottomCount: number
}

View File

@ -17,11 +17,11 @@ export interface IProfileTemplates
export interface IProfileSides
{
descriptionLocaleKey: string;
usec: TemplateSide;
bear: TemplateSide;
usec: ITemplateSide;
bear: ITemplateSide;
}
export interface TemplateSide
export interface ITemplateSide
{
character: IPmcData;
suits: string[];

View File

@ -77,7 +77,19 @@ export interface IEquipmentBuild
export interface IMagazineBuild
{
Id: string;
Name: string;
Caliber: string
TopCount: number
BottomCount: number
Items: IMagazineTemplateAmmoItem[]
type: string
}
export interface IMagazineTemplateAmmoItem
{
TemplateId: string
Count: number
}
export interface Dialogue

View File

@ -22,7 +22,7 @@ export class BuildsStaticRouter extends StaticRouter
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(url: string, info: any, sessionID: string, output: string): any =>
{
return this.buildsCallbacks.setMagazine(url, info, sessionID);
return this.buildsCallbacks.createMagazineTemplate(url, info, sessionID);
},
),
new RouteAction(