UNPKG

koishi-plugin-shandian

Version:

闪电小游戏

139 lines (137 loc) 5.63 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __export = (target, all) => { for (var name2 in all) __defProp(target, name2, { get: all[name2], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { Config: () => Config, apply: () => apply, name: () => name, usage: () => usage }); module.exports = __toCommonJS(src_exports); var import_koishi = require("koishi"); var name = "shandian"; var usage = ` 闪电 创建和加入游戏 闪电 开始 开始游戏 闪电 结束 结束游戏 <small>测试阶段,有意见欢迎提<small/> `; var Config = import_koishi.Schema.object({}); function apply(ctx) { let game = {}; const hitValue = ["♠2", "♠3", "♠4", "♠5", "♠6", "♠7", "♠8", "♠9"]; ctx.command("闪电", "闪电游戏").action(async ({ session }) => { if (game[session.channelId] === void 0) { game[session.channelId] = { players: [session.userId], status: "waiting" }; return `══闪电══ 已将[闪电]置于${session.username}(${session.userId})的判定区 发送“闪电”以加入游戏 发送“闪电.开始”以开始游戏`; } else if (game[session.channelId].status === "waiting") { if (game[session.channelId].players.includes(session.userId)) { return `${import_koishi.h.at(session.userId)}你已经在游戏中了`; } else { game[session.channelId].players.push(session.userId); let userNames = []; for (const userId of game[session.channelId].players) { let user = await session.bot.getUser(userId); console.log(user); userNames.push(user.name); } console.log(userNames); return `${import_koishi.h.at(session.userId)} 加入游戏成功,当前游戏成员:${userNames}`; } } else { return `${import_koishi.h.at(session.userId)} 游戏进行中,请等待`; } }).example("闪电 创建和加入闪电游戏"); ctx.command("闪电.开始", "开始闪电游戏").action(async ({ session }) => { if (game[session.channelId] === void 0) { return `${import_koishi.h.at(session.userId)} 游戏未开始, 发送“闪电”以创建游戏`; } else if (game[session.channelId].status === "waiting") { game[session.channelId].status = "playing"; await gameStart(session); delete game[session.channelId]; return; } else { return `${import_koishi.h.at(session.userId)} 游戏进行中,请等待`; } }).example("创建游戏后可开始游戏"); ctx.command("闪电.结束", "终止闪电游戏").action(async ({ session }) => { if (game[session.channelId] === void 0) { return `${import_koishi.h.at(session.userId)} 游戏未开始, 发送“闪电”以创建游戏`; } else if (game[session.channelId].status === "waiting" || game[session.channelId].status === "playing") { delete game[session.channelId]; return `${import_koishi.h.at(session.userId)} 正在结束游戏..`; } }).example("游戏中随时输入此命令以结束游戏"); async function gameStart(session) { let players = game[session.channelId].players; session.send(`══闪电══ 游戏开始 游戏中随时输入 “闪电 结束” 以结束游戏`); session.send(import_koishi.h.image("http://101.132.253.14/wp-content/uploads/2024/10/b9d8b701d19e02521c958348.png")); await (0, import_koishi.sleep)(2e3); for (let i = 0; i < players.length; i++) { if (game[session.channelId] === void 0) { session.send(`已终止游戏`); return; } let playerId = players[i]; let playerName = (await session.bot.getUser(playerId)).name; session.send(`闪电来到了${playerName}的判定区`); await (0, import_koishi.sleep)(1e3); session.send(`${playerName}的判定结果是...`); await (0, import_koishi.sleep)(3e3); let randPoke = getRandomPoke(); session.send(`${randPoke}`); await (0, import_koishi.sleep)(1e3); if (hitValue.includes(randPoke)) { session.send(`${import_koishi.h.at(playerId)} 被劈死了! 游戏结束`); return; } session.send(`${playerName}没有被击中!`); await (0, import_koishi.sleep)(1e3); if (i === players.length - 1) { i = -1; } } } __name(gameStart, "gameStart"); function getRandomPoke() { const suits = ["♠", "♥", "♣", "♦"]; const values = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]; let suitsIndex = Math.floor(Math.random() * suits.length); let valuesIndex = Math.floor(Math.random() * values.length); return suits[suitsIndex] + values[valuesIndex]; } __name(getRandomPoke, "getRandomPoke"); } __name(apply, "apply"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Config, apply, name, usage });