koishi-plugin-smmcat-gensokyo 0.0.23 → 0.0.25

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
@@ -111,12 +111,21 @@ type LastPlay = {
111
111
  isPK?: boolean;
112
112
  };
113
113
  };
114
+ type InvitationTemp = {
115
+ [keys: string]: {
116
+ time: number;
117
+ for: string;
118
+ playName: string;
119
+ seen: boolean;
120
+ };
121
+ };
114
122
  export declare const BattleData: {
115
123
  config: Config;
116
124
  ctx: Context;
117
125
  historyTemp: BattleHistory;
118
126
  lastPlay: LastPlay;
119
127
  teamTemp: TeamData;
128
+ invitationTemp: InvitationTemp;
120
129
  init(config: Config, ctx: Context): void;
121
130
  /** 玩家是否正在战斗 */
122
131
  isBattle(session: Session): boolean;
@@ -124,8 +133,19 @@ export declare const BattleData: {
124
133
  isBattleByUserId(userId: string): boolean;
125
134
  /** 玩家是否在队伍中 */
126
135
  isTeam(session: Session): boolean;
136
+ /** 玩家是否在队伍中 通过UserId */
127
137
  isTeamByUserId(userId: string): boolean;
128
138
  teamListByUser(userId: string): UserBaseAttribute[];
139
+ /** 创建队伍 */
140
+ creatTeam(session: Session): Promise<void>;
141
+ /** 邀请加入队伍 */
142
+ invitationTeam(session: Session, playName: string): Promise<void>;
143
+ /** 加入队伍 */
144
+ joinTeam(session: Session): Promise<void>;
145
+ /** 退出队伍 */
146
+ exitTeam(session: Session): Promise<void>;
147
+ /** 解散队伍 */
148
+ dissolveTeam(session: Session): Promise<void>;
129
149
  /** 创建战斗-与怪物 */
130
150
  createBattleByMonster(session: Session, goal: {
131
151
  name: string;
package/lib/index.js CHANGED
@@ -217,7 +217,7 @@ var GensokyoMap = {
217
217
  "野猪巢穴": {
218
218
  floor: 1,
219
219
  areaName: "野猪巢穴",
220
- type: "冒险区" /* 冒险区 */,
220
+ type: "BOSS区" /* BOSS区 */,
221
221
  needLv: 1,
222
222
  top: "绿野平原四",
223
223
  monster: [{ name: "蓬莱山辉夜", lv: 20 }]
@@ -1191,6 +1191,7 @@ var BattleData = {
1191
1191
  historyTemp: {},
1192
1192
  lastPlay: {},
1193
1193
  teamTemp: {},
1194
+ invitationTemp: {},
1194
1195
  init(config, ctx) {
1195
1196
  this.config = config;
1196
1197
  this.ctx = ctx;
@@ -1207,6 +1208,7 @@ var BattleData = {
1207
1208
  isTeam(session) {
1208
1209
  return !!BattleData.teamTemp[session.userId];
1209
1210
  },
1211
+ /** 玩家是否在队伍中 通过UserId */
1210
1212
  isTeamByUserId(userId) {
1211
1213
  return !!BattleData.teamTemp[userId];
1212
1214
  },
@@ -1224,6 +1226,109 @@ var BattleData = {
1224
1226
  });
1225
1227
  return teamList;
1226
1228
  },
1229
+ /** 创建队伍 */
1230
+ async creatTeam(session) {
1231
+ const { userId } = session;
1232
+ if (BattleData.isTeamByUserId(userId)) {
1233
+ await session.send(`${User.getUserName(userId)}:你已经加入了${BattleData.teamTemp[userId].for}的队伍,需要退出才可以重新创建!`);
1234
+ return;
1235
+ }
1236
+ BattleData.teamTemp[userId] = {
1237
+ for: userId,
1238
+ identity: "队长"
1239
+ };
1240
+ await session.send("创建队伍成功!发送 /队伍邀请 昵称 \n可对周围对应昵称玩家进行组队邀请!");
1241
+ },
1242
+ /** 邀请加入队伍 */
1243
+ async invitationTeam(session, playName) {
1244
+ const { userId } = session;
1245
+ if (!BattleData.isTeamByUserId(userId)) {
1246
+ await session.send(`你还没有创建队伍,请发送 /队伍创建 创建队伍吧!`);
1247
+ return;
1248
+ }
1249
+ const teamInfo = BattleData.teamTemp[userId];
1250
+ if (teamInfo.identity !== "队长") {
1251
+ await session.send(`你不是小队队长,无法邀请玩家加入!`);
1252
+ return;
1253
+ }
1254
+ const nearUser = GensokyoMap.nearbyPlayersByUserId(userId);
1255
+ const invitationUser = nearUser.find((item) => item.playName == playName);
1256
+ if (!invitationUser) {
1257
+ await session.send(`玩家${playName}不在你附近,邀请失败!`);
1258
+ return;
1259
+ }
1260
+ if (BattleData.isTeamByUserId(invitationUser.userId)) {
1261
+ await session.send(`对方已经组队,或者已经在队伍中!`);
1262
+ return;
1263
+ }
1264
+ BattleData.invitationTemp[invitationUser.userId] = {
1265
+ time: Date.now(),
1266
+ for: userId,
1267
+ playName: User.getUserName(userId),
1268
+ seen: false
1269
+ };
1270
+ await session.send(`已经发送邀请,等待TA的 /队伍加入 操作`);
1271
+ },
1272
+ /** 加入队伍 */
1273
+ async joinTeam(session) {
1274
+ const { userId } = session;
1275
+ if (!BattleData.invitationTemp[userId]) {
1276
+ await session.send("当前最后记录中无人邀请你加入队伍...");
1277
+ return;
1278
+ }
1279
+ if (BattleData.isTeamByUserId(userId)) {
1280
+ await session.send(`你已经在队伍中,无法再次加入,若需要加入请发送 /队伍退出`);
1281
+ return;
1282
+ }
1283
+ const invInfo = BattleData.invitationTemp[userId];
1284
+ if (Date.now() - invInfo.time > 36e5) {
1285
+ await session.send(`${invInfo.playName}的邀请队伍请求已超时!`);
1286
+ delete BattleData.invitationTemp[userId];
1287
+ return;
1288
+ }
1289
+ if (BattleData.teamListByUser(invInfo.for).length >= 4) {
1290
+ await session.send(`${invInfo.playName}的队伍人员已满!无法加入`);
1291
+ return;
1292
+ }
1293
+ BattleData.teamTemp[userId] = {
1294
+ for: invInfo.for,
1295
+ identity: "队员"
1296
+ };
1297
+ await session.send(`加入${invInfo.playName}的队伍成功!
1298
+ 若后续需要退出可发送 /队伍退出`);
1299
+ },
1300
+ /** 退出队伍 */
1301
+ async exitTeam(session) {
1302
+ const { userId } = session;
1303
+ if (!BattleData.isTeamByUserId(userId)) {
1304
+ await session.send("你还没有加入任何队伍!");
1305
+ return;
1306
+ }
1307
+ if (BattleData.teamTemp[userId].identity == "队长") {
1308
+ await session.send("你是小队队长,无法退出。若要解散队伍,请发送 /队伍解散");
1309
+ return;
1310
+ }
1311
+ const teamName = User.getUserName(BattleData.teamTemp[userId].for);
1312
+ delete BattleData.teamTemp[userId];
1313
+ await session.send(`退出${teamName}的小队成功!`);
1314
+ },
1315
+ /** 解散队伍 */
1316
+ async dissolveTeam(session) {
1317
+ const { userId } = session;
1318
+ if (!BattleData.isTeamByUserId(userId)) {
1319
+ await session.send("你还没有加入任何队伍!");
1320
+ return;
1321
+ }
1322
+ if (BattleData.teamTemp[userId].identity == "队员") {
1323
+ await session.send("你不是小队队长,无法解散。");
1324
+ return;
1325
+ }
1326
+ const team = BattleData.teamListByUser(userId);
1327
+ team.forEach((item) => {
1328
+ delete BattleData.teamTemp[item.userId];
1329
+ });
1330
+ await session.send("操作成功,已经解散你创建的小队。");
1331
+ },
1227
1332
  /** 创建战斗-与怪物 */
1228
1333
  async createBattleByMonster(session, goal) {
1229
1334
  if (BattleData.isBattle(session)) {
@@ -1947,6 +2052,10 @@ var User = {
1947
2052
  });
1948
2053
  User.userTempData = temp;
1949
2054
  },
2055
+ /** 获取玩家名字 */
2056
+ getUserName(userId) {
2057
+ return User.userTempData[userId].playName || null;
2058
+ },
1950
2059
  /** 获取角色基础属性 */
1951
2060
  async getUserAttribute(session) {
1952
2061
  if (!User.userTempData[session.userId]) {
@@ -2339,14 +2448,27 @@ function apply(ctx, config) {
2339
2448
  await session.send("您正在战斗中,无法移动!");
2340
2449
  return;
2341
2450
  }
2451
+ if (BattleData.isTeam(session) && BattleData.teamTemp[session.userId].identity !== "队长") {
2452
+ return `你在队伍中,请等待队长选择移动的位置!`;
2453
+ }
2342
2454
  if (User.isDie(session.userId)) {
2343
2455
  return `你已经阵亡,请发送 /补给 进行治疗。`;
2344
2456
  }
2345
2457
  GensokyoMap.move(session, "top" /* 上 */, async (val) => {
2458
+ if (BattleData.isTeam(session)) {
2459
+ const { userId } = session;
2460
+ Object.keys(BattleData.teamTemp).forEach((_userId) => {
2461
+ if (BattleData.teamTemp[userId].for == userId && userId !== _userId) {
2462
+ GensokyoMap.userCurrentLoal[_userId].areaName = GensokyoMap.userCurrentLoal[userId].areaName;
2463
+ GensokyoMap.userCurrentLoal[_userId].floor = GensokyoMap.userCurrentLoal[userId].floor;
2464
+ GensokyoMap.userCurrentLoal[_userId].moveing = false;
2465
+ }
2466
+ });
2467
+ }
2346
2468
  await session.send(GensokyoMap.userAreaTextFormat(userData.playName, val));
2347
2469
  if (val.map.type == "冒险区" /* 冒险区 */ && val.map.monster?.length) {
2348
2470
  if (random(0, 10) <= 2) {
2349
- const selectMonster = val.map.monster[random(0, val.map.monster.length)];
2471
+ const selectMonster = val.map.monster[random(0, val.map.monster.length - 1)];
2350
2472
  await session.send(`糟糕!你被 Lv.${selectMonster.lv} ${selectMonster.name} 发现,强制开启战斗!`);
2351
2473
  await BattleData.createBattleByMonster(session, [selectMonster]);
2352
2474
  }
@@ -2362,14 +2484,27 @@ function apply(ctx, config) {
2362
2484
  await session.send("您正在战斗中,无法移动!");
2363
2485
  return;
2364
2486
  }
2487
+ if (BattleData.isTeam(session) && BattleData.teamTemp[session.userId].identity !== "队长") {
2488
+ return `你在队伍中,请等待队长选择移动的位置!`;
2489
+ }
2365
2490
  if (User.isDie(session.userId)) {
2366
2491
  return `你已经阵亡,请发送 /补给 进行治疗。`;
2367
2492
  }
2368
2493
  GensokyoMap.move(session, "down" /* 下 */, async (val) => {
2494
+ if (BattleData.isTeam(session)) {
2495
+ const { userId } = session;
2496
+ Object.keys(BattleData.teamTemp).forEach((_userId) => {
2497
+ if (BattleData.teamTemp[userId].for == userId && userId !== _userId) {
2498
+ GensokyoMap.userCurrentLoal[_userId].areaName = GensokyoMap.userCurrentLoal[userId].areaName;
2499
+ GensokyoMap.userCurrentLoal[_userId].floor = GensokyoMap.userCurrentLoal[userId].floor;
2500
+ GensokyoMap.userCurrentLoal[_userId].moveing = false;
2501
+ }
2502
+ });
2503
+ }
2369
2504
  await session.send(GensokyoMap.userAreaTextFormat(userData.playName, val));
2370
2505
  if (val.map.type == "冒险区" /* 冒险区 */ && val.map.monster?.length) {
2371
2506
  if (random(0, 10) <= 2) {
2372
- const selectMonster = val.map.monster[random(0, val.map.monster.length)];
2507
+ const selectMonster = val.map.monster[random(0, val.map.monster.length - 1)];
2373
2508
  await session.send(`糟糕!你被 Lv.${selectMonster.lv} ${selectMonster.name} 发现,强制发生战斗!`);
2374
2509
  await BattleData.createBattleByMonster(session, [selectMonster]);
2375
2510
  }
@@ -2385,14 +2520,27 @@ function apply(ctx, config) {
2385
2520
  await session.send("您正在战斗中,无法移动!");
2386
2521
  return;
2387
2522
  }
2523
+ if (BattleData.isTeam(session) && BattleData.teamTemp[session.userId].identity !== "队长") {
2524
+ return `你在队伍中,请等待队长选择移动的位置!`;
2525
+ }
2388
2526
  if (User.isDie(session.userId)) {
2389
2527
  return `你已经阵亡,请发送 /补给 进行治疗。`;
2390
2528
  }
2391
2529
  GensokyoMap.move(session, "left" /* 左 */, async (val) => {
2530
+ if (BattleData.isTeam(session)) {
2531
+ const { userId } = session;
2532
+ Object.keys(BattleData.teamTemp).forEach((_userId) => {
2533
+ if (BattleData.teamTemp[userId].for == userId && userId !== _userId) {
2534
+ GensokyoMap.userCurrentLoal[_userId].areaName = GensokyoMap.userCurrentLoal[userId].areaName;
2535
+ GensokyoMap.userCurrentLoal[_userId].floor = GensokyoMap.userCurrentLoal[userId].floor;
2536
+ GensokyoMap.userCurrentLoal[_userId].moveing = false;
2537
+ }
2538
+ });
2539
+ }
2392
2540
  await session.send(GensokyoMap.userAreaTextFormat(userData.playName, val));
2393
2541
  if (val.map.type == "冒险区" /* 冒险区 */ && val.map.monster?.length) {
2394
2542
  if (random(0, 10) <= 2) {
2395
- const selectMonster = val.map.monster[random(0, val.map.monster.length)];
2543
+ const selectMonster = val.map.monster[random(0, val.map.monster.length - 1)];
2396
2544
  await session.send(`糟糕!你被 Lv.${selectMonster.lv} ${selectMonster.name} 发现,强制发生战斗!`);
2397
2545
  await BattleData.createBattleByMonster(session, [selectMonster]);
2398
2546
  }
@@ -2408,14 +2556,27 @@ function apply(ctx, config) {
2408
2556
  await session.send("您正在战斗中,无法移动!");
2409
2557
  return;
2410
2558
  }
2559
+ if (BattleData.isTeam(session) && BattleData.teamTemp[session.userId].identity !== "队长") {
2560
+ return `你在队伍中,请等待队长选择移动的位置!`;
2561
+ }
2411
2562
  if (User.isDie(session.userId)) {
2412
2563
  return `你已经阵亡,请发送 /补给 进行治疗。`;
2413
2564
  }
2414
2565
  GensokyoMap.move(session, "right" /* 右 */, async (val) => {
2566
+ if (BattleData.isTeam(session)) {
2567
+ const { userId } = session;
2568
+ Object.keys(BattleData.teamTemp).forEach((_userId) => {
2569
+ if (BattleData.teamTemp[userId].for == userId && userId !== _userId) {
2570
+ GensokyoMap.userCurrentLoal[_userId].areaName = GensokyoMap.userCurrentLoal[userId].areaName;
2571
+ GensokyoMap.userCurrentLoal[_userId].floor = GensokyoMap.userCurrentLoal[userId].floor;
2572
+ GensokyoMap.userCurrentLoal[_userId].moveing = false;
2573
+ }
2574
+ });
2575
+ }
2415
2576
  await session.send(GensokyoMap.userAreaTextFormat(userData.playName, val));
2416
2577
  if (val.map.type == "冒险区" /* 冒险区 */ && val.map.monster?.length) {
2417
2578
  if (random(0, 10) <= 2) {
2418
- const selectMonster = val.map.monster[random(0, val.map.monster.length)];
2579
+ const selectMonster = val.map.monster[random(0, val.map.monster.length - 1)];
2419
2580
  await session.send(`糟糕!你被 Lv.${selectMonster.lv} ${selectMonster.name} 发现,强制发生战斗!`);
2420
2581
  await BattleData.createBattleByMonster(session, [selectMonster]);
2421
2582
  }
@@ -2560,6 +2721,46 @@ function apply(ctx, config) {
2560
2721
  await User.setDatabaseUserAttribute(session.userId);
2561
2722
  return playName + `通过补给,目前已恢复HP和MP`;
2562
2723
  });
2724
+ ctx.command("幻想乡/队伍操作");
2725
+ ctx.command("队伍操作/队伍创建").action(async ({ session }) => {
2726
+ if (BattleData.isBattle(session)) {
2727
+ return `战斗中无法进行队伍创建操作!`;
2728
+ }
2729
+ await BattleData.creatTeam(session);
2730
+ });
2731
+ ctx.command("队伍操作/队伍信息").action(async ({ session }) => {
2732
+ const team = BattleData.teamListByUser(session.userId);
2733
+ if (!team.length) return `你还没有队伍...`;
2734
+ return `当前队伍信息如下:
2735
+ ` + team.map((item) => `lv.${item.lv} ${item.playName} [${BattleData.teamTemp[item.userId].identity}]`).join("\n");
2736
+ });
2737
+ ctx.command("队伍操作/队伍邀请 <playName>").action(async ({ session }, playName) => {
2738
+ if (BattleData.isBattle(session)) {
2739
+ return `战斗中无法进行队伍邀请操作!`;
2740
+ }
2741
+ if (!playName) {
2742
+ return `请选择需要邀请的玩家昵称。例如 /队伍邀请 夜夜酱`;
2743
+ }
2744
+ await BattleData.invitationTeam(session, playName);
2745
+ });
2746
+ ctx.command("队伍操作/队伍加入").action(async ({ session }) => {
2747
+ if (BattleData.isBattle(session)) {
2748
+ return `战斗中无法进行队伍创建操作!`;
2749
+ }
2750
+ await BattleData.joinTeam(session);
2751
+ });
2752
+ ctx.command("队伍操作/队伍退出").action(async ({ session }) => {
2753
+ if (BattleData.isBattle(session)) {
2754
+ return `战斗中无法进行队伍退出操作!`;
2755
+ }
2756
+ await BattleData.exitTeam(session);
2757
+ });
2758
+ ctx.command("队伍操作/队伍解散").action(async ({ session }) => {
2759
+ if (BattleData.isBattle(session)) {
2760
+ return `战斗中无法进行队伍解散操作!`;
2761
+ }
2762
+ await BattleData.dissolveTeam(session);
2763
+ });
2563
2764
  }
2564
2765
  __name(apply, "apply");
2565
2766
  // Annotate the CommonJS export names for ESM import in node:
package/lib/users.d.ts CHANGED
@@ -81,6 +81,8 @@ export declare const User: {
81
81
  ctx: Context;
82
82
  userTempData: UserTempData;
83
83
  init(config: Config, ctx: Context): Promise<void>;
84
+ /** 获取玩家名字 */
85
+ getUserName(userId: string): string;
84
86
  /** 获取角色基础属性 */
85
87
  getUserAttribute(session: Session): Promise<UserBaseAttribute>;
86
88
  /** 获取角色实际等级属性数据 */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gensokyo",
3
3
  "description": "名为《幻想乡》的文字冒险游戏",
4
- "version": "0.0.23",
4
+ "version": "0.0.25",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [