koishi-plugin-ggcevo-game 1.0.23 → 1.0.24

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
@@ -12,6 +12,8 @@ export interface Config {
12
12
  groupId: string[];
13
13
  checkInterval: number;
14
14
  dailyPKLimit: number;
15
+ sameOpponentLimit: boolean;
16
+ maxDailyBeChallenged: number;
15
17
  }
16
18
  export declare const Config: Schema<Config>;
17
19
  export declare const inject: {
@@ -31,6 +33,7 @@ declare module 'koishi' {
31
33
  ggcevo_blacklist: blacklist;
32
34
  ggcevo_achievements: Achievement;
33
35
  ggcevo_pk: PKRecord;
36
+ ggcevo_pk_logs: PKLog;
34
37
  }
35
38
  }
36
39
  export interface backpack {
@@ -116,4 +119,11 @@ export interface PKRecord {
116
119
  todayCount: number;
117
120
  lastPK: Date;
118
121
  }
122
+ interface PKLog {
123
+ id: number;
124
+ initiator_handle: string;
125
+ target_handle: string;
126
+ date: Date;
127
+ }
119
128
  export declare function apply(ctx: Context, config: Config): void;
129
+ export {};
package/lib/index.js CHANGED
@@ -39,7 +39,9 @@ var Config = import_koishi.Schema.object({
39
39
  admins: import_koishi.Schema.array(import_koishi.Schema.string()).description("管理员QQ号列表,支持配置多个").default([]).role("table"),
40
40
  groupId: import_koishi.Schema.array(import_koishi.Schema.string()).description("游戏大厅黑名单通知群组,例如 onebot:123456").default([]).role("table"),
41
41
  checkInterval: import_koishi.Schema.number().default(60).description("检查间隔(秒)"),
42
- dailyPKLimit: import_koishi.Schema.number().description("每人每天可发起PK次数").default(3)
42
+ dailyPKLimit: import_koishi.Schema.number().description("每人每天可发起PK次数").default(3),
43
+ sameOpponentLimit: import_koishi.Schema.boolean().description("是否开启同玩家每日单次PK限制").default(true),
44
+ maxDailyBeChallenged: import_koishi.Schema.number().description("每日最多被挑战次数(0=无限制)").default(5)
43
45
  });
44
46
  var inject = {
45
47
  required: ["database"]
@@ -177,6 +179,15 @@ function apply(ctx, config) {
177
179
  }, {
178
180
  primary: "handle"
179
181
  });
182
+ ctx.model.extend("ggcevo_pk_logs", {
183
+ id: "unsigned",
184
+ initiator_handle: "string",
185
+ target_handle: "string",
186
+ date: "timestamp"
187
+ }, {
188
+ primary: "id",
189
+ autoInc: true
190
+ });
180
191
  const initDefaultItems = {
181
192
  "咕咕币": { id: 1, type: "抽奖道具", description: "用于进行抽奖" },
182
193
  "兑换券": { id: 2, type: "兑换货币", description: "用于兑换赞助物品" },
@@ -1530,6 +1541,28 @@ ${achievementList.join("\n")}`;
1530
1541
  if (initiatorPK.todayCount >= config.dailyPKLimit) {
1531
1542
  return `今日挑战次数已用尽(${config.dailyPKLimit}次/日)`;
1532
1543
  }
1544
+ const nowChina = convertUTCtoChinaTime(/* @__PURE__ */ new Date());
1545
+ const todayStart = new Date(nowChina);
1546
+ todayStart.setUTCHours(0, 0, 0, 0);
1547
+ if (config.sameOpponentLimit) {
1548
+ const sameOpponentCount = await ctx.database.select("ggcevo_pk_logs").where({
1549
+ initiator_handle: initiatorHandle,
1550
+ target_handle: targetHandle,
1551
+ date: { $gte: todayStart }
1552
+ }).execute((row) => import_koishi.$.count(row.id));
1553
+ if (sameOpponentCount > 0) {
1554
+ return "您今天已经挑战过该玩家,请明天再试";
1555
+ }
1556
+ }
1557
+ if (config.maxDailyBeChallenged > 0) {
1558
+ const beChallengedCount = await ctx.database.select("ggcevo_pk_logs").where({
1559
+ target_handle: targetHandle,
1560
+ date: { $gte: todayStart }
1561
+ }).execute((row) => import_koishi.$.count(row.id));
1562
+ if (beChallengedCount >= config.maxDailyBeChallenged) {
1563
+ return `该玩家今日已被挑战太多次(最多${config.maxDailyBeChallenged}次)`;
1564
+ }
1565
+ }
1533
1566
  const [initiatorData, targetData] = await Promise.all([
1534
1567
  ctx.database.get("ggcevo_rank", initiatorHandle),
1535
1568
  ctx.database.get("ggcevo_rank", targetHandle)
@@ -1581,6 +1614,11 @@ ${achievementList.join("\n")}`;
1581
1614
  // 更新最后参与时间
1582
1615
  }
1583
1616
  ]);
1617
+ await ctx.database.create("ggcevo_pk_logs", {
1618
+ initiator_handle: initiatorHandle,
1619
+ target_handle: targetHandle,
1620
+ date: /* @__PURE__ */ new Date()
1621
+ });
1584
1622
  if (isWin) {
1585
1623
  await ctx.database.set("ggcevo_sign", targetHandle, { totalRewards: targetGold - goldTransfer });
1586
1624
  await ctx.database.set("ggcevo_sign", initiatorHandle, { totalRewards: initiatorGold + goldTransfer });
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.23",
4
+ "version": "1.0.24",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [