Added getTrader() and utilise inside various classes

This commit is contained in:
Dev 2024-05-28 14:13:44 +01:00
parent fdb7a2b7d8
commit 7cdac4e38b
7 changed files with 23 additions and 5 deletions

View File

@ -66,6 +66,7 @@
"customisation-unable_to_find_suit_with_id": "Unable to find suit with offer id: %s",
"customisation-unable_to_get_trader_suits": "Unable to get suits from trader: %s",
"database-data_at_path_missing": "The database was unable to retreive data from: [%s] Please ensure your configs are valid and the data at the location exists",
"database-no_trader_found_with_id": "Unable to find trader: %s in database",
"dialog-chatbot_id_already_exists": "Chat bot: %s being registered already exists, unable to register bot",
"dialog-missing_item_template": "Unable to find item tpl {{tpl}} in db, cannot send message of type {{type}}, skipping",
"dialogue-unable_to_find_dialogs_in_profile": "No dialog object in profile: {{sessionId}}",

View File

@ -39,7 +39,7 @@ export class CustomizationController
{
const pmcData = this.profileHelper.getPmcProfile(sessionID);
const clothing = this.databaseService.getCustomization();
const suits = this.databaseService.getTraders()[traderID].suits;
const suits = this.databaseService.getTrader(traderID).suits;
// Get an inner join of clothing from templates.customization and Ragman's suits array
const matchingSuits = suits?.filter((suit) => suit.suiteId in clothing);

View File

@ -675,7 +675,7 @@ export class InraidController
const serverProfile = this.saveServer.getProfile(sessionId);
const pmcData = serverProfile.characters.pmc;
const dialogueTemplates = this.databaseService.getTraders()[traderId].dialogue;
const dialogueTemplates = this.databaseService.getTrader(traderId).dialogue;
if (!dialogueTemplates)
{
this.logger.error(this.localisationService.getText("inraid-unable_to_deliver_item_no_trader_found", traderId));

View File

@ -586,7 +586,7 @@ export class InsuranceController
const labsId = "laboratory";
// After all of the item filtering that we've done, if there are no items remaining, the insurance has
// successfully "failed" to return anything and an appropriate message should be sent to the player.
const traderDialogMessages = this.databaseServer.getTraders()[insurance.traderId].dialogue;
const traderDialogMessages = this.databaseServer.getTrader(insurance.traderId).dialogue;
// Map is labs + insurance is disabled in base.json
if (

View File

@ -724,7 +724,7 @@ export class InventoryController
{
// Not fence
// get tpl from trader assort
return this.databaseService.getTraders()[request.fromOwner.id].assort.items
return this.databaseService.getTrader(request.fromOwner.id).assort.items
.find((item) => item._id === request.item)._tpl;
}

View File

@ -288,7 +288,7 @@ export class TradeController
sessionId,
this.traderHelper.getTraderById(trader),
MessageType.MESSAGE_WITH_ITEMS,
this.randomUtil.getArrayValue(this.databaseService.getTraders()[trader].dialogue.soldItems),
this.randomUtil.getArrayValue(this.databaseService.getTrader(trader).dialogue.soldItems),
curencyReward.flatMap((x) => x),
this.timeUtil.getHoursAsSeconds(72),
);

View File

@ -263,4 +263,21 @@ export class DatabaseService
return this.databaseServer.getTables().traders!;
}
/**
* Get specific trader by their Id
* @param traderId Desired trader id
* @returns assets/database/traders/
*/
public getTrader(traderId: string): ITrader
{
const traders = this.getTraders();
const desiredTrader = traders[traderId];
if (!desiredTrader)
{
throw new error(this.localisationService.getText("database-no_trader_found_with_id", traderId));
}
return desiredTrader!;
}
}