koishi-plugin-smmcat-gensokyo 0.0.33 → 0.0.34

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 CHANGED
@@ -421,6 +421,40 @@ var getFreeList = /* @__PURE__ */ __name((arr) => {
421
421
  }
422
422
  return arrAdd;
423
423
  }, "getFreeList");
424
+ var AsyncOperationQueue = class {
425
+ static {
426
+ __name(this, "AsyncOperationQueue");
427
+ }
428
+ queue;
429
+ running;
430
+ constructor() {
431
+ this.queue = [];
432
+ this.running = false;
433
+ }
434
+ async add(operation) {
435
+ return new Promise((resolve, reject) => {
436
+ this.queue.push({ operation, resolve, reject });
437
+ if (!this.running) {
438
+ this.process();
439
+ }
440
+ });
441
+ }
442
+ async process() {
443
+ if (this.queue.length === 0) {
444
+ this.running = false;
445
+ return;
446
+ }
447
+ this.running = true;
448
+ const { operation, resolve, reject } = this.queue.shift();
449
+ try {
450
+ const result = await operation();
451
+ resolve(result);
452
+ } catch (error) {
453
+ reject(error);
454
+ }
455
+ this.process();
456
+ }
457
+ };
424
458
 
425
459
  // src/damage.ts
426
460
  var Damage = class {
@@ -3060,6 +3094,7 @@ function apply(ctx, config) {
3060
3094
  Monster.init(config, ctx);
3061
3095
  Props.init(config, ctx);
3062
3096
  });
3097
+ const Queue = new AsyncOperationQueue();
3063
3098
  ctx.command("幻想乡");
3064
3099
  ctx.command("幻想乡/移动.上").action(async ({ session }) => {
3065
3100
  console.log(session.userId.slice(0, 6) + "触发了上移动");
@@ -3224,18 +3259,18 @@ function apply(ctx, config) {
3224
3259
  await BattleData.createBattleByMonster(session, [selectMonster]);
3225
3260
  } else {
3226
3261
  const selectMonster = areaInfo.monster;
3227
- await BattleData.createBattleByMonster(session, selectMonster);
3262
+ await Queue.add(async () => await BattleData.createBattleByMonster(session, selectMonster));
3228
3263
  }
3229
3264
  });
3230
3265
  ctx.command("幻想乡/打怪攻击 <goal>").action(async ({ session }, goal) => {
3231
3266
  const userData = await User.getUserAttribute(session);
3232
3267
  if (!userData) return;
3233
- BattleData.play(session, "普攻", goal);
3268
+ await Queue.add(async () => BattleData.play(session, "普攻", goal));
3234
3269
  });
3235
3270
  ctx.command("幻想乡/打怪技能 <skill> <goal>").action(async ({ session }, skill, goal) => {
3236
3271
  const userData = await User.getUserAttribute(session);
3237
3272
  if (!userData) return;
3238
- BattleData.play(session, skill, goal);
3273
+ await Queue.add(async () => await BattleData.play(session, skill, goal));
3239
3274
  });
3240
3275
  ctx.command("幻想乡/打怪pk <goal>").action(async ({ session }, goal) => {
3241
3276
  const userData = await User.getUserAttribute(session);
@@ -3260,10 +3295,10 @@ function apply(ctx, config) {
3260
3295
  if (BattleData.isTeamByUserId(exist.userId)) {
3261
3296
  const teamItem = BattleData.teamListByUser(exist.userId);
3262
3297
  await session.send(`对方有组队,您将扮演攻击方与对方队伍进行战斗。`);
3263
- await BattleData.createBattleByUser(session, teamItem.map((item) => ({ userId: item.userId })));
3298
+ await Queue.add(async () => await BattleData.createBattleByUser(session, teamItem.map((item) => ({ userId: item.userId }))));
3264
3299
  } else {
3265
3300
  await session.send(`您将扮演攻击方与对方进行战斗。`);
3266
- await BattleData.createBattleByUser(session, [{ userId: exist.userId }]);
3301
+ await Queue.add(async () => await BattleData.createBattleByUser(session, [{ userId: exist.userId }]));
3267
3302
  }
3268
3303
  });
3269
3304
  ctx.command("幻想乡/道具使用 <props>").action(async ({ session }, props) => {
@@ -3376,7 +3411,7 @@ function apply(ctx, config) {
3376
3411
  await session.send(await ctx.puppeteer.render(html));
3377
3412
  });
3378
3413
  ctx.command("幻想乡/打怪逃跑").action(async ({ session }) => {
3379
- await BattleData.battleEscape(session);
3414
+ await Queue.add(async () => await BattleData.battleEscape(session));
3380
3415
  });
3381
3416
  }
3382
3417
  __name(apply, "apply");
package/lib/utlis.d.ts CHANGED
@@ -2,3 +2,10 @@ export declare const random: (min: number, max: number) => number;
2
2
  /** 血量可视化 */
3
3
  export declare const generateHealthDisplay: (current: number, total: number) => string;
4
4
  export declare const getFreeList: (arr: any[]) => any[];
5
+ export declare class AsyncOperationQueue {
6
+ queue: any[];
7
+ running: boolean;
8
+ constructor();
9
+ add(operation: any): Promise<unknown>;
10
+ process(): Promise<void>;
11
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gensokyo",
3
3
  "description": "名为《幻想乡》的文字冒险游戏",
4
- "version": "0.0.33",
4
+ "version": "0.0.34",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [