koishi-plugin-xxck-1 0.3.7 → 0.3.8
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/index.js +29 -6
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -205,6 +205,23 @@ async function getNextId(ctx, table) {
|
|
|
205
205
|
return list.length ? list[0].id + 1 : 1;
|
|
206
206
|
}
|
|
207
207
|
__name(getNextId, "getNextId");
|
|
208
|
+
async function getShopRowsByDate(ctx, shopDate) {
|
|
209
|
+
const rows = await ctx.database.get("gacha_shop_daily", { shop_date: shopDate });
|
|
210
|
+
const merged = /* @__PURE__ */ new Map();
|
|
211
|
+
for (const row of rows) {
|
|
212
|
+
const key = String(row.card_id);
|
|
213
|
+
const exist = merged.get(key);
|
|
214
|
+
if (!exist) {
|
|
215
|
+
merged.set(key, { ...row });
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if ((row.server_bought ?? 0) > (exist.server_bought ?? 0)) {
|
|
219
|
+
exist.server_bought = row.server_bought ?? 0;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return Array.from(merged.values());
|
|
223
|
+
}
|
|
224
|
+
__name(getShopRowsByDate, "getShopRowsByDate");
|
|
208
225
|
function unescapeHtml(str) {
|
|
209
226
|
if (!str || typeof str !== "string") return "";
|
|
210
227
|
return str.replace(/&/gi, "&");
|
|
@@ -1027,7 +1044,7 @@ async function _do_upgrade(ctx, session, card_ids, signResetHour, signResetMinut
|
|
|
1027
1044
|
let total_cost = 0;
|
|
1028
1045
|
const shop_card_info = [];
|
|
1029
1046
|
const [shopCards, cardPool] = await Promise.all([
|
|
1030
|
-
ctx
|
|
1047
|
+
getShopRowsByDate(ctx, today),
|
|
1031
1048
|
ctx.database.get("gacha_card_pool", {})
|
|
1032
1049
|
]);
|
|
1033
1050
|
ctx.logger.info(`[升格] 当前店铺卡片:`, shopCards.map((s) => s.card_id));
|
|
@@ -1047,6 +1064,7 @@ async function _do_upgrade(ctx, session, card_ids, signResetHour, signResetMinut
|
|
|
1047
1064
|
}
|
|
1048
1065
|
for (let i = 0; i < num; i++) {
|
|
1049
1066
|
shop_card_info.push({
|
|
1067
|
+
id: shopCard.id,
|
|
1050
1068
|
card_id: shopCard.card_id,
|
|
1051
1069
|
card_name: cardInfo.card_name,
|
|
1052
1070
|
card_star: shopCard.card_star,
|
|
@@ -1089,14 +1107,17 @@ async function _do_upgrade(ctx, session, card_ids, signResetHour, signResetMinut
|
|
|
1089
1107
|
if (d > 0) disturbance_total += d;
|
|
1090
1108
|
}
|
|
1091
1109
|
}
|
|
1092
|
-
|
|
1110
|
+
const shopRow = {
|
|
1093
1111
|
shop_date: today,
|
|
1094
1112
|
card_id: card.card_id,
|
|
1095
1113
|
card_star: card.card_star,
|
|
1096
1114
|
price: card.price,
|
|
1097
1115
|
server_limit: card.server_limit,
|
|
1098
1116
|
server_bought: card.server_bought + 1
|
|
1099
|
-
}
|
|
1117
|
+
};
|
|
1118
|
+
await ctx.database.upsert("gacha_shop_daily", [
|
|
1119
|
+
card.id != null ? { id: card.id, ...shopRow } : { ...shopRow }
|
|
1120
|
+
]);
|
|
1100
1121
|
}
|
|
1101
1122
|
await ctx.database.upsert("gacha_user_draw_count", [{
|
|
1102
1123
|
qq,
|
|
@@ -1300,7 +1321,7 @@ async function _do_shop(ctx, session, signResetHour, signResetMinute) {
|
|
|
1300
1321
|
todayDate.setDate(todayDate.getDate() - 1);
|
|
1301
1322
|
}
|
|
1302
1323
|
const today = `${todayDate.getFullYear()}${String(todayDate.getMonth() + 1).padStart(2, "0")}${String(todayDate.getDate()).padStart(2, "0")}`;
|
|
1303
|
-
let todayShop = await ctx
|
|
1324
|
+
let todayShop = await getShopRowsByDate(ctx, today);
|
|
1304
1325
|
if (todayShop.length === 0) {
|
|
1305
1326
|
const [sevenStarCards, sixStarCards, fiveStarCards] = await Promise.all([
|
|
1306
1327
|
ctx.database.get("gacha_card_pool", { card_star: 7 }),
|
|
@@ -1313,7 +1334,9 @@ async function _do_shop(ctx, session, signResetHour, signResetMinute) {
|
|
|
1313
1334
|
const selected7 = sevenStarCards.sort(() => Math.random() - 0.5).slice(0, 4);
|
|
1314
1335
|
const selected6 = sixStarCards.sort(() => Math.random() - 0.5).slice(0, 6);
|
|
1315
1336
|
const selected5 = fiveStarCards.sort(() => Math.random() - 0.5).slice(0, 10);
|
|
1316
|
-
const allCards =
|
|
1337
|
+
const allCards = Array.from(
|
|
1338
|
+
new Map([...selected7, ...selected6, ...selected5].map((c) => [String(c.card_id), c])).values()
|
|
1339
|
+
);
|
|
1317
1340
|
const SHOP_PRICE_BASE = { 7: 800, 6: 200, 5: 20 };
|
|
1318
1341
|
const SHOP_PRICE_RANGE = { 7: 80, 6: 30, 5: 0 };
|
|
1319
1342
|
for (const card of allCards) {
|
|
@@ -1339,7 +1362,7 @@ async function _do_shop(ctx, session, signResetHour, signResetMinute) {
|
|
|
1339
1362
|
});
|
|
1340
1363
|
}
|
|
1341
1364
|
}
|
|
1342
|
-
todayShop = await ctx
|
|
1365
|
+
todayShop = await getShopRowsByDate(ctx, today);
|
|
1343
1366
|
}
|
|
1344
1367
|
const pool = await ctx.database.get("gacha_card_pool", {});
|
|
1345
1368
|
const poolMap = new Map(pool.map((p) => [p.card_id, p]));
|