Favours dot object notation whenever possible.

This commit is contained in:
Refringe 2023-11-13 11:51:02 -05:00
parent e709b6c111
commit ce45862e75
No known key found for this signature in database
GPG Key ID: 64E03E5F892C6F9E
20 changed files with 56 additions and 56 deletions

View File

@ -651,7 +651,7 @@ export class GameController
*/ */
protected fixRoguesSpawningInstantlyOnLighthouse(): void protected fixRoguesSpawningInstantlyOnLighthouse(): void
{ {
const lighthouse = this.databaseServer.getTables().locations["lighthouse"].base; const lighthouse = this.databaseServer.getTables().locations.lighthouse.base;
for (const wave of lighthouse.BossLocationSpawn) for (const wave of lighthouse.BossLocationSpawn)
{ {
// Find Rogues that spawn instantly // Find Rogues that spawn instantly
@ -815,9 +815,9 @@ export class GameController
// Merge started/success/fail quest assorts into one dictionary // Merge started/success/fail quest assorts into one dictionary
const mergedQuestAssorts = { const mergedQuestAssorts = {
...traderData.questassort["started"], ...traderData.questassort.started,
...traderData.questassort["success"], ...traderData.questassort.success,
...traderData.questassort["fail"], ...traderData.questassort.fail,
}; };
// Loop over all assorts for trader // Loop over all assorts for trader
@ -850,14 +850,14 @@ export class GameController
{ {
const bots = this.databaseServer.getTables().bots.types; const bots = this.databaseServer.getTables().bots.types;
if (bots["bear"]) if (bots.bear)
{ {
bots["bear"].firstName.push(playerName); bots.bear.firstName.push(playerName);
} }
if (bots["usec"]) if (bots.usec)
{ {
bots["usec"].firstName.push(playerName); bots.usec.firstName.push(playerName);
} }
} }
} }
@ -868,10 +868,10 @@ export class GameController
*/ */
protected checkForAndRemoveUndefinedDialogs(fullProfile: IAkiProfile): void protected checkForAndRemoveUndefinedDialogs(fullProfile: IAkiProfile): void
{ {
const undefinedDialog = fullProfile.dialogues["undefined"]; const undefinedDialog = fullProfile.dialogues.undefined;
if (undefinedDialog) if (undefinedDialog)
{ {
delete fullProfile.dialogues["undefined"]; delete fullProfile.dialogues.undefined;
} }
} }

View File

@ -374,7 +374,7 @@ export class HideoutController
const itemsToAdd = Object.entries(addItemToHideoutRequest.items).map((kvp) => const itemsToAdd = Object.entries(addItemToHideoutRequest.items).map((kvp) =>
{ {
const item = pmcData.Inventory.items.find((invItem) => invItem._id === kvp[1]["id"]); const item = pmcData.Inventory.items.find((invItem) => invItem._id === kvp[1].id);
return { return {
inventoryItem: item, inventoryItem: item,
requestedItem: kvp[1], requestedItem: kvp[1],
@ -400,7 +400,7 @@ export class HideoutController
{ {
this.logger.error( this.logger.error(
this.localisationService.getText("hideout-unable_to_find_item_in_inventory", { this.localisationService.getText("hideout-unable_to_find_item_in_inventory", {
itemId: item.requestedItem["id"], itemId: item.requestedItem.id,
area: hideoutArea.type, area: hideoutArea.type,
}), }),
); );

View File

@ -410,7 +410,7 @@ export class QuestController
); );
// For some reason non-en locales don't have repeatable quest ids, fall back to en and grab it if possible // For some reason non-en locales don't have repeatable quest ids, fall back to en and grab it if possible
const enLocale = this.databaseServer.getTables().locales.global["en"]; const enLocale = this.databaseServer.getTables().locales.global.en;
questStartedMessageText = enLocale[repeatableQuestProfile.startedMessageText]; questStartedMessageText = enLocale[repeatableQuestProfile.startedMessageText];
if (!questStartedMessageText) if (!questStartedMessageText)

View File

@ -305,7 +305,7 @@ export class RepeatableQuestController
} }
// Add "any" to pickup quest pool // Add "any" to pickup quest pool
questPool.pool.Pickup.locations["any"] = ["any"]; questPool.pool.Pickup.locations.any = ["any"];
const eliminationConfig = this.repeatableQuestHelper.getEliminationConfigByPmcLevel(pmcLevel, repeatableConfig); const eliminationConfig = this.repeatableQuestHelper.getEliminationConfigByPmcLevel(pmcLevel, repeatableConfig);
const targetsConfig = this.repeatableQuestHelper.probabilityObjectArray(eliminationConfig.targets); const targetsConfig = this.repeatableQuestHelper.probabilityObjectArray(eliminationConfig.targets);

View File

@ -282,8 +282,8 @@ export class BotGenerator
} }
const pmcNames = [ const pmcNames = [
...this.databaseServer.getTables().bots.types["usec"].firstName, ...this.databaseServer.getTables().bots.types.usec.firstName,
...this.databaseServer.getTables().bots.types["bear"].firstName, ...this.databaseServer.getTables().bots.types.bear.firstName,
]; ];
return `${name} (${this.randomUtil.getArrayValue(pmcNames)})`; return `${name} (${this.randomUtil.getArrayValue(pmcNames)})`;

View File

@ -502,7 +502,7 @@ export class BotLootGenerator
{ {
this.logger.warning(this.localisationService.getText("bot-unable_to_find_loot_n_value_for_bot", botRole)); this.logger.warning(this.localisationService.getText("bot-unable_to_find_loot_n_value_for_bot", botRole));
return this.botConfig.lootNValue["scav"]; return this.botConfig.lootNValue.scav;
} }
return result; return result;
@ -642,7 +642,7 @@ export class BotLootGenerator
{ {
if (isPmc) if (isPmc)
{ {
return this.botConfig.itemSpawnLimits["pmc"]; return this.botConfig.itemSpawnLimits.pmc;
} }
if (this.botConfig.itemSpawnLimits[botRole.toLowerCase()]) if (this.botConfig.itemSpawnLimits[botRole.toLowerCase()])
@ -654,7 +654,7 @@ export class BotLootGenerator
this.localisationService.getText("bot-unable_to_find_spawn_limits_fallback_to_defaults", botRole), this.localisationService.getText("bot-unable_to_find_spawn_limits_fallback_to_defaults", botRole),
); );
return this.botConfig.itemSpawnLimits["default"]; return this.botConfig.itemSpawnLimits.default;
} }
/** /**

View File

@ -50,10 +50,10 @@ export class BotHelper
{ {
if (this.randomUtil.getChance100(this.pmcConfig.chanceSameSideIsHostilePercent)) if (this.randomUtil.getChance100(this.pmcConfig.chanceSameSideIsHostilePercent))
{ {
difficultySettings.Mind["CAN_RECEIVE_PLAYER_REQUESTS_BEAR"] = false; difficultySettings.Mind.CAN_RECEIVE_PLAYER_REQUESTS_BEAR = false;
difficultySettings.Mind["CAN_RECEIVE_PLAYER_REQUESTS_USEC"] = false; difficultySettings.Mind.CAN_RECEIVE_PLAYER_REQUESTS_USEC = false;
difficultySettings.Mind["DEFAULT_USEC_BEHAVIOUR"] = "Attack"; difficultySettings.Mind.DEFAULT_USEC_BEHAVIOUR = "Attack";
difficultySettings.Mind["DEFAULT_BEAR_BEHAVIOUR"] = "Attack"; difficultySettings.Mind.DEFAULT_BEAR_BEHAVIOUR = "Attack";
} }
} }

View File

@ -139,8 +139,8 @@ export class DurabilityLimitsHelper
protected generateMaxPmcArmorDurability(itemMaxDurability: number): number protected generateMaxPmcArmorDurability(itemMaxDurability: number): number
{ {
const lowestMaxPercent = this.botConfig.durability["pmc"].armor.lowestMaxPercent; const lowestMaxPercent = this.botConfig.durability.pmc.armor.lowestMaxPercent;
const highestMaxPercent = this.botConfig.durability["pmc"].armor.highestMaxPercent; const highestMaxPercent = this.botConfig.durability.pmc.armor.highestMaxPercent;
const multiplier = this.randomUtil.getInt(lowestMaxPercent, highestMaxPercent); const multiplier = this.randomUtil.getInt(lowestMaxPercent, highestMaxPercent);
return itemMaxDurability * (multiplier / 100); return itemMaxDurability * (multiplier / 100);

View File

@ -60,7 +60,7 @@ export class HttpServerHelper
public sendTextJson(resp: any, output: any): void public sendTextJson(resp: any, output: any): void
{ {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
resp.writeHead(200, "OK", {"Content-Type": this.mime["json"]}); resp.writeHead(200, "OK", {"Content-Type": this.mime.json});
resp.end(output); resp.end(output);
} }
} }

View File

@ -325,9 +325,9 @@ export class InventoryHelper
const itemLocation = {}; const itemLocation = {};
// Item already has location property, use it // Item already has location property, use it
if (itemLib[tmpKey]["location"] !== undefined) if (itemLib[tmpKey].location !== undefined)
{ {
itemLocation["location"] = itemLib[tmpKey]["location"]; itemLocation.location = itemLib[tmpKey].location;
} }
output.profileChanges[sessionID].items.new.push({ output.profileChanges[sessionID].items.new.push({

View File

@ -28,7 +28,7 @@ export const Listen = (basePath: string) =>
this.handlers = {}; this.handlers = {};
// Retrieve all handlers // Retrieve all handlers
const handlersArray = Base.prototype["handlers"]; const handlersArray = Base.prototype.handlers;
if (!handlersArray) if (!handlersArray)
{ {
return; return;
@ -53,7 +53,7 @@ export const Listen = (basePath: string) =>
} }
// Cleanup the handlers list // Cleanup the handlers list
Base.prototype["handlers"] = []; Base.prototype.handlers = [];
} }
// The canHandle method is used to check if the Listener handles a request // The canHandle method is used to check if the Listener handles a request
@ -105,13 +105,13 @@ const createHttpDecorator = (httpMethod: HttpMethods) =>
return (target: any, propertyKey: string) => return (target: any, propertyKey: string) =>
{ {
// If the handlers array has not been initialized yet // If the handlers array has not been initialized yet
if (!target["handlers"]) if (!target.handlers)
{ {
target["handlers"] = []; target.handlers = [];
} }
// Flag the method as a HTTP handler // Flag the method as a HTTP handler
target["handlers"].push({ target.handlers.push({
handlerName: propertyKey, handlerName: propertyKey,
path, path,
httpMethod, httpMethod,

View File

@ -74,7 +74,7 @@ export class HttpServer
protected handleRequest(req: IncomingMessage, resp: ServerResponse): void protected handleRequest(req: IncomingMessage, resp: ServerResponse): void
{ {
// Pull sessionId out of cookies and store inside app context // Pull sessionId out of cookies and store inside app context
const sessionId = this.getCookies(req)["PHPSESSID"]; const sessionId = this.getCookies(req).PHPSESSID;
this.applicationContext.addValue(ContextVariableType.SESSION_ID, sessionId); this.applicationContext.addValue(ContextVariableType.SESSION_ID, sessionId);
// http.json logRequests boolean option to allow the user/server to choose to not log requests // http.json logRequests boolean option to allow the user/server to choose to not log requests

View File

@ -64,10 +64,10 @@ export class AkiHttpListener implements IHttpListener
// determine if the payload is compressed. All PUT requests are, and POST requests without // determine if the payload is compressed. All PUT requests are, and POST requests without
// debug = 1 are as well. This should be fixed. // debug = 1 are as well. This should be fixed.
// let compressed = req.headers["content-encoding"] === "deflate"; // let compressed = req.headers["content-encoding"] === "deflate";
const compressed = req.method === "PUT" || req.headers["debug"] !== "1"; const compressed = req.method === "PUT" || req.headers.debug !== "1";
const value = compressed ? zlib.inflateSync(buffer) : buffer; const value = compressed ? zlib.inflateSync(buffer) : buffer;
if (req.headers["debug"] === "1") if (req.headers.debug === "1")
{ {
this.logger.debug(value.toString(), true); this.logger.debug(value.toString(), true);
} }
@ -107,7 +107,7 @@ export class AkiHttpListener implements IHttpListener
let handled = false; let handled = false;
// Check if this is a debug request, if so just send the raw response without transformation // Check if this is a debug request, if so just send the raw response without transformation
if (req.headers["debug"] === "1") if (req.headers.debug === "1")
{ {
this.sendJson(resp, output, sessionID); this.sendJson(resp, output, sessionID);
} }

View File

@ -148,8 +148,8 @@ export class InsuranceService
{ {
const dialogueTemplates = this.databaseServer.getTables().traders[Traders.PRAPOR].dialogue; // todo: get trader id instead of hard coded prapor const dialogueTemplates = this.databaseServer.getTables().traders[Traders.PRAPOR].dialogue; // todo: get trader id instead of hard coded prapor
const randomResponseId = locationName?.toLowerCase() === "laboratory" ? const randomResponseId = locationName?.toLowerCase() === "laboratory" ?
this.randomUtil.getArrayValue(dialogueTemplates["insuranceFailedLabs"]) : this.randomUtil.getArrayValue(dialogueTemplates.insuranceFailedLabs) :
this.randomUtil.getArrayValue(dialogueTemplates["insuranceFailed"]); this.randomUtil.getArrayValue(dialogueTemplates.insuranceFailed);
this.mailSendService.sendLocalisedNpcMessageToPlayer( this.mailSendService.sendLocalisedNpcMessageToPlayer(
sessionId, sessionId,

View File

@ -39,7 +39,7 @@ export class LocaleService
`Unable to find desired locale file using locale ${this.getDesiredGameLocale()} from config/locale.json, falling back to 'en'`, `Unable to find desired locale file using locale ${this.getDesiredGameLocale()} from config/locale.json, falling back to 'en'`,
); );
return this.databaseServer.getTables().locales.global["en"]; return this.databaseServer.getTables().locales.global.en;
} }
/** /**

View File

@ -59,7 +59,7 @@ export class LocalisationService
*/ */
public getKeys(): string[] public getKeys(): string[]
{ {
return Object.keys(this.databaseServer.getTables().locales.server["en"]); return Object.keys(this.databaseServer.getTables().locales.server.en);
} }
/** /**
@ -69,7 +69,7 @@ export class LocalisationService
*/ */
public getRandomTextThatMatchesPartialKey(partialKey: string): string public getRandomTextThatMatchesPartialKey(partialKey: string): string
{ {
const filteredKeys = Object.keys(this.databaseServer.getTables().locales.server["en"]).filter((x) => const filteredKeys = Object.keys(this.databaseServer.getTables().locales.server.en).filter((x) =>
x.startsWith(partialKey) x.startsWith(partialKey)
); );
const chosenKey = this.randomUtil.getArrayValue(filteredKeys); const chosenKey = this.randomUtil.getArrayValue(filteredKeys);

View File

@ -469,9 +469,9 @@ export class ProfileFixerService
protected addMissingBonusesProperty(pmcProfile: IPmcData): void protected addMissingBonusesProperty(pmcProfile: IPmcData): void
{ {
if (typeof pmcProfile["Bonuses"] === "undefined") if (typeof pmcProfile.Bonuses === "undefined")
{ {
pmcProfile["Bonuses"] = []; pmcProfile.Bonuses = [];
this.logger.debug("Missing Bonuses property added to profile"); this.logger.debug("Missing Bonuses property added to profile");
} }
} }
@ -1024,7 +1024,7 @@ export class ProfileFixerService
*/ */
public addMissingHideoutAreasToProfile(fullProfile: IAkiProfile): void public addMissingHideoutAreasToProfile(fullProfile: IAkiProfile): void
{ {
const pmcProfile = fullProfile.characters["pmc"]; const pmcProfile = fullProfile.characters.pmc;
// No profile, probably new account being created // No profile, probably new account being created
if (!pmcProfile?.Hideout) if (!pmcProfile?.Hideout)
{ {
@ -1163,11 +1163,11 @@ export class ProfileFixerService
*/ */
protected migrateImprovements(pmcProfile: IPmcData): void protected migrateImprovements(pmcProfile: IPmcData): void
{ {
if (pmcProfile.Hideout["Improvements"]) if (pmcProfile.Hideout.Improvements)
{ {
// Correct name is `Improvement` // Correct name is `Improvement`
pmcProfile.Hideout.Improvement = this.jsonUtil.clone(pmcProfile.Hideout["Improvements"]); pmcProfile.Hideout.Improvement = this.jsonUtil.clone(pmcProfile.Hideout.Improvements);
delete pmcProfile.Hideout["Improvements"]; delete pmcProfile.Hideout.Improvements;
this.logger.success("Successfully migrated hideout Improvements data to new location, deleted old data"); this.logger.success("Successfully migrated hideout Improvements data to new location, deleted old data");
} }
} }

View File

@ -418,10 +418,10 @@ export class SeasonalEventService
*/ */
protected addLootItemsToGifterDropItemsList(): void protected addLootItemsToGifterDropItemsList(): void
{ {
const gifterBot = this.databaseServer.getTables().bots.types["gifter"]; const gifterBot = this.databaseServer.getTables().bots.types.gifter;
for (const difficulty in gifterBot.difficulty) for (const difficulty in gifterBot.difficulty)
{ {
gifterBot.difficulty[difficulty].Patrol["ITEMS_TO_DROP"] = gifterBot.inventory.items.Backpack.join(", "); gifterBot.difficulty[difficulty].Patrol.ITEMS_TO_DROP = gifterBot.inventory.items.Backpack.join(", ");
} }
} }
@ -471,7 +471,7 @@ export class SeasonalEventService
protected addPumpkinsToScavBackpacks(): void protected addPumpkinsToScavBackpacks(): void
{ {
const assaultBackpack = this.databaseServer.getTables().bots.types["assault"].inventory.items.Backpack; const assaultBackpack = this.databaseServer.getTables().bots.types.assault.inventory.items.Backpack;
assaultBackpack.push("634959225289190e5e773b3b"); assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b"); assaultBackpack.push("634959225289190e5e773b3b");
assaultBackpack.push("634959225289190e5e773b3b"); assaultBackpack.push("634959225289190e5e773b3b");

View File

@ -161,8 +161,8 @@ describe("BotGenerator", () =>
it("should return name `test (usec)` for player scav bot", () => it("should return name `test (usec)` for player scav bot", () =>
{ {
botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100; botGenerator.botConfig.chanceAssaultScavHasPlayerScavName = 100;
botGenerator.databaseServer.getTables().bots.types["usec"].firstName = ["usec"]; botGenerator.databaseServer.getTables().bots.types.usec.firstName = ["usec"];
botGenerator.databaseServer.getTables().bots.types["bear"].firstName = []; botGenerator.databaseServer.getTables().bots.types.bear.firstName = [];
const mockPlayerProfile = { const mockPlayerProfile = {
Info: { Info: {

View File

@ -256,7 +256,7 @@ describe("ItemHelper", () =>
const fixedItem = itemHelper.fixItemStackCount(initialItem); const fixedItem = itemHelper.fixItemStackCount(initialItem);
expect(fixedItem.upd).toBeDefined(); expect(fixedItem.upd).toBeDefined();
expect(fixedItem.upd!.StackObjectsCount).toBe(1); expect(fixedItem.upd?.StackObjectsCount).toBe(1);
}); });
it("should set upd.StackObjectsCount to 1 if upd.StackObjectsCount is undefined", () => it("should set upd.StackObjectsCount to 1 if upd.StackObjectsCount is undefined", () =>
@ -269,7 +269,7 @@ describe("ItemHelper", () =>
const fixedItem = itemHelper.fixItemStackCount(initialItem); const fixedItem = itemHelper.fixItemStackCount(initialItem);
expect(fixedItem.upd).toBeDefined(); expect(fixedItem.upd).toBeDefined();
expect(fixedItem.upd!.StackObjectsCount).toBe(1); expect(fixedItem.upd?.StackObjectsCount).toBe(1);
}); });
it("should not change upd.StackObjectsCount if it is already defined", () => it("should not change upd.StackObjectsCount if it is already defined", () =>
@ -284,7 +284,7 @@ describe("ItemHelper", () =>
const fixedItem = itemHelper.fixItemStackCount(initialItem); const fixedItem = itemHelper.fixItemStackCount(initialItem);
expect(fixedItem.upd).toBeDefined(); expect(fixedItem.upd).toBeDefined();
expect(fixedItem.upd!.StackObjectsCount).toBe(5); expect(fixedItem.upd?.StackObjectsCount).toBe(5);
}); });
}); });