koishi-plugin-smmcat-gensokyo 0.0.33 → 0.0.35

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
@@ -405,13 +405,16 @@ var random = /* @__PURE__ */ __name((min, max) => {
405
405
  return Math.floor(Math.random() * (max - min + 1)) + min;
406
406
  }, "random");
407
407
  var generateHealthDisplay = /* @__PURE__ */ __name((current, total) => {
408
- const ratio = current / total;
409
408
  const displayLength = 10;
410
- const filledLength = Math.floor(ratio * displayLength);
409
+ const filledChar = "■";
410
+ const unfilledChar = "□";
411
+ const clampedCurrent = Math.max(0, Math.min(current, total));
412
+ const ratio = clampedCurrent / total;
413
+ const filledLength = Math.max(0, Math.min(Math.floor(ratio * displayLength), displayLength));
411
414
  const unfilledLength = displayLength - filledLength;
412
- const filled = "■".repeat(filledLength);
413
- const unfilled = "□".repeat(unfilledLength);
414
- return filled + unfilled;
415
+ const filled = filledChar.repeat(filledLength);
416
+ const unfilled = unfilledChar.repeat(unfilledLength);
417
+ return `${filled}${unfilled} (${current}/${total})`;
415
418
  }, "generateHealthDisplay");
416
419
  var getFreeList = /* @__PURE__ */ __name((arr) => {
417
420
  let arrAdd = [...arr];
@@ -421,6 +424,40 @@ var getFreeList = /* @__PURE__ */ __name((arr) => {
421
424
  }
422
425
  return arrAdd;
423
426
  }, "getFreeList");
427
+ var AsyncOperationQueue = class {
428
+ static {
429
+ __name(this, "AsyncOperationQueue");
430
+ }
431
+ queue;
432
+ running;
433
+ constructor() {
434
+ this.queue = [];
435
+ this.running = false;
436
+ }
437
+ async add(operation) {
438
+ return new Promise((resolve, reject) => {
439
+ this.queue.push({ operation, resolve, reject });
440
+ if (!this.running) {
441
+ this.process();
442
+ }
443
+ });
444
+ }
445
+ async process() {
446
+ if (this.queue.length === 0) {
447
+ this.running = false;
448
+ return;
449
+ }
450
+ this.running = true;
451
+ const { operation, resolve, reject } = this.queue.shift();
452
+ try {
453
+ const result = await operation();
454
+ resolve(result);
455
+ } catch (error) {
456
+ reject(error);
457
+ }
458
+ this.process();
459
+ }
460
+ };
424
461
 
425
462
  // src/damage.ts
426
463
  var Damage = class {
@@ -3060,6 +3097,7 @@ function apply(ctx, config) {
3060
3097
  Monster.init(config, ctx);
3061
3098
  Props.init(config, ctx);
3062
3099
  });
3100
+ const Queue = new AsyncOperationQueue();
3063
3101
  ctx.command("幻想乡");
3064
3102
  ctx.command("幻想乡/移动.上").action(async ({ session }) => {
3065
3103
  console.log(session.userId.slice(0, 6) + "触发了上移动");
@@ -3224,18 +3262,18 @@ function apply(ctx, config) {
3224
3262
  await BattleData.createBattleByMonster(session, [selectMonster]);
3225
3263
  } else {
3226
3264
  const selectMonster = areaInfo.monster;
3227
- await BattleData.createBattleByMonster(session, selectMonster);
3265
+ await Queue.add(async () => await BattleData.createBattleByMonster(session, selectMonster));
3228
3266
  }
3229
3267
  });
3230
3268
  ctx.command("幻想乡/打怪攻击 <goal>").action(async ({ session }, goal) => {
3231
3269
  const userData = await User.getUserAttribute(session);
3232
3270
  if (!userData) return;
3233
- BattleData.play(session, "普攻", goal);
3271
+ await Queue.add(async () => BattleData.play(session, "普攻", goal));
3234
3272
  });
3235
3273
  ctx.command("幻想乡/打怪技能 <skill> <goal>").action(async ({ session }, skill, goal) => {
3236
3274
  const userData = await User.getUserAttribute(session);
3237
3275
  if (!userData) return;
3238
- BattleData.play(session, skill, goal);
3276
+ await Queue.add(async () => await BattleData.play(session, skill, goal));
3239
3277
  });
3240
3278
  ctx.command("幻想乡/打怪pk <goal>").action(async ({ session }, goal) => {
3241
3279
  const userData = await User.getUserAttribute(session);
@@ -3260,10 +3298,10 @@ function apply(ctx, config) {
3260
3298
  if (BattleData.isTeamByUserId(exist.userId)) {
3261
3299
  const teamItem = BattleData.teamListByUser(exist.userId);
3262
3300
  await session.send(`对方有组队,您将扮演攻击方与对方队伍进行战斗。`);
3263
- await BattleData.createBattleByUser(session, teamItem.map((item) => ({ userId: item.userId })));
3301
+ await Queue.add(async () => await BattleData.createBattleByUser(session, teamItem.map((item) => ({ userId: item.userId }))));
3264
3302
  } else {
3265
3303
  await session.send(`您将扮演攻击方与对方进行战斗。`);
3266
- await BattleData.createBattleByUser(session, [{ userId: exist.userId }]);
3304
+ await Queue.add(async () => await BattleData.createBattleByUser(session, [{ userId: exist.userId }]));
3267
3305
  }
3268
3306
  });
3269
3307
  ctx.command("幻想乡/道具使用 <props>").action(async ({ session }, props) => {
@@ -3376,7 +3414,7 @@ function apply(ctx, config) {
3376
3414
  await session.send(await ctx.puppeteer.render(html));
3377
3415
  });
3378
3416
  ctx.command("幻想乡/打怪逃跑").action(async ({ session }) => {
3379
- await BattleData.battleEscape(session);
3417
+ await Queue.add(async () => await BattleData.battleEscape(session));
3380
3418
  });
3381
3419
  }
3382
3420
  __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.35",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [