koishi-plugin-ggcevo-game 1.0.27 → 1.1.1

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.d.ts CHANGED
@@ -118,6 +118,8 @@ export interface PKRecord {
118
118
  wins: number;
119
119
  todayCount: number;
120
120
  lastPK: Date;
121
+ enable: boolean;
122
+ lastToggle: Date;
121
123
  }
122
124
  interface PKLog {
123
125
  id: number;
package/lib/index.js CHANGED
@@ -175,7 +175,15 @@ function apply(ctx, config) {
175
175
  total: "unsigned",
176
176
  wins: "unsigned",
177
177
  todayCount: "unsigned",
178
- lastPK: "timestamp"
178
+ lastPK: "timestamp",
179
+ enable: {
180
+ // 新增字段
181
+ type: "boolean",
182
+ initial: true
183
+ // 默认开启
184
+ },
185
+ lastToggle: "timestamp"
186
+ // 新增字段
179
187
  }, {
180
188
  primary: "handle"
181
189
  });
@@ -1518,15 +1526,23 @@ ${achievementList.join("\n")}`;
1518
1526
  total: 0,
1519
1527
  wins: 0,
1520
1528
  todayCount: 0,
1521
- lastPK: /* @__PURE__ */ new Date(0)
1529
+ lastPK: /* @__PURE__ */ new Date(0),
1522
1530
  // 明确初始化 lastPK
1531
+ enable: true,
1532
+ // 新增默认值
1533
+ lastToggle: /* @__PURE__ */ new Date(0)
1534
+ // 新增默认值
1523
1535
  };
1524
1536
  let targetPK = {
1525
1537
  handle: targetHandle,
1526
1538
  total: 0,
1527
1539
  wins: 0,
1528
1540
  todayCount: 0,
1529
- lastPK: /* @__PURE__ */ new Date(0)
1541
+ lastPK: /* @__PURE__ */ new Date(0),
1542
+ enable: true,
1543
+ // 新增默认值
1544
+ lastToggle: /* @__PURE__ */ new Date(0)
1545
+ // 新增默认值
1530
1546
  };
1531
1547
  await ctx.database.withTransaction(async () => {
1532
1548
  const [dbInitiator] = await ctx.database.get("ggcevo_pk", { handle: initiatorHandle });
@@ -1534,6 +1550,12 @@ ${achievementList.join("\n")}`;
1534
1550
  const [dbTarget] = await ctx.database.get("ggcevo_pk", { handle: targetHandle });
1535
1551
  if (dbTarget) Object.assign(targetPK, dbTarget);
1536
1552
  });
1553
+ if (!initiatorPK.enable) {
1554
+ return "您已关闭PK功能,无法发起挑战";
1555
+ }
1556
+ if (!targetPK.enable) {
1557
+ return "对方已关闭PK功能,无法接受挑战";
1558
+ }
1537
1559
  const now = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1538
1560
  if (!isSameDate(convertUTCtoChinaTime(initiatorPK.lastPK), now)) {
1539
1561
  initiatorPK.todayCount = 0;
@@ -1544,11 +1566,12 @@ ${achievementList.join("\n")}`;
1544
1566
  const nowChina = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1545
1567
  const todayStart = new Date(nowChina);
1546
1568
  todayStart.setUTCHours(0, 0, 0, 0);
1569
+ const adjustedTime = new Date(todayStart.getTime() - 8 * 60 * 60 * 1e3);
1547
1570
  if (config.sameOpponentLimit) {
1548
1571
  const sameOpponentCount = await ctx.database.select("ggcevo_pk_logs").where({
1549
1572
  initiator_handle: initiatorHandle,
1550
1573
  target_handle: targetHandle,
1551
- date: { $gte: todayStart }
1574
+ date: { $gte: adjustedTime }
1552
1575
  }).execute((row) => import_koishi.$.count(row.id));
1553
1576
  if (sameOpponentCount > 0) {
1554
1577
  return "您今天已经挑战过该玩家,请明天再试";
@@ -1557,12 +1580,19 @@ ${achievementList.join("\n")}`;
1557
1580
  if (config.maxDailyBeChallenged > 0) {
1558
1581
  const beChallengedCount = await ctx.database.select("ggcevo_pk_logs").where({
1559
1582
  target_handle: targetHandle,
1560
- date: { $gte: todayStart }
1583
+ date: { $gte: adjustedTime }
1561
1584
  }).execute((row) => import_koishi.$.count(row.id));
1562
1585
  if (beChallengedCount >= config.maxDailyBeChallenged) {
1563
1586
  return `该玩家今日已被挑战太多次(最多${config.maxDailyBeChallenged}次)`;
1564
1587
  }
1565
1588
  }
1589
+ const [finalInitiator, finalTarget] = await Promise.all([
1590
+ ctx.database.get("ggcevo_pk", initiatorHandle),
1591
+ ctx.database.get("ggcevo_pk", targetHandle)
1592
+ ]);
1593
+ if (!finalInitiator[0]?.enable || !finalTarget[0]?.enable) {
1594
+ return "对战状态已发生变化,请重新发起挑战";
1595
+ }
1566
1596
  const [initiatorData, targetData] = await Promise.all([
1567
1597
  ctx.database.get("ggcevo_rank", initiatorHandle),
1568
1598
  ctx.database.get("ggcevo_rank", targetHandle)
@@ -1600,7 +1630,11 @@ ${achievementList.join("\n")}`;
1600
1630
  total: initiatorPK.total + 1,
1601
1631
  wins: isWin ? initiatorPK.wins + 1 : initiatorPK.wins,
1602
1632
  todayCount: initiatorPK.todayCount + 1,
1603
- lastPK: /* @__PURE__ */ new Date()
1633
+ lastPK: /* @__PURE__ */ new Date(),
1634
+ enable: initiatorPK.enable,
1635
+ // 包含新字段
1636
+ lastToggle: initiatorPK.lastToggle
1637
+ // 包含新字段
1604
1638
  },
1605
1639
  // 应战者记录(新增部分)
1606
1640
  {
@@ -1610,8 +1644,12 @@ ${achievementList.join("\n")}`;
1610
1644
  // 应战者胜利时增加
1611
1645
  todayCount: targetPK.todayCount,
1612
1646
  // 不消耗应战者次数
1613
- lastPK: targetPK.lastPK
1647
+ lastPK: targetPK.lastPK,
1614
1648
  // 保留原有时间不更新
1649
+ enable: targetPK.enable,
1650
+ // 包含新字段
1651
+ lastToggle: targetPK.lastToggle
1652
+ // 包含新字段
1615
1653
  }
1616
1654
  ]);
