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