mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Merge pull request #7064 from piousbox/shared-code-crit
shared-code-crit
This commit is contained in:
@@ -1,12 +1,6 @@
|
||||
module.exports = function(user, stat, chance) {
|
||||
var s;
|
||||
if (stat == null) {
|
||||
stat = 'str';
|
||||
}
|
||||
if (chance == null) {
|
||||
chance = .03;
|
||||
}
|
||||
s = user._statsComputed[stat];
|
||||
|
||||
module.exports = function crit (user, stat = 'str', chance = 0.03) {
|
||||
let s = user._statsComputed[stat];
|
||||
if (user.fns.predictableRandom() <= chance * (1 + s / 100)) {
|
||||
return 1.5 + 4 * s / (s + 200);
|
||||
} else {
|
||||
|
||||
@@ -11,7 +11,6 @@ const COMMON_FILES = [
|
||||
// @TODO remove these negations as the files are converted over.
|
||||
'!./common/script/content/index.js',
|
||||
'!./common/script/ops/reset.js',
|
||||
'!./common/script/fns/crit.js',
|
||||
'!./common/script/fns/randomDrop.js',
|
||||
'!./common/script/libs/countExists.js',
|
||||
'!./common/script/libs/encodeiCalLink.js',
|
||||
|
||||
17
test/common/fns/crit.test.js
Normal file
17
test/common/fns/crit.test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import crit from '../../../common/script/fns/crit';
|
||||
import {
|
||||
generateUser,
|
||||
} from '../../helpers/common.helper';
|
||||
|
||||
describe('crit', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
user = generateUser();
|
||||
});
|
||||
|
||||
it('computes', () => {
|
||||
let result = crit(user);
|
||||
expect(result).to.eql(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user