Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETSCRIPT: level parameter of getActionRepGain is not really optional #257

Closed
bupjae opened this issue Dec 20, 2022 · 2 comments
Closed

Comments

@bupjae
Copy link

bupjae commented Dec 20, 2022

getActionRepGain: (ctx) => (_type, _name, _level) => {
const type = helpers.string(ctx, "type", _type);
const name = helpers.string(ctx, "name", _name);
const level = helpers.number(ctx, "level", _level);
checkBladeburnerAccess(ctx);
const action = getBladeburnerActionObject(ctx, type, name);
let rewardMultiplier;
if (level == null || isNaN(level)) {
rewardMultiplier = Math.pow(action.rewardFac, action.level - 1);
} else {
rewardMultiplier = Math.pow(action.rewardFac, level - 1);
}
return action.rankGain * rewardMultiplier * BitNodeMultipliers.BladeburnerRank;
},

On line 148, it seems the intention is make level parameter optional; if level parameter is not given, use current level of given action.

However, on line 144, if level parameter is not given properly, runtime error is thrown.

@Snarling
Copy link
Collaborator

Yeah that's my bad, pretty sure I messed that up. Checking the documentation verifies that level was supposed to be optional.

Moving the type verification for level after retrieving the action means we can select the correct default level, and we can also make rewardMultiplier a constant instead of needing to define it multiple ways based on a conditional.

   //...
   const action = getBladeburnerActionObject(ctx, type, name); 
   const level = _level === undefined ? action.level : helpers.number(ctx, "level", _level); 
   const rewardMultiplier = Math.pow(action.rewardFac, level - 1); 
   //...

@Snarling
Copy link
Collaborator

Snarling commented Jan 2, 2023

Fixed in 80d751e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants