koishi-plugin-ggcevo-game 0.3.6 → 0.3.8

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 +32 -14
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -960,22 +960,40 @@ ${items.join("、")}
960
960
  if (!name2) return "输入超时,请重新输入指令。";
961
961
  const handle = `${profile.regionId}-S2-${profile.realmId}-${profile.profileId}`;
962
962
  const configname = itemConfig[name2];
963
- if (!configname) return `无效的物品名称,请重新输入指令。`;
963
+ if (!configname) return "无效的物品名称,请重新输入";
964
964
  const userRecords = await ctx.database.get("ggcevo_exchange", { handle, item: name2 });
965
965
  if (userRecords.length > 0) return "您已经兑换过该物品";
966
966
  if (configname.quantity !== void 0) {
967
967
  const globalRecords = await ctx.database.get("ggcevo_exchange", { item: name2 });
968
- if (globalRecords.length >= configname.quantity) return "该物品已经被兑换尽了";
968
+ if (globalRecords.length >= configname.quantity) return "该物品已兑尽";
969
969
  }
970
- const [coupon] = await ctx.database.get("ggcevo_backpack", { handle, itemId: 2 });
971
- if (!coupon || coupon.quantity < configname.cost) {
972
- return `兑换需要 ${configname.cost} 张兑奖券,当前持有:${coupon?.quantity || 0}`;
970
+ const petItems = /* @__PURE__ */ new Set(["小狗", "小猫", "小黄鸭", "萌萌熊", "荆棘蜥蜴", "爆笑小狗", "熔岩蟹", "远古蝗虫", "绿毛虫", "妙蛙种子", "皮卡丘", "哆啦A梦"]);
971
+ const qualityMap = { "t3": 4, "t2": 5, "t1": 6, "t0": 7 };
972
+ let cost = configname.cost;
973
+ let itemId = 2;
974
+ let couponName = "兑奖券";
975
+ if (petItems.has(name2)) {
976
+ const [specialCoupon] = await ctx.database.get("ggcevo_backpack", {
977
+ handle,
978
+ itemId: qualityMap[configname.quality]
979
+ });
980
+ if (specialCoupon?.quantity >= 1) {
981
+ itemId = qualityMap[configname.quality];
982
+ cost = 1;
983
+ couponName = `${configname.quality}级宠物扭蛋`;
984
+ }
985
+ }
986
+ const [coupon] = await ctx.database.get("ggcevo_backpack", { handle, itemId });
987
+ if (!coupon || coupon.quantity < cost) {
988
+ const requireMsg = petItems.has(name2) ? `需要 1 个${configname.quality}级扭蛋 或 ${configname.cost}个兑奖券` : `需要 ${configname.cost}个兑奖券`;
989
+ return `${requireMsg}
990
+ 当前持有:${coupon?.quantity || 0}个${couponName}`;
973
991
  }
974
992
  await ctx.database.withTransaction(async () => {
975
993
  await ctx.database.set(
976
994
  "ggcevo_backpack",
977
- { handle, itemId: 2 },
978
- { quantity: coupon.quantity - configname.cost }
995
+ { handle, itemId },
996
+ { quantity: coupon.quantity - cost }
979
997
  );
980
998
  await ctx.database.create("ggcevo_exchange", {
981
999
  userId: session.userId,
@@ -984,10 +1002,10 @@ ${items.join("、")}
984
1002
  date: /* @__PURE__ */ new Date()
985
1003
  });
986
1004
  });
987
- return `兑换成功!消耗 ${configname.cost} 张兑奖券获得【${name2}】(游戏物品发放请联系管理员)`;
1005
+ return `兑换成功!消耗 ${cost} 个${couponName}获得【${name2}】`;
988
1006
  } catch (error) {
989
1007
  console.error("兑换失败:", error);
990
- return `兑换失败`;
1008
+ return "兑换失败";
991
1009
  }
992
1010
  });
993
1011
  ctx.command("ggcevo/兑换记录").action(async ({ session }) => {
@@ -1046,17 +1064,17 @@ ${output}`;
1046
1064
  if (!backpack || backpack.quantity < 1) {
1047
1065
  return `当前扭蛋币不足,剩余:${backpack?.quantity || 0}枚`;
1048
1066
  }
1049
- await ctx.database.upsert("ggcevo_backpack", [{
1050
- handle,
1051
- itemId: 3,
1052
- quantity: backpack.quantity - 1
1053
- }]);
1054
1067
  const award = PetCapsuleToy();
1055
1068
  const items = await ctx.database.get("ggcevo_items", { name: award });
1056
1069
  if (items.length === 0) {
1057
1070
  return `系统错误,奖品${award}不存在,请联系管理员。`;
1058
1071
  }
1059
1072
  const item = items[0];
1073
+ await ctx.database.upsert("ggcevo_backpack", [{
1074
+ handle,
1075
+ itemId: 3,
1076
+ quantity: backpack.quantity - 1
1077
+ }]);
1060
1078
  const [userAward] = await ctx.database.get("ggcevo_backpack", { handle, itemId: item.id });
1061
1079
  const currentQuantity = userAward ? userAward.quantity : 0;
1062
1080
  await ctx.database.upsert("ggcevo_backpack", [{
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ggcevo-game",
3
3
  "description": "星际争霸2游戏大厅地图咕咕虫-evo小游戏",
4
- "version": "0.3.6",
4
+ "version": "0.3.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [