koishi-plugin-smmcat-gensokyo 0.0.17 → 0.0.18

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.
@@ -11,7 +11,9 @@ export type propsTemplateData = {
11
11
  info: string;
12
12
  price: number;
13
13
  cooling?: number;
14
- fn: (session: Session) => void;
14
+ fn: (session: Session) => Promise<void | {
15
+ err: boolean;
16
+ }>;
15
17
  };
16
18
  };
17
19
  export declare const propsData: propsTemplateData;
package/lib/index.js CHANGED
@@ -451,7 +451,7 @@ var propsData = {
451
451
  type: "消耗类" /* 消耗类 */,
452
452
  info: "回复自身20HP",
453
453
  price: 10,
454
- fn: /* @__PURE__ */ __name(function(session) {
454
+ fn: /* @__PURE__ */ __name(async function(session) {
455
455
  User.giveHPMP(session.userId, { hp: 20 }, async (val) => {
456
456
  if (val.err) {
457
457
  await session.send(val.err);
@@ -467,7 +467,7 @@ var propsData = {
467
467
  type: "消耗类" /* 消耗类 */,
468
468
  info: "回复自身20MP",
469
469
  price: 10,
470
- fn: /* @__PURE__ */ __name(function(session) {
470
+ fn: /* @__PURE__ */ __name(async function(session) {
471
471
  User.giveHPMP(session.userId, { mp: 20 }, async (val) => {
472
472
  if (val.err) {
473
473
  await session.send(val.err);
@@ -483,7 +483,7 @@ var propsData = {
483
483
  type: "消耗类" /* 消耗类 */,
484
484
  info: "回复自身20MP和20HP",
485
485
  price: 20,
486
- fn: /* @__PURE__ */ __name(function(session) {
486
+ fn: /* @__PURE__ */ __name(async function(session) {
487
487
  User.giveHPMP(session.userId, { hp: 20, mp: 20 }, async (val) => {
488
488
  if (val.err) {
489
489
  await session.send(val.err);
@@ -500,10 +500,10 @@ var propsData = {
500
500
  info: "复活玩家,复活时保留 20% 血量。(该道具使用完需要冷却 6 分钟)",
501
501
  price: 10,
502
502
  cooling: 3600,
503
- fn: /* @__PURE__ */ __name(function(session) {
503
+ fn: /* @__PURE__ */ __name(async function(session) {
504
504
  if (!User.isDie(session.userId)) {
505
505
  session.send(`啊哈...你还没有阵亡,使用失败!`);
506
- return;
506
+ return { err: true };
507
507
  }
508
508
  const { maxHp } = User.getUserAttributeByUserId(session.userId);
509
509
  User.giveLife(session.userId, Math.floor(maxHp * 0.2), async (val) => {
@@ -595,7 +595,12 @@ var Props = {
595
595
  if (propsData[propsName].cooling) {
596
596
  coolingTemp[userId];
597
597
  }
598
- propsData[propsName].fn(session);
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
+ }
599
604
  });
600
605
  }
601
606
  };
@@ -1913,19 +1918,21 @@ ${Object.keys(UserOccDict).map((i) => `【${i}】:${UserOccDict[i].info}`).join(
1913
1918
  const upProps = [];
1914
1919
  for (const item of props) {
1915
1920
  const propsItem = propsData[item.name];
1916
- if (!propsItem) continue;
1917
- userProps[item.name] = {
1918
- name: propsItem.name,
1919
- type: propsItem.type,
1920
- value: 0
1921
- };
1921
+ if (!propsData[item.name]) continue;
1922
+ if (!userProps[item.name]) {
1923
+ userProps[item.name] = {
1924
+ name: propsItem.name,
1925
+ type: propsItem.type,
1926
+ value: 0
1927
+ };
1928
+ }
1922
1929
  userProps[item.name].value += item.val || 1;
1923
1930
  upProps.push({ name: item.name, val: userProps[item.name].value });
1924
1931
  }
1932
+ await Props.setDatabasePropsData(userId);
1925
1933
  fn && await fn({
1926
1934
  currentProps: upProps
1927
1935
  });
1928
- await Props.setDatabasePropsData(userId);
1929
1936
  },
1930
1937
  /** 去除玩家指定道具 */
1931
1938
  async loseProps(userId, props, fn) {
@@ -1955,10 +1962,10 @@ ${Object.keys(UserOccDict).map((i) => `【${i}】:${UserOccDict[i].info}`).join(
1955
1962
  }
1956
1963
  userProps[props.name].value -= props.val || 1;
1957
1964
  if (userProps[props.name].value == 0) delete userProps[props.name];
1965
+ await Props.setDatabasePropsData(userId);
1958
1966
  fn && await fn({
1959
1967
  currentProps: { name: props.name, val: userProps[props.name]?.value || 0 }
1960
1968
  });
1961
- await Props.setDatabasePropsData(userId);
1962
1969
  },
1963
1970
  /** 目标是否死亡 */
1964
1971
  isDie(userId) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-gensokyo",
3
3
  "description": "名为《幻想乡》的文字冒险游戏",
4
- "version": "0.0.17",
4
+ "version": "0.0.18",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [