(More) Simple Parameter Reassignment Issues

Addresses some of the simple linting errors regarding the reassignment of function parameters.
This commit is contained in:
Refringe 2024-02-05 22:02:44 -05:00
parent d8fe911464
commit c29482394b
No known key found for this signature in database
GPG Key ID: 64E03E5F892C6F9E
6 changed files with 38 additions and 43 deletions

View File

@ -85,11 +85,13 @@ export class BotController
* Get bot difficulty settings * Get bot difficulty settings
* adjust PMC settings to ensure they engage the correct bot types * adjust PMC settings to ensure they engage the correct bot types
* @param type what bot the server is requesting settings for * @param type what bot the server is requesting settings for
* @param difficulty difficulty level server requested settings for * @param diffLevel difficulty level server requested settings for
* @returns Difficulty object * @returns Difficulty object
*/ */
public getBotDifficulty(type: string, difficulty: string): Difficulty public getBotDifficulty(type: string, diffLevel: string): Difficulty
{ {
let difficulty = diffLevel.toLowerCase();
const raidConfig = this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue< const raidConfig = this.applicationContext.getLatestValue(ContextVariableType.RAID_CONFIGURATION)?.getValue<
IGetRaidConfigurationRequestData IGetRaidConfigurationRequestData
>(); >();

View File

@ -452,11 +452,11 @@ export class InraidController
): void ): void
{ {
// Update scav profile inventory // Update scav profile inventory
scavData = this.inRaidHelper.setInventory(sessionID, scavData, offraidData.profile); const updatedScavData = this.inRaidHelper.setInventory(sessionID, scavData, offraidData.profile);
// Reset scav hp and save to json // Reset scav hp and save to json
this.healthHelper.resetVitality(sessionID); this.healthHelper.resetVitality(sessionID);
this.saveServer.getProfile(sessionID).characters.scav = scavData; this.saveServer.getProfile(sessionID).characters.scav = updatedScavData;
// Scav karma // Scav karma
this.handlePostRaidPlayerScavKarmaChanges(pmcData, offraidData); this.handlePostRaidPlayerScavKarmaChanges(pmcData, offraidData);

View File

@ -299,10 +299,10 @@ export class BotGenerator
*/ */
protected logPmcGeneratedCount(output: IBotBase[]): void protected logPmcGeneratedCount(output: IBotBase[]): void
{ {
const pmcCount = output.reduce( const pmcCount = output.reduce((acc, cur) =>
(acc, cur) => cur.Info.Side === "Bear" || cur.Info.Side === "Usec" ? ++acc : acc, {
0, return cur.Info.Side === "Bear" || cur.Info.Side === "Usec" ? acc + 1 : acc;
); }, 0);
this.logger.debug(`Generated ${output.length} total bots. Replaced ${pmcCount} with PMCs`); this.logger.debug(`Generated ${output.length} total bots. Replaced ${pmcCount} with PMCs`);
} }

View File

@ -903,12 +903,12 @@ export class RepeatableQuestGenerator
* *
* There's also a random variation of the reward the spread of which can be also defined in the config. * There's also a random variation of the reward the spread of which can be also defined in the config.
* *
* Additonaly, a scaling factor w.r.t. quest difficulty going from 0.2...1 can be used * Additionally, a scaling factor w.r.t. quest difficulty going from 0.2...1 can be used
* *
* @param {integer} pmcLevel player's level * @param {integer} pmcLevel player's level
* @param {number} difficulty a reward scaling factor goint from 0.2 to 1 * @param {number} difficulty a reward scaling factor from 0.2 to 1
* @param {string} traderId the trader for reputation gain (and possible in the future filtering of reward item type based on trader) * @param {string} traderId the trader for reputation gain (and possible in the future filtering of reward item type based on trader)
* @param {object} repeatableConfig The configuration for the repeatably kind (daily, weekly) as configured in QuestConfig for the requestd quest * @param {object} repeatableConfig The configuration for the repeatable kind (daily, weekly) as configured in QuestConfig for the requested quest
* @returns {object} object of "Reward"-type that can be given for a repeatable mission * @returns {object} object of "Reward"-type that can be given for a repeatable mission
*/ */
protected generateReward( protected generateReward(
@ -919,7 +919,7 @@ export class RepeatableQuestGenerator
questConfig: IBaseQuestConfig, questConfig: IBaseQuestConfig,
): IQuestRewards ): IQuestRewards
{ {
// difficulty could go from 0.2 ... -> for lowest diffuculty receive 0.2*nominal reward // difficulty could go from 0.2 ... -> for lowest difficulty receive 0.2*nominal reward
const levelsConfig = repeatableConfig.rewardScaling.levels; const levelsConfig = repeatableConfig.rewardScaling.levels;
const roublesConfig = repeatableConfig.rewardScaling.roubles; const roublesConfig = repeatableConfig.rewardScaling.roubles;
const xpConfig = repeatableConfig.rewardScaling.experience; const xpConfig = repeatableConfig.rewardScaling.experience;
@ -929,19 +929,19 @@ export class RepeatableQuestGenerator
const skillPointRewardConfig = repeatableConfig.rewardScaling.skillPointReward; const skillPointRewardConfig = repeatableConfig.rewardScaling.skillPointReward;
const reputationConfig = repeatableConfig.rewardScaling.reputation; const reputationConfig = repeatableConfig.rewardScaling.reputation;
const effectiveDifficulty = Number.isNaN(difficulty) ? 1 : difficulty;
if (Number.isNaN(difficulty)) if (Number.isNaN(difficulty))
{ {
difficulty = 1;
this.logger.warning(this.localisationService.getText("repeatable-difficulty_was_nan")); this.logger.warning(this.localisationService.getText("repeatable-difficulty_was_nan"));
} }
// rewards are generated based on pmcLevel, difficulty and a random spread // rewards are generated based on pmcLevel, difficulty and a random spread
const rewardXP = Math.floor( const rewardXP = Math.floor(
difficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, xpConfig) effectiveDifficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, xpConfig)
* this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig), * this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig),
); );
const rewardRoubles = Math.floor( const rewardRoubles = Math.floor(
difficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, roublesConfig) effectiveDifficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, roublesConfig)
* this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig), * this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig),
); );
const rewardNumItems = this.randomUtil.randInt( const rewardNumItems = this.randomUtil.randInt(
@ -950,7 +950,7 @@ export class RepeatableQuestGenerator
); );
const rewardReputation = const rewardReputation =
Math.round( Math.round(
100 * difficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, reputationConfig) 100 * effectiveDifficulty * this.mathUtil.interp1(pmcLevel, levelsConfig, reputationConfig)
* this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig), * this.randomUtil.getFloat(1 - rewardSpreadConfig, 1 + rewardSpreadConfig),
) / 100; ) / 100;
const skillRewardChance = this.mathUtil.interp1(pmcLevel, levelsConfig, skillRewardChanceConfig); const skillRewardChance = this.mathUtil.interp1(pmcLevel, levelsConfig, skillRewardChanceConfig);
@ -998,7 +998,7 @@ export class RepeatableQuestGenerator
const defaultPresets = Object.values(this.presetHelper.getDefaultPresets()); const defaultPresets = Object.values(this.presetHelper.getDefaultPresets());
const defaultPresetClone = this.jsonUtil.clone(this.randomUtil.getArrayValue(defaultPresets)); const defaultPresetClone = this.jsonUtil.clone(this.randomUtil.getArrayValue(defaultPresets));
// use _encyclopedia as its always the base items _tpl, items[0] isnt guaranteed to be base item // use _encyclopedia as its always the base items _tpl, items[0] isn't guaranteed to be base item
rewards.Success.push( rewards.Success.push(
this.generateRewardItem(defaultPresetClone._encyclopedia, 1, rewardIndex, defaultPresetClone._items), this.generateRewardItem(defaultPresetClone._encyclopedia, 1, rewardIndex, defaultPresetClone._items),
); );
@ -1014,7 +1014,7 @@ export class RepeatableQuestGenerator
if (this.itemHelper.isOfBaseclass(itemSelected._id, BaseClasses.AMMO)) if (this.itemHelper.isOfBaseclass(itemSelected._id, BaseClasses.AMMO))
{ {
// Dont reward ammo that stacks to less than what's defined in config // Don't reward ammo that stacks to less than what's defined in config
if (itemSelected._props.StackMaxSize < repeatableConfig.rewardAmmoStackMinSize) if (itemSelected._props.StackMaxSize < repeatableConfig.rewardAmmoStackMinSize)
{ {
continue; continue;
@ -1028,7 +1028,7 @@ export class RepeatableQuestGenerator
// Get a stack size of ammo that fits rouble budget // Get a stack size of ammo that fits rouble budget
const stackSizeThatFitsBudget = Math.round(stackRoubleBudget / singleCartridgePrice); const stackSizeThatFitsBudget = Math.round(stackRoubleBudget / singleCartridgePrice);
// Get itemDbs max stack size for ammo - dont go above 100 (some mods mess around with stack sizes) // Get itemDbs max stack size for ammo - don't go above 100 (some mods mess around with stack sizes)
const stackMaxCount = Math.min(itemSelected._props.StackMaxSize, 100); const stackMaxCount = Math.min(itemSelected._props.StackMaxSize, 100);
// Choose smallest value between budget fitting size and stack max // Choose smallest value between budget fitting size and stack max

View File

@ -55,11 +55,7 @@ export class ItemHelper
*/ */
public isValidItem(tpl: string, invalidBaseTypes: string[] = null): boolean public isValidItem(tpl: string, invalidBaseTypes: string[] = null): boolean
{ {
if (invalidBaseTypes === null) const baseTypes = invalidBaseTypes || this.defaultInvalidBaseTypes;
{
invalidBaseTypes = this.defaultInvalidBaseTypes;
}
const itemDetails = this.getItem(tpl); const itemDetails = this.getItem(tpl);
if (!itemDetails[0]) if (!itemDetails[0])
@ -67,10 +63,9 @@ export class ItemHelper
return false; return false;
} }
// Is item valid
return !itemDetails[1]._props.QuestItem return !itemDetails[1]._props.QuestItem
&& itemDetails[1]._type === "Item" && itemDetails[1]._type === "Item"
&& !this.isOfBaseclasses(tpl, invalidBaseTypes) && baseTypes.every((x) => !this.isOfBaseclass(tpl, x))
&& this.getItemPrice(tpl) > 0 && this.getItemPrice(tpl) > 0
&& !this.itemFilterService.isItemBlacklisted(tpl); && !this.itemFilterService.isItemBlacklisted(tpl);
} }
@ -1063,20 +1058,16 @@ export class ItemHelper
minSizePercent = 0.25, minSizePercent = 0.25,
): void ): void
{ {
// no caliber defined, choose one at random let chosenCaliber = caliber || this.getRandomValidCaliber(magTemplate);
if (!caliber)
{
caliber = this.getRandomValidCaliber(magTemplate);
}
// Edge case for the Klin pp-9, it has a typo in its ammo caliber // Edge case for the Klin pp-9, it has a typo in its ammo caliber
if (caliber === "Caliber9x18PMM") if (chosenCaliber === "Caliber9x18PMM")
{ {
caliber = "Caliber9x18PM"; chosenCaliber = "Caliber9x18PM";
} }
// Chose a randomly weighted cartridge that fits // Chose a randomly weighted cartridge that fits
const cartridgeTpl = this.drawAmmoTpl(caliber, staticAmmoDist); const cartridgeTpl = this.drawAmmoTpl(chosenCaliber, staticAmmoDist);
this.fillMagazineWithCartridge(magazine, magTemplate, cartridgeTpl, minSizePercent); this.fillMagazineWithCartridge(magazine, magTemplate, cartridgeTpl, minSizePercent);
} }

