Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"items": [ | ||
{ | ||
"title": "刷题", | ||
"detail": [ | ||
"一遍过样例", | ||
null | ||
] | ||
}, | ||
{ | ||
"title": "装弱", | ||
"detail": [ | ||
"我好菜啊", | ||
"你太强了" | ||
] | ||
}, | ||
{ | ||
"title": { | ||
"boy": "搞基", | ||
"girl": "搞姬" | ||
}, | ||
"detail": [ | ||
"爱上学习", | ||
"会被掰弯" | ||
] | ||
}, | ||
{ | ||
"title": "直播写代码", | ||
"detail": [ | ||
"月入百万", | ||
"CE, RE and T,身败名裂" | ||
] | ||
}, | ||
{ | ||
"title": "学数论", | ||
"detail": [ | ||
"思维敏捷", | ||
"咋看都不会" | ||
] | ||
}, | ||
{ | ||
"title": "参加模拟赛", | ||
"detail": [ | ||
"AK 虐场", | ||
"爆零" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
let Random = require('random-js'); | ||
|
||
let crc32 = require('buffer-crc32'); | ||
let hash = x => crc32.unsigned(Buffer(x)); | ||
|
||
let config = require('../divine.json'); | ||
|
||
/* | ||
name: Used for the random seed | ||
sex: 1 for boys, -1 for girls, 0 for others | ||
*/ | ||
module.exports = (name, sex) => { | ||
if (sex == 1) sex = 'boy'; | ||
else if (sex == -1) sex = 'girl'; | ||
|
||
let res = { | ||
fortune: undefined, | ||
good: [], | ||
bad: [] | ||
}; | ||
|
||
let date = new Date(); | ||
let h = hash(name + hash(date.getFullYear().toString() + date.getMonth().toString() + date.getDate().toString())); | ||
let random = new Random(Random.engines.mt19937().seed(h)); | ||
|
||
let x = random.integer(1, 100); | ||
if (x <= 25) res.fortune = '大吉'; | ||
else if (x <= 50) res.fortune = '大凶'; | ||
else if (x <= 60) res.fortune = '中平'; | ||
else if (x <= 70) res.fortune = '小吉'; | ||
else if (x <= 80) res.fortune = '小凶'; | ||
else if (x <= 90) res.fortune = '吉'; | ||
else res.fortune = '凶'; | ||
|
||
let items = Array.from(config.items); | ||
function generate(type) { | ||
while (1) { | ||
let id = random.integer(0, items.length - 1); | ||
|
||
if (!items[id]) continue; | ||
|
||
let x = Object.assign({}, items[id]); | ||
if (typeof x.title === 'object') { | ||
if (x.title[sex]) x.title = x.title[sex]; | ||
else continue; | ||
} | ||
|
||
if (!x.detail[type]) continue; | ||
|
||
x.detail = x.detail[type]; | ||
|
||
if (typeof x.detail === 'object') { | ||
if (x.detail[sex]) x.detail = x.detail[sex]; | ||
else continue; | ||
} | ||
|
||
items[id] = null; | ||
|
||
return x; | ||
} | ||
} | ||
|
||
if (res.fortune != '大凶') { | ||
res.good[0] = generate(0); | ||
res.good[1] = generate(0); | ||
} | ||
|
||
if (res.fortune != '大吉') { | ||
res.bad[0] = generate(1); | ||
res.bad[1] = generate(1); | ||
} | ||
|
||
return res; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters