koishi-plugin-smmcat-gensokyo 0.0.18 → 0.0.20

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.
Files changed (2) hide show
  1. package/lib/index.js +166 -162
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -444,168 +444,6 @@ var userBenchmark = {
444
444
  }
445
445
  };
446
446
 
447
- // src/data/initProps.ts
448
- var propsData = {
449
- "红药": {
450
- name: "红药",
451
- type: "消耗类" /* 消耗类 */,
452
- info: "回复自身20HP",
453
- price: 10,
454
- fn: /* @__PURE__ */ __name(async function(session) {
455
- User.giveHPMP(session.userId, { hp: 20 }, async (val) => {
456
- if (val.err) {
457
- await session.send(val.err);
458
- return;
459
- }
460
- const msg = `回复成功,玩家当前血量:${val.currentHP}`;
461
- await session.send(msg);
462
- });
463
- }, "fn")
464
- },
465
- "蓝药": {
466
- name: "蓝药",
467
- type: "消耗类" /* 消耗类 */,
468
- info: "回复自身20MP",
469
- price: 10,
470
- fn: /* @__PURE__ */ __name(async function(session) {
471
- User.giveHPMP(session.userId, { mp: 20 }, async (val) => {
472
- if (val.err) {
473
- await session.send(val.err);
474
- return;
475
- }
476
- const msg = `回复成功,玩家当前蓝量:${val.currentMP}`;
477
- await session.send(msg);
478
- });
479
- }, "fn")
480
- },
481
- "初级万能药": {
482
- name: "初级万能药",
483
- type: "消耗类" /* 消耗类 */,
484
- info: "回复自身20MP和20HP",
485
- price: 20,
486
- fn: /* @__PURE__ */ __name(async function(session) {
487
- User.giveHPMP(session.userId, { hp: 20, mp: 20 }, async (val) => {
488
- if (val.err) {
489
- await session.send(val.err);
490
- return;
491
- }
492
- const msg = `回复成功,玩家当前血量:${val.currentHP}、蓝量:${val.currentMP}`;
493
- await session.send(msg);
494
- });
495
- }, "fn")
496
- },
497
- "初级复活卷轴": {
498
- name: "初级复活卷轴",
499
- type: "消耗类" /* 消耗类 */,
500
- info: "复活玩家,复活时保留 20% 血量。(该道具使用完需要冷却 6 分钟)",
501
- price: 10,
502
- cooling: 3600,
503
- fn: /* @__PURE__ */ __name(async function(session) {
504
- if (!User.isDie(session.userId)) {
505
- session.send(`啊哈...你还没有阵亡,使用失败!`);
506
- return { err: true };
507
- }
508
- const { maxHp } = User.getUserAttributeByUserId(session.userId);
509
- User.giveLife(session.userId, Math.floor(maxHp * 0.2), async (val) => {
510
- await session.send(`复活成功,当前血量:${val.currentHP}`);
511
- });
512
- }, "fn")
513
- }
514
- };
515
-
516
- // src/props.ts
517
- var Props = {
518
- config: {},
519
- ctx: {},
520
- userPorpsTemp: {},
521
- async init(config, ctx) {
522
- Props.config = config;
523
- Props.ctx = ctx;
524
- ctx.database.extend("smm_gensokyo_user_props", {
525
- userId: "string",
526
- props: "json"
527
- }, {
528
- primary: "userId",
529
- autoInc: false
530
- });
531
- const temp = {};
532
- const propsList = await ctx.database.get("smm_gensokyo_user_props", {});
533
- propsList.forEach((item) => {
534
- temp[item.userId] = item.props;
535
- });
536
- Props.userPorpsTemp = temp;
537
- },
538
- /** 创建本地数据 */
539
- async initUserPropsData(userId) {
540
- if (!Props.userPorpsTemp[userId]) {
541
- Props.userPorpsTemp[userId] = {};
542
- const temp = {
543
- userId,
544
- props: {}
545
- };
546
- await Props.ctx.database.create("smm_gensokyo_user_props", temp);
547
- }
548
- },
549
- /** 获取持有道具信息 */
550
- async getPropsDataByUserId(userId) {
551
- await Props.initUserPropsData(userId);
552
- const userProps = Props.userPorpsTemp[userId];
553
- const msgList = Object.keys(userProps).map((item) => {
554
- return `${userProps[item].name}:${userProps[item].value}个`;
555
- });
556
- return msgList.length ? `当前您持有如下道具:
557
-
558
- ` + msgList.join("\n") : "您没有任何道具...";
559
- },
560
- /** 更新本地数据库对应数据 */
561
- async setDatabasePropsData(userId) {
562
- const propsData2 = Props.userPorpsTemp[userId];
563
- if (propsData2) {
564
- const temp = {
565
- props: propsData2
566
- };
567
- await Props.ctx.database.set("smm_gensokyo_user_props", { userId }, temp);
568
- }
569
- },
570
- /** 使用指定道具 */
571
- async userProps(session, propsName) {
572
- const userId = session.userId;
573
- const userPropsData = Props.userPorpsTemp[userId];
574
- if (!userPropsData) return;
575
- if (!userPropsData[propsName]) {
576
- await session.send(`您似乎没有${propsName}这个道具...`);
577
- return;
578
- }
579
- if (propsData[propsName].cooling) {
580
- if (!coolingTemp[userId]) coolingTemp[userId] = {};
581
- if (!coolingTemp[userId][propsName]) coolingTemp[userId][propsName] = 0;
582
- const gapTime = Date.now() - coolingTemp[userId][propsName];
583
- if (gapTime < propsData[propsName].cooling) {
584
- await session.send(`该道具冷却还未结束,请等待${Math.ceil((coolingTemp[userId][propsName] - gapTime) / 60)}秒!`);
585
- return;
586
- } else {
587
- coolingTemp[userId][propsName] = Date.now();
588
- }
589
- }
590
- User.loseProps(userId, { name: propsName, val: 1 }, async (val) => {
591
- if (val.err) {
592
- await session.send(val.err);
593
- return;
594
- }
595
- if (propsData[propsName].cooling) {
596
- coolingTemp[userId];
597
- }
598
- const result = await propsData[propsName].fn(session);
599
- if (result && typeof result === "object" && "err" in result) {
600
- if (result.err) {
601
- await User.giveProps(userId, [{ name: propsName, val: 1 }]);
602
- }
603
- }
604
- });
605
- }
606
- };
607
- var coolingTemp = {};
608
-
609
447
  // src/monster.ts
