koishi-plugin-ggcevo-game 1.0.19 → 1.0.21
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 +50 -13
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1487,13 +1487,14 @@ ${achievementList.join("\n")}`;
|
|
|
1487
1487
|
ctx.logger.error("SC2大厅监控失败:", error);
|
|
1488
1488
|
}
|
|
1489
1489
|
}, config.checkInterval * 1e3);
|
|
1490
|
-
ctx.command("ggcevo/pk
|
|
1490
|
+
ctx.command("ggcevo/pk [user]", "发起玩家对战").alias("挑战").action(async (argv, user) => {
|
|
1491
1491
|
try {
|
|
1492
1492
|
const session = argv.session;
|
|
1493
|
+
if (!user) return "缺少参数,请使用@指定对战玩家";
|
|
1493
1494
|
const [profile] = await ctx.database.get("sc2arcade_player", { userId: session.userId });
|
|
1494
1495
|
if (!profile) return "您的 QQ 未绑定句柄。";
|
|
1495
1496
|
const parsedUser = import_koishi.h.parse(user)[0];
|
|
1496
|
-
if (!parsedUser || parsedUser.type !== "at") return "
|
|
1497
|
+
if (!parsedUser || parsedUser.type !== "at") return "格式错误,请使用@指定对战玩家";
|
|
1497
1498
|
const targetUserId = parsedUser.attrs.id;
|
|
1498
1499
|
let targetUsername = parsedUser.attrs.name || targetUserId;
|
|
1499
1500
|
const [targetprofile] = await ctx.database.get("sc2arcade_player", { userId: targetUsername });
|
|
@@ -1501,10 +1502,26 @@ ${achievementList.join("\n")}`;
|
|
|
1501
1502
|
const initiatorHandle = `${profile.regionId}-S2-${profile.realmId}-${profile.profileId}`;
|
|
1502
1503
|
const targetHandle = `${targetprofile.regionId}-S2-${targetprofile.realmId}-${targetprofile.profileId}`;
|
|
1503
1504
|
if (initiatorHandle === targetHandle) return "不能挑战自己哦~";
|
|
1504
|
-
let initiatorPK
|
|
1505
|
+
let initiatorPK = {
|
|
1506
|
+
handle: initiatorHandle,
|
|
1507
|
+
total: 0,
|
|
1508
|
+
wins: 0,
|
|
1509
|
+
todayCount: 0,
|
|
1510
|
+
lastPK: /* @__PURE__ */ new Date(0)
|
|
1511
|
+
// 明确初始化 lastPK
|
|
1512
|
+
};
|
|
1513
|
+
let targetPK = {
|
|
1514
|
+
handle: targetHandle,
|
|
1515
|
+
total: 0,
|
|
1516
|
+
wins: 0,
|
|
1517
|
+
todayCount: 0,
|
|
1518
|
+
lastPK: /* @__PURE__ */ new Date(0)
|
|
1519
|
+
};
|
|
1505
1520
|
await ctx.database.withTransaction(async () => {
|
|
1506
|
-
[
|
|
1507
|
-
|
|
1521
|
+
const [dbInitiator] = await ctx.database.get("ggcevo_pk", { handle: initiatorHandle });
|
|
1522
|
+
if (dbInitiator) Object.assign(initiatorPK, dbInitiator);
|
|
1523
|
+
const [dbTarget] = await ctx.database.get("ggcevo_pk", { handle: targetHandle });
|
|
1524
|
+
if (dbTarget) Object.assign(targetPK, dbTarget);
|
|
1508
1525
|
});
|
|
1509
1526
|
const now = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
|
|
1510
1527
|
if (!isSameDate(convertUTCtoChinaTime(initiatorPK.lastPK), now)) {
|
|
@@ -1517,6 +1534,12 @@ ${achievementList.join("\n")}`;
|
|
|
1517
1534
|
ctx.database.get("ggcevo_rank", initiatorHandle),
|
|
1518
1535
|
ctx.database.get("ggcevo_rank", targetHandle)
|
|
1519
1536
|
]);
|
|
1537
|
+
if (!initiatorData[0]?.rank) {
|
|
1538
|
+
return "发起者尚未有积分数据,无法发起挑战";
|
|
1539
|
+
}
|
|
1540
|
+
if (!targetData[0]?.rank) {
|
|
1541
|
+
return "对方尚未有积分数据,无法接受挑战";
|
|
1542
|
+
}
|
|
1520
1543
|
const [initiatorSign, targetSign] = await Promise.all([
|
|
1521
1544
|
ctx.database.get("ggcevo_sign", initiatorHandle),
|
|
1522
1545
|
ctx.database.get("ggcevo_sign", targetHandle)
|
|
@@ -1537,13 +1560,27 @@ ${achievementList.join("\n")}`;
|
|
|
1537
1560
|
return `${isWin ? "对方" : "你"}的金币不足以完成交易`;
|
|
1538
1561
|
}
|
|
1539
1562
|
await ctx.database.withTransaction(async () => {
|
|
1540
|
-
await ctx.database.upsert("ggcevo_pk", [
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1563
|
+
await ctx.database.upsert("ggcevo_pk", [
|
|
1564
|
+
// 发起者记录
|
|
1565
|
+
{
|
|
1566
|
+
handle: initiatorHandle,
|
|
1567
|
+
total: initiatorPK.total + 1,
|
|
1568
|
+
wins: isWin ? initiatorPK.wins + 1 : initiatorPK.wins,
|
|
1569
|
+
todayCount: initiatorPK.todayCount + 1,
|
|
1570
|
+
lastPK: /* @__PURE__ */ new Date()
|
|
1571
|
+
},
|
|
1572
|
+
// 应战者记录(新增部分)
|
|
1573
|
+
{
|
|
1574
|
+
handle: targetHandle,
|
|
1575
|
+
total: targetPK.total + 1,
|
|
1576
|
+
wins: !isWin ? targetPK.wins + 1 : targetPK.wins,
|
|
1577
|
+
// 应战者胜利时增加
|
|
1578
|
+
todayCount: targetPK.todayCount,
|
|
1579
|
+
// 不消耗应战者次数
|
|
1580
|
+
lastPK: /* @__PURE__ */ new Date()
|
|
1581
|
+
// 更新最后参与时间
|
|
1582
|
+
}
|
|
1583
|
+
]);
|
|
1547
1584
|
if (isWin) {
|
|
1548
1585
|
await ctx.database.set("ggcevo_sign", targetHandle, { totalRewards: targetGold - goldTransfer });
|
|
1549
1586
|
await ctx.database.set("ggcevo_sign", initiatorHandle, { totalRewards: initiatorGold + goldTransfer });
|
|
@@ -1559,7 +1596,7 @@ ${achievementList.join("\n")}`;
|
|
|
1559
1596
|
`📊 胜率预测:${winRate.toFixed(1)}%`,
|
|
1560
1597
|
`🎰 金币变动:${stealPercentage}%`
|
|
1561
1598
|
];
|
|
1562
|
-
isWin ? result.push(
|
|
1599
|
+
isWin ? result.push(`💰您获得 ${goldTransfer}`, `💸 对方损失 ${goldTransfer}`) : result.push(`💸您损失 ${goldTransfer}`, `💰 对方获得 ${goldTransfer}`);
|
|
1563
1600
|
result.push(`📅 剩余挑战次数:${config.dailyPKLimit - (initiatorPK.todayCount + 1)}`);
|
|
1564
1601
|
return result.join("\n");
|
|
1565
1602
|
} catch (error) {
|