View File

@ -83,18 +83,20 @@ export class RagfairSellHelper
const result: SellResult[] = []; const result: SellResult[] = [];
// Value can sometimes be NaN for whatever reason, default to base chance if that happens // Value can sometimes be NaN for whatever reason, default to base chance if that happens
const effectiveSellChance = Number.isNaN(sellChancePercent)
? this.ragfairConfig.sell.chance.base
: sellChancePercent;
if (Number.isNaN(sellChancePercent)) if (Number.isNaN(sellChancePercent))
{ {
this.logger.warning( this.logger.warning(
`Sell chance was not a number: ${sellChancePercent}, defaulting to ${this.ragfairConfig.sell.chance.base}%`, `Sell chance was not a number: ${sellChancePercent}, defaulting to ${this.ragfairConfig.sell.chance.base}%`,
); );
sellChancePercent = this.ragfairConfig.sell.chance.base;
} }
this.logger.debug(`Rolling to sell: ${itemSellCount} items (chance: ${sellChancePercent}%)`); this.logger.debug(`Rolling to sell: ${itemSellCount} items (chance: ${effectiveSellChance}%)`);
// No point rolling for a sale on a 0% chance item, exit early // No point rolling for a sale on a 0% chance item, exit early
if (sellChancePercent === 0) if (effectiveSellChance === 0)
{ {
return result; return result;
} }
@ -102,11 +104,11 @@ export class RagfairSellHelper
while (remainingCount > 0 && sellTime < endTime) while (remainingCount > 0 && sellTime < endTime)
{ {
const boughtAmount = this.randomUtil.getInt(1, remainingCount); const boughtAmount = this.randomUtil.getInt(1, remainingCount);
if (this.randomUtil.getChance100(sellChancePercent)) if (this.randomUtil.getChance100(effectiveSellChance))
{ {
// Passed roll check, item will be sold // Passed roll check, item will be sold
// Weight time to sell towards selling faster based on how cheap the item sold // Weight time to sell towards selling faster based on how cheap the item sold
const weighting = (100 - sellChancePercent) / 100; const weighting = (100 - effectiveSellChance) / 100;
let maximumTime = weighting * (this.ragfairConfig.sell.time.max * 60); let maximumTime = weighting * (this.ragfairConfig.sell.time.max * 60);
const minimumTime = this.ragfairConfig.sell.time.min * 60; const minimumTime = this.ragfairConfig.sell.time.min * 60;
if (maximumTime < minimumTime) if (maximumTime < minimumTime)