610
448
  var import_koishi = require("koishi");
611
449
 
@@ -1498,6 +1336,172 @@ function initBattleAttribute(data) {
1498
1336
  }
1499
1337
  __name(initBattleAttribute, "initBattleAttribute");
1500
1338
 
1339
+ // src/data/initProps.ts
1340
+ var propsData = {
1341
+ "红药": {
1342
+ name: "红药",
1343
+ type: "消耗类" /* 消耗类 */,
1344
+ info: "回复自身20HP",
1345
+ price: 10,
1346
+ fn: /* @__PURE__ */ __name(async function(session) {
1347
+ User.giveHPMP(session.userId, { hp: 20 }, async (val) => {
1348
+ if (val.err) {
1349
+ await session.send(val.err);
1350
+ return;
1351
+ }
1352
+ const msg = `回复成功,玩家当前血量:${val.currentHP}`;
1353
+ await session.send(msg);
1354
+ });
1355
+ }, "fn")
1356
+ },
1357
+ "蓝药": {
1358
+ name: "蓝药",
1359
+ type: "消耗类" /* 消耗类 */,
1360
+ info: "回复自身20MP",
1361
+ price: 10,
1362
+ fn: /* @__PURE__ */ __name(async function(session) {
1363
+ User.giveHPMP(session.userId, { mp: 20 }, async (val) => {
1364
+ if (val.err) {
1365
+ await session.send(val.err);
1366
+ return;
1367
+ }
1368
+ const msg = `回复成功,玩家当前蓝量:${val.currentMP}`;
1369
+ await session.send(msg);
1370
+ });
1371
+ }, "fn")
1372
+ },
1373
+ "初级万能药": {
1374
+ name: "初级万能药",
1375
+ type: "消耗类" /* 消耗类 */,
1376
+ info: "回复自身20MP和20HP",
1377
+ price: 20,
1378
+ fn: /* @__PURE__ */ __name(async function(session) {
1379
+ User.giveHPMP(session.userId, { hp: 20, mp: 20 }, async (val) => {
1380
+ if (val.err) {
1381
+ await session.send(val.err);
1382
+ return;
1383
+ }
1384
+ const msg = `回复成功,玩家当前血量:${val.currentHP}、蓝量:${val.currentMP}`;
1385
+ await session.send(msg);
1386
+ });
1387
+ }, "fn")
1388
+ },
1389
+ "初级复活卷轴": {
1390
+ name: "初级复活卷轴",
1391
+ type: "消耗类" /* 消耗类 */,
1392
+ info: "复活玩家,复活时保留 20% 血量。(该道具使用完需要冷却 6 分钟)",
1393
+ price: 10,
1394
+ cooling: 3600,
1395
+ fn: /* @__PURE__ */ __name(async function(session) {
1396
+ if (BattleData.isBattleByUserId(session.userId)) {
1397
+ session.send(`该道具在战斗中无法使用!请在小队脱离战斗后使用。`);
1398
+ return { err: true };
1399
+ }
1400
+ if (!User.isDie(session.userId)) {
1401
+ session.send(`您还没有阵亡,使用失败!`);
1402
+ return { err: true };
1403
+ }
1404
+ const { maxHp } = User.getUserAttributeByUserId(session.userId);
1405
+ User.giveLife(session.userId, Math.floor(maxHp * 0.2), async (val) => {
1406
+ await session.send(`复活成功,当前血量:${val.currentHP}`);
1407
+ });
1408
+ }, "fn")
1409
+ }
1410
+ };
1411
+
1412
+ // src/props.ts
1413
+ var Props = {
1414
+ config: {},
1415
+ ctx: {},
1416
+ userPorpsTemp: {},
1417
+ async init(config, ctx) {
1418
+ Props.config = config;
1419
+ Props.ctx = ctx;
1420
+ ctx.database.extend("smm_gensokyo_user_props", {
1421
+ userId: "string",
1422
+ props: "json"
1423
+ }, {
1424
+ primary: "userId",
1425
+ autoInc: false
1426
+ });
1427
+ const temp = {};
1428
+ const propsList = await ctx.database.get("smm_gensokyo_user_props", {});
1429
+ propsList.forEach((item) => {
1430
+ temp[item.userId] = item.props;
1431
+ });
1432
+ Props.userPorpsTemp = temp;
1433
+ },
1434
+ /** 创建本地数据 */
1435
+ async initUserPropsData(userId) {
1436
+ if (!Props.userPorpsTemp[userId]) {
1437
+ Props.userPorpsTemp[userId] = {};
1438
+ const temp = {
1439
+ userId,
1440
+ props: {}
1441
+ };
1442
+ await Props.ctx.database.create("smm_gensokyo_user_props", temp);
1443
+ }
1444
+ },
1445
+ /** 获取持有道具信息 */
1446
+ async getPropsDataByUserId(userId) {
1447
+ await Props.initUserPropsData(userId);
1448
+ const userProps = Props.userPorpsTemp[userId];
1449
+ const msgList = Object.keys(userProps).map((item) => {
1450
+ return `${userProps[item].name}:${userProps[item].value}个`;
1451
+ });
1452
+ return msgList.length ? `当前您持有如下道具:
1453
+
1454
+ ` + msgList.join("\n") : "您没有任何道具...";
1455
+ },
1456
+ /** 更新本地数据库对应数据 */
1457
+ async setDatabasePropsData(userId) {
1458
+ const propsData2 = Props.userPorpsTemp[userId];
1459
+ if (propsData2) {
1460
+ const temp = {
1461
+ props: propsData2
1462
+ };
1463
+ await Props.ctx.database.set("smm_gensokyo_user_props", { userId }, temp);
1464
+ }
1465
+ },
1466
+ /** 使用指定道具 */
1467
+ async userProps(session, propsName) {
1468
+ const userId = session.userId;
1469
+ const userPropsData = Props.userPorpsTemp[userId];
1470
+ if (!userPropsData) return;
1471
+ if (!userPropsData[propsName]) {
1472
+ await session.send(`您似乎没有${propsName}这个道具...`);
1473
+ return;
1474
+ }
1475
+ if (propsData[propsName].cooling) {
1476
+ if (!coolingTemp[userId]) coolingTemp[userId] = {};
1477
+ if (!coolingTemp[userId][propsName]) coolingTemp[userId][propsName] = 0;
1478
+ const gapTime = Date.now() - coolingTemp[userId][propsName];
1479
+ if (gapTime < propsData[propsName].cooling) {
1480
+ await session.send(`该道具冷却还未结束,请等待${Math.ceil((coolingTemp[userId][propsName] - gapTime) / 60)}秒!`);
1481
+ return;
1482
+ } else {
1483
+ coolingTemp[userId][propsName] = Date.now();
1484
+ }
1485
+ }
1486
+ User.loseProps(userId, { name: propsName, val: 1 }, async (val) => {
1487
+ if (val.err) {
1488
+ await session.send(val.err);
1489
+ return;
1490
+ }
1491
+ if (propsData[propsName].cooling) {
1492
+ coolingTemp[userId];
1493
+ }
1494
+ const result = await propsData[propsName].fn(session);
1495
+ if (result && typeof result === "object" && "err" in result) {
1496
+ if (result.err) {
1497
+ await User.giveProps(userId, [{ name: propsName, val: 1 }]);
1498
+ }
1499
+ }
1500
+ });
1501
+ }
1502
+ };
1503
+ var coolingTemp = {};
1504
+
1501
1505
  // src/users.ts
1502
1506
  var UserOccDict = {
1503
1507
  ["剑士" /* 剑士 */]: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gensokyo",
3
3
  "description": "名为《幻想乡》的文字冒险游戏",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [