mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 06:50:43 -05:00
Refactor getTraderSuits() to make better use of .filter() instead of loops
Moved magic strings into object Misc comments
This commit is contained in:
parent
48ba66f470
commit
e4fb8cb40d
@ -17,6 +17,11 @@ import { LocalisationService } from "../services/LocalisationService";
|
|||||||
@injectable()
|
@injectable()
|
||||||
export class CustomizationController
|
export class CustomizationController
|
||||||
{
|
{
|
||||||
|
protected readonly clothingIds = {
|
||||||
|
lowerParentId: "5cd944d01388ce000a659df9",
|
||||||
|
upperParentId: "5cd944ca1388ce03a44dc2a4"
|
||||||
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@inject("WinstonLogger") protected logger: ILogger,
|
@inject("WinstonLogger") protected logger: ILogger,
|
||||||
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
|
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
|
||||||
@ -27,45 +32,41 @@ export class CustomizationController
|
|||||||
)
|
)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get purchasable clothing items from trader that match players side (usec/bear)
|
||||||
|
* @param traderID trader to look up clothing for
|
||||||
|
* @param sessionID Session id
|
||||||
|
* @returns ISuit array
|
||||||
|
*/
|
||||||
public getTraderSuits(traderID: string, sessionID: string): ISuit[]
|
public getTraderSuits(traderID: string, sessionID: string): ISuit[]
|
||||||
{
|
{
|
||||||
const pmcData: IPmcData = this.profileHelper.getPmcProfile(sessionID);
|
const pmcData: IPmcData = this.profileHelper.getPmcProfile(sessionID);
|
||||||
const templates = this.databaseServer.getTables().templates.customization;
|
const templates = this.databaseServer.getTables().templates.customization;
|
||||||
const suits = this.databaseServer.getTables().traders[traderID].suits;
|
const suits = this.databaseServer.getTables().traders[traderID].suits;
|
||||||
const result: ISuit[] = [];
|
|
||||||
|
|
||||||
// get only suites from the player's side (e.g. USEC)
|
// Get an inner join of clothing from templates.customization and ragmans suits array
|
||||||
for (const suit of suits)
|
const matchingSuits = suits.filter(x => x.suiteId in templates);
|
||||||
{
|
|
||||||
if (suit.suiteId in templates)
|
// Return all suits that have a side array containing the players side (usec/bear)
|
||||||
{
|
return matchingSuits.filter(x => templates[x.suiteId]._props.Side.includes(pmcData.Info.Side));
|
||||||
for (let i = 0; i < templates[suit.suiteId]._props.Side.length; i++)
|
|
||||||
{
|
|
||||||
if (templates[suit.suiteId]._props.Side[i] === pmcData.Info.Side)
|
|
||||||
{
|
|
||||||
result.push(suit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Equip one to many clothing items to player */
|
||||||
public wearClothing(pmcData: IPmcData, wearClothingRequest: IWearClothingRequestData, sessionID: string): IItemEventRouterResponse
|
public wearClothing(pmcData: IPmcData, wearClothingRequest: IWearClothingRequestData, sessionID: string): IItemEventRouterResponse
|
||||||
{
|
{
|
||||||
for (const suitId of wearClothingRequest.suites)
|
for (const suitId of wearClothingRequest.suites)
|
||||||
{
|
{
|
||||||
|
// Find desired clothing item in db
|
||||||
const dbSuit = this.databaseServer.getTables().templates.customization[suitId];
|
const dbSuit = this.databaseServer.getTables().templates.customization[suitId];
|
||||||
|
|
||||||
// Lower Node
|
// Legs
|
||||||
if (dbSuit._parent === "5cd944d01388ce000a659df9")
|
if (dbSuit._parent === this.clothingIds.lowerParentId)
|
||||||
{
|
{
|
||||||
pmcData.Customization.Feet = dbSuit._props.Feet;
|
pmcData.Customization.Feet = dbSuit._props.Feet;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Upper Node
|
// Torso
|
||||||
if (dbSuit._parent === "5cd944ca1388ce03a44dc2a4")
|
if (dbSuit._parent === this.clothingIds.upperParentId)
|
||||||
{
|
{
|
||||||
pmcData.Customization.Body = dbSuit._props.Body;
|
pmcData.Customization.Body = dbSuit._props.Body;
|
||||||
pmcData.Customization.Hands = dbSuit._props.Hands;
|
pmcData.Customization.Hands = dbSuit._props.Hands;
|
||||||
@ -75,6 +76,13 @@ export class CustomizationController
|
|||||||
return this.eventOutputHolder.getOutput(sessionID);
|
return this.eventOutputHolder.getOutput(sessionID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Purchase/unlock a clothing item from a trader
|
||||||
|
* @param pmcData Player profile
|
||||||
|
* @param buyClothingRequest Request object
|
||||||
|
* @param sessionId Session id
|
||||||
|
* @returns IItemEventRouterResponse
|
||||||
|
*/
|
||||||
public buyClothing(pmcData: IPmcData, buyClothingRequest: IBuyClothingRequestData, sessionId: string): IItemEventRouterResponse
|
public buyClothing(pmcData: IPmcData, buyClothingRequest: IBuyClothingRequestData, sessionId: string): IItemEventRouterResponse
|
||||||
{
|
{
|
||||||
const db = this.databaseServer.getTables();
|
const db = this.databaseServer.getTables();
|
||||||
@ -115,7 +123,7 @@ export class CustomizationController
|
|||||||
* Has an outfit been purchased by a player
|
* Has an outfit been purchased by a player
|
||||||
* @param suitId clothing id
|
* @param suitId clothing id
|
||||||
* @param sessionID Session id
|
* @param sessionID Session id
|
||||||
* @returns true/false
|
* @returns true if purchased already
|
||||||
*/
|
*/
|
||||||
protected outfitAlreadyPurchased(suitId: string, sessionID: string): boolean
|
protected outfitAlreadyPurchased(suitId: string, sessionID: string): boolean
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user