koishi-plugin-jrys-plus 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/roll.d.ts +2 -2
- package/lib/roll.js +11 -1
- package/lib/templates/fortune.html +2 -2
- package/package.json +1 -1
package/lib/roll.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export declare class Jrys {
|
|
|
2
2
|
constructor();
|
|
3
3
|
seededRandom(seed: number): number;
|
|
4
4
|
/** 同一天同一用户运势值固定(0~maxRange) */
|
|
5
|
-
getFortune(uid: number, maxRange?: number): Promise<number>;
|
|
5
|
+
getFortune(uid: number | string, maxRange?: number): Promise<number>;
|
|
6
6
|
/** 抽 4 个不重复的黄历事件 */
|
|
7
|
-
getRandomObjects(jsonObject: Array<any>, uid: number): Promise<Array<any>>;
|
|
7
|
+
getRandomObjects(jsonObject: Array<any>, uid: number | string): Promise<Array<any>>;
|
|
8
8
|
}
|
package/lib/roll.js
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
// 每日运势值、随机黄历事件
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Jrys = void 0;
|
|
5
|
+
/** 将任意字符串/数字转为稳定的正整数 hash */
|
|
6
|
+
function hashUID(uid) {
|
|
7
|
+
const str = String(uid);
|
|
8
|
+
let hash = 5381;
|
|
9
|
+
for (let i = 0; i < str.length; i++) {
|
|
10
|
+
hash = ((hash << 5) + hash) ^ str.charCodeAt(i);
|
|
11
|
+
hash = hash >>> 0; // 转为无符号 32 位
|
|
12
|
+
}
|
|
13
|
+
return hash;
|
|
14
|
+
}
|
|
5
15
|
class Jrys {
|
|
6
16
|
constructor() { }
|
|
7
17
|
seededRandom(seed) {
|
|
@@ -11,7 +21,7 @@ class Jrys {
|
|
|
11
21
|
/** 同一天同一用户运势值固定(0~maxRange) */
|
|
12
22
|
async getFortune(uid, maxRange = 100) {
|
|
13
23
|
const etime = new Date().setHours(0, 0, 0, 0);
|
|
14
|
-
const todaySeed = (
|
|
24
|
+
const todaySeed = (hashUID(uid) ^ etime) % 1000000001;
|
|
15
25
|
return Math.floor(this.seededRandom(todaySeed) * maxRange);
|
|
16
26
|
}
|
|
17
27
|
/** 抽 4 个不重复的黄历事件 */
|
|
@@ -159,8 +159,8 @@
|
|
|
159
159
|
<script>
|
|
160
160
|
(function() {
|
|
161
161
|
var luck = {{LUCK}};
|
|
162
|
-
// 运势 0~
|
|
163
|
-
var starCount = Math.
|
|
162
|
+
// 运势 0~99 均匀映射为 1~10 颗星(每档 10%)
|
|
163
|
+
var starCount = Math.floor(luck / 10) + 1;
|
|
164
164
|
// 十种彩色
|
|
165
165
|
var colors = [
|
|
166
166
|
'#ff4757', '#ff6b81', '#ffa502', '#eccc68',
|