Improve getTrader()
Error when no profile found Reduce returns to 1 fold two checks into one Remove magic string reliance on TradersInfo exist check More comments
This commit is contained in:
parent
729b180e85
commit
0e3d25df03
@ -48,24 +48,35 @@ export class TraderHelper
|
|||||||
this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER);
|
this.traderConfig = this.configServer.getConfig(ConfigTypes.TRADER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a trader base object, update profile to reflect players current standing in profile
|
||||||
|
* when trader not found in profile
|
||||||
|
* @param traderID Traders Id to get
|
||||||
|
* @param sessionID Players id
|
||||||
|
* @returns Trader base
|
||||||
|
*/
|
||||||
public getTrader(traderID: string, sessionID: string): ITraderBase
|
public getTrader(traderID: string, sessionID: string): ITraderBase
|
||||||
{
|
{
|
||||||
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
||||||
const trader = this.databaseServer.getTables().traders[traderID].base;
|
if (!pmcData)
|
||||||
|
|
||||||
if (!("TradersInfo" in pmcData))
|
|
||||||
{
|
{
|
||||||
// pmc profile wiped
|
this.logger.error(`No profile with sessionId: ${sessionID}`);
|
||||||
return trader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(traderID in pmcData.TradersInfo))
|
// Profile has traderInfo dict (profile beyond creation stage) but no requested trader in profile
|
||||||
|
if (pmcData.TradersInfo && !(traderID in pmcData.TradersInfo))
|
||||||
{
|
{
|
||||||
// trader doesn't exist in profile
|
// Add trader values to profile
|
||||||
this.resetTrader(sessionID, traderID);
|
this.resetTrader(sessionID, traderID);
|
||||||
this.lvlUp(traderID, pmcData);
|
this.lvlUp(traderID, pmcData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const trader = this.databaseServer.getTables().traders?.[traderID]?.base;
|
||||||
|
if (!trader)
|
||||||
|
{
|
||||||
|
this.logger.error(`No trader with Id: ${traderID} found`);
|
||||||
|
}
|
||||||
|
|
||||||
return trader;
|
return trader;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user