1617
1655
  await ctx.database.create("ggcevo_pk_logs", {
@@ -1642,6 +1680,52 @@ ${achievementList.join("\n")}`;
1642
1680
  return "对战功能暂时不可用,请稍后重试";
1643
1681
  }
1644
1682
  });
1683
+ ctx.command("ggcevo/切换pk状态", "切换玩家对战状态").action(async ({ session }) => {
1684
+ const [profile] = await ctx.database.get("sc2arcade_player", { userId: session.userId });
1685
+ if (!profile) return "您的 QQ 未绑定句柄";
1686
+ const handle = `${profile.regionId}-S2-${profile.realmId}-${profile.profileId}`;
1687
+ const [pkRecord] = await ctx.database.get("ggcevo_pk", { handle }) || [null];
1688
+ const currentState = pkRecord?.enable ?? true;
1689
+ const lastToggle = pkRecord?.lastToggle ?? /* @__PURE__ */ new Date(0);
1690
+ if (!pkRecord) {
1691
+ await ctx.database.create("ggcevo_pk", {
1692
+ handle,
1693
+ total: 0,
1694
+ wins: 0,
1695
+ todayCount: 0,
1696
+ lastPK: /* @__PURE__ */ new Date(0),
1697
+ enable: true,
1698
+ // 默认初始状态为开启
1699
+ lastToggle: /* @__PURE__ */ new Date(0)
1700
+ });
1701
+ }
1702
+ const now = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1703
+ const lastToggleTime = convertUTCtoChinaTime(lastToggle);
1704
+ const diffDays = Math.floor((now.getTime() - lastToggleTime.getTime()) / (1e3 * 3600 * 24));
1705
+ if (diffDays < 3 && lastToggleTime.getTime() !== 0) {
1706
+ const remaining = 3 - diffDays;
1707
+ return `状态切换冷却中,${remaining}天后再试(下次可切换时间:${new Date(lastToggle.getTime() + 3 * 864e5).toLocaleDateString("zh-CN")})`;
1708
+ }
1709
+ const action = currentState ? "关闭" : "开启";
1710
+ await session.send(`您当前的PK状态为【${currentState ? "开启" : "关闭"}】,确认要${action}吗?(30秒内回复“是”确认)`);
1711
+ const confirm = await session.prompt(3e4);
1712
+ if (confirm !== "是") return "已取消操作";
1713
+ await ctx.database.upsert("ggcevo_pk", [{
1714
+ handle,
1715
+ enable: !currentState,
1716
+ lastToggle: /* @__PURE__ */ new Date(),
1717
+ // 保持其他字段不变
1718
+ total: pkRecord?.total || 0,
1719
+ wins: pkRecord?.wins || 0,
1720
+ todayCount: pkRecord?.todayCount || 0,
1721
+ lastPK: pkRecord?.lastPK || /* @__PURE__ */ new Date(0)
1722
+ }], ["handle"]);
1723
+ return `PK状态已${!currentState ? "开启" : "关闭"},下次可切换时间:${new Date(Date.now() + 3 * 864e5).toLocaleDateString("zh-CN", {
1724
+ year: "numeric",
1725
+ month: "2-digit",
1726
+ day: "2-digit"
1727
+ })}`;
1728
+ });
1645
1729
  }
1646
1730
  __name(apply, "apply");
1647
1731
  function simpleDraw() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ggcevo-game",
3
3
  "description": "星际争霸2游戏大厅咕咕虫-Evo地图专属插件",
4
- "version": "1.0.27",
4
+ "version": "1.1.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [