koishi-plugin-smmcat-gensokyo 0.0.32 → 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/battle.d.ts CHANGED
@@ -177,6 +177,10 @@ export declare const BattleData: {
177
177
  };
178
178
  /** 清理战场 */
179
179
  clearBattleData(session: Session): void;
180
+ /** 打怪逃跑 */
181
+ battleEscape(session: Session): Promise<void>;
182
+ /** 同步状态 */
183
+ aynchronize(agent: BattleAttribute): void;
180
184
  play(session: Session, atkType: string, select?: string): Promise<void>;
181
185
  /** 结算奖励 */
182
186
  settlement(tempData: {
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 {
@@ -1304,6 +1338,38 @@ MP:${item.mp}/${item.maxMp + item.gain.maxMp}`);
1304
1338
  }
1305
1339
  });
1306
1340
  },
1341
+ /** 打怪逃跑 */
1342
+ async battleEscape(session) {
1343
+ const currentBattle = BattleData.lastPlay[session.userId];
1344
+ if (currentBattle.isPK) {
1345
+ await session.send(`与玩家PK中途不能逃跑啊!`);
1346
+ return;
1347
+ }
1348
+ if (currentBattle.goal.some((item) => item.selfType == "BOSS" /* BOSS */)) {
1349
+ await session.send(`与BOSS对战的中途不能逃跑啊!`);
1350
+ return;
1351
+ }
1352
+ const allAgentList = [...currentBattle.goal, ...currentBattle.self];
1353
+ const losePrice = random(5, 10);
1354
+ const isTeam = BattleData.isTeam(session);
1355
+ for (const agent of allAgentList) {
1356
+ if (agent.type == "玩家") {
1357
+ BattleData.aynchronize(agent);
1358
+ await User.lostMonetary(agent.userId, losePrice);
1359
+ await User.setDatabaseUserAttribute(agent.userId);
1360
+ }
1361
+ }
1362
+ BattleData.clearBattleData(session);
1363
+ await session.send(isTeam ? `队伍在战斗中逃跑了,逃跑中均失去${losePrice}货币...` : `您在战斗中逃跑了。逃跑途中失去${losePrice}货币...`);
1364
+ },
1365
+ /** 同步状态 */
1366
+ aynchronize(agent) {
1367
+ User.userTempData[agent.userId].hp = agent.hp > 0 ? agent.hp : 0;
1368
+ User.userTempData[agent.userId].mp = agent.mp;
1369
+ if (User.userTempData[agent.userId].hp <= 0) {
1370
+ User.userTempData[agent.userId].isDie = true;
1371
+ }
1372
+ },
1307
1373
  async play(session, atkType, select) {
1308
1374
  if (!BattleData.isBattle(session)) {
1309
1375
  await session.send("您并没有任何参与战斗。");
@@ -2033,7 +2099,7 @@ ${Object.keys(UserOccDict).map((i) => `【${i}】:${UserOccDict[i].info}`).join(
2033
2099
  name: afterData.playName,
2034
2100
  lv: afterData.lv,
2035
2101
  maxHp: afterData.maxHp - beforData.maxHp,
2036
- maxMp: afterData.maxMp = beforData.maxMp,
2102
+ maxMp: afterData.maxMp - beforData.maxMp,
2037
2103
  atk: afterData.atk - beforData.atk,
2038
2104
  def: afterData.def - beforData.def
2039
2105
  };
@@ -2701,7 +2767,7 @@ ${belowUser.map((item) => {
2701
2767
  [!]存在商店:${data.map.shopName}` : "") + (data.map.npc ? `
2702
2768
  [!]存在npc:${data.map.npc.join("、")}` : "") + (data.map.monster ? `
2703
2769
  [!]存在野怪:${data.map.monster.map((i) => `lv.${i.lv} ${i.name}`).join("、")}` : "") + (liveUser.length ? `
2704
- [!]区域玩家:${liveUser.length > 3 ? liveUser.slice(0, 3).join("、") + `...等${liveUser.length}` : liveUser.join("、")}` : "");
2770
+ [!]区域玩家:${liveUser.length > 3 ? liveUser.slice(0, 3).join("、") + `...等${liveUser.length}名玩家` : liveUser.join("、")}` : "");
2705
2771
  return str + mapInfo;
2706
2772
  }
2707
2773
  };
@@ -3028,6 +3094,7 @@ function apply(ctx, config) {
3028
3094
  Monster.init(config, ctx);
3029
3095
  Props.init(config, ctx);
3030
3096
  });
3097
+ const Queue = new AsyncOperationQueue();
3031
3098
  ctx.command("幻想乡");
3032
3099
  ctx.command("幻想乡/移动.上").action(async ({ session }) => {
3033
3100
  console.log(session.userId.slice(0, 6) + "触发了上移动");
@@ -3192,18 +3259,18 @@ function apply(ctx, config) {
3192
3259
  await BattleData.createBattleByMonster(session, [selectMonster]);
3193
3260
  } else {
3194
3261
  const selectMonster = areaInfo.monster;
3195
- await BattleData.createBattleByMonster(session, selectMonster);
3262
+ await Queue.add(async () => await BattleData.createBattleByMonster(session, selectMonster));
3196
3263
  }
3197
3264
  });
3198
3265
  ctx.command("幻想乡/打怪攻击 <goal>").action(async ({ session }, goal) => {
3199
3266
  const userData = await User.getUserAttribute(session);
3200
3267
  if (!userData) return;
3201
- BattleData.play(session, "普攻", goal);
3268
+ await Queue.add(async () => BattleData.play(session, "普攻", goal));
3202
3269
  });
3203
3270
  ctx.command("幻想乡/打怪技能 <skill> <goal>").action(async ({ session }, skill, goal) => {
3204
3271
  const userData = await User.getUserAttribute(session);
3205
3272
  if (!userData) return;
3206
- BattleData.play(session, skill, goal);
3273
+ await Queue.add(async () => await BattleData.play(session, skill, goal));
3207
3274
  });
3208
3275
  ctx.command("幻想乡/打怪pk <goal>").action(async ({ session }, goal) => {
3209
3276
  const userData = await User.getUserAttribute(session);
@@ -3228,10 +3295,10 @@ function apply(ctx, config) {
3228
3295
  if (BattleData.isTeamByUserId(exist.userId)) {
3229
3296
  const teamItem = BattleData.teamListByUser(exist.userId);
3230
3297
  await session.send(`对方有组队,您将扮演攻击方与对方队伍进行战斗。`);
3231
- 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 }))));
3232
3299
  } else {
3233
3300
  await session.send(`您将扮演攻击方与对方进行战斗。`);
3234
- await BattleData.createBattleByUser(session, [{ userId: exist.userId }]);
3301
+ await Queue.add(async () => await BattleData.createBattleByUser(session, [{ userId: exist.userId }]));
3235
3302
  }
3236
3303
  });
3237
3304
  ctx.command("幻想乡/道具使用 <props>").action(async ({ session }, props) => {
@@ -3343,6 +3410,9 @@ function apply(ctx, config) {
3343
3410
  console.log(html);
3344
3411
  await session.send(await ctx.puppeteer.render(html));
3345
3412
  });
3413
+ ctx.command("幻想乡/打怪逃跑").action(async ({ session }) => {
3414
+ await Queue.add(async () => await BattleData.battleEscape(session));
3415
+ });
3346
3416
  }
3347
3417
  __name(apply, "apply");
3348
3418
  // Annotate the CommonJS export names for ESM import in node:
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.32",
4
+ "version": "0.0.34",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [