fix: gacha

This commit is contained in:
bietiaop 2024-07-09 17:20:11 +08:00
parent 550f7e0d99
commit 7455033ba6
4 changed files with 36 additions and 14 deletions

View file

@ -97,6 +97,7 @@ export class GachaLog extends ZZZPlugin {
return false; return false;
} }
await this.getPlayerInfo(); await this.getPlayerInfo();
await this.reply('正在查询抽卡记录,首次下载资源可能耗费一些时间,请稍等');
const data = await anaylizeGachaLog(uid); const data = await anaylizeGachaLog(uid);
if (!data) { if (!data) {
await this.reply('未查询到抽卡记录,请先发送抽卡链接'); await this.reply('未查询到抽卡记录,请先发送抽卡链接');

View file

@ -175,44 +175,50 @@ export async function anaylizeGachaLog(uid) {
const earliest = data[data.length - 1]; const earliest = data[data.length - 1];
const latest = data[0]; const latest = data[0];
const list = []; const list = [];
let lastFive = `${data.length}`; let lastFive = null;
let preIndex = 0; let preIndex = 0;
let luck = 0; let luck = 0;
data.forEach((item, i) => { let i = 0;
for (const item of data) {
await item.get_assets();
let isUp = true; let isUp = true;
if (item.rank_type === '4') { if (item.rank_type === '4') {
if (NORMAL_LIST.includes(item.name)) { if (NORMAL_LIST.includes(item.name)) {
isUp = false; isUp = false;
} }
if (lastFive === `${data.length}`) { if (lastFive === null) {
lastFive = `${i + 1}`; lastFive = i;
}
if (list.length > 0) {
list[list.length - 1]['totalCount'] = i - preIndex;
} }
list.push({ list.push({
...item, ...item,
rank_type_label: RANK_MAP[item.rank_type], rank_type_label: RANK_MAP[item.rank_type],
isUp: isUp, isUp: isUp,
totalCount: '-',
}); });
if (list.length > 0) {
list[list.length - 1]['totalCount'] = i - preIndex;
}
preIndex = i; preIndex = i;
} }
if (i === data.length - 1 && list.length > 0) { if (i === data.length - 1 && list.length > 0) {
list[list.length - 1]['totalCount'] = i - preIndex; list[list.length - 1]['totalCount'] = i - preIndex;
} }
}); i++;
}
const upCount = list.length; const upCount = list.length;
const totalCount = data.length; const totalCount = data.length;
const fiveStars = list.length; const fiveStars = list.length;
logger.mark('fiveStars', fiveStars);
logger.mark('totalCount', totalCount);
let timeRange = '还没有抽卡'; let timeRange = '还没有抽卡';
let avgFive = '-'; let avgFive = '-';
let avgUp = '-'; let avgUp = '-';
if (data.length > 0) { if (data.length > 0) {
timeRange = `${latest.time} ${earliest.time}`; timeRange = `${latest.time} ${earliest.time}`;
if (fiveStars > 0) avgFive = (totalCount / fiveStars).toFixed(1); if (fiveStars > 0)
if (upCount > 0) avgUp = (totalCount / upCount).toFixed(1); avgFive = ((totalCount - lastFive) / fiveStars).toFixed(1);
if (upCount > 0) avgUp = ((totalCount - lastFive) / upCount).toFixed(1);
}
if (!lastFive && fiveStars === 0) {
lastFive = '-';
} }
result.push({ result.push({
name, name,

View file

@ -1,3 +1,5 @@
import { getSquareAvatar, getSquareBangboo } from '../lib/download.js';
/** /**
* @class * @class
*/ */
@ -39,6 +41,8 @@ export class SingleGachaLog {
this.item_type = item_type; this.item_type = item_type;
this.rank_type = rank_type; this.rank_type = rank_type;
this.id = id; this.id = id;
this.square_icon = '';
} }
/** /**
@ -52,6 +56,17 @@ export class SingleGachaLog {
this.gacha_type === this.gacha_type this.gacha_type === this.gacha_type
); );
} }
async get_assets() {
if (this.item_type === '音擎') {
} else if (this.item_type === '邦布') {
const result = await getSquareBangboo(this.item_id);
this.square_icon = result;
} else {
const result = await getSquareAvatar(this.item_id);
this.square_icon = result;
}
}
} }
/** /**

View file

@ -40,9 +40,9 @@
<div class="item rankS {{inv.isUp && 'up'}}"> <div class="item rankS {{inv.isUp && 'up'}}">
<div class="rank rankS"></div> <div class="rank rankS"></div>
<div class="image"> <div class="image">
<img src="./images/role_square_avatar_1011.png" alt=""> <img src="{{inv.square_icon}}" alt="">
</div> </div>
<div class="count">{{inv?.totalCount || '-'}}抽</div> <div class="count">{{inv?.totalCount}}抽</div>
</div> </div>
{{/each}} {{/each}}
</div> </div>