@bot-shiki/koishi-plugin-werewolf
Version:
Touhou werewolf game
144 lines (143 loc) • 4.88 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rotate = exports.Character = exports.Preset = exports.Identity = exports.Weather = exports.t = exports.logger = void 0;
const koishi_1 = require("koishi");
exports.logger = new koishi_1.Logger('werewolf');
const t = (path, param) => koishi_1.h.i18n('lobby.game.th-werewolf.' + path, param);
exports.t = t;
exports.Weather = [
'kaisei', 'kirisame', 'donten', 'souten', 'hyou',
'hanagumori', 'noumu', 'yuki', 'tenkiame', 'utoame',
'fuuu', 'seiran', 'kawagiri', 'taifuu', 'nagi',
'diamond-dust', 'kousa', 'retsujitsu', 'baiu', 'kyokkou',
];
var Identity;
(function (Identity) {
Identity.Neutral = ['doremy', 'parsee'];
Identity.Youkai = [];
Identity.Youkai.push(...Identity.Youkai.Expert = ['yukari', 'utsuho', 'remilia', 'yuuka', 'mamizou', 'iku']);
Identity.Youkai.push(...Identity.Youkai.Normal = ['kagerou', 'rumia', 'mystia', 'wriggle', 'wakasagihime', 'sekibanki', 'kyouko', 'tewi', 'chen', 'nazrin', 'kogasa']);
Identity.Ningen = [];
Identity.Ningen.push(...Identity.Ningen.Expert = ['reimu', 'rinnosuke']);
Identity.Ningen.push(...Identity.Ningen.Normal = ['marisa', 'sanae', 'sumireko', 'kosuzu', 'renko', 'merry', 'akyuu', 'youmu', 'mokou']);
Identity.Expert = [...Identity.Neutral, ...Identity.Youkai.Expert, ...Identity.Ningen.Expert];
function getParty(identity) {
if (Identity.Neutral.includes(identity))
return 'neutral';
if (Identity.Youkai.includes(identity))
return 'youkai';
if (Identity.Ningen.includes(identity))
return 'ningen';
}
Identity.getParty = getParty;
})(Identity || (exports.Identity = Identity = {}));
exports.Preset = require('./preset');
class Character {
game;
player;
identity;
party;
/** 是贤者 */
isSage;
/** 角色死因 */
killer;
/** 苍天的替死者 */
scapegoat;
/** 目标角色 */
target;
/** 台风 */
taifuu;
/** 得票数 */
votes;
/** 选定目标的时间 */
voteTime;
/** remilia 知晓阵营 */
isKnown;
/** 全员知晓身份 */
isWellKnown;
/** 无法被替死或发动复仇 */
isScapegoat;
/** doremy 噩梦状态 */
nightmare;
/** 是否出局 (含 utsuho 被投死) */
isOut;
constructor(game, player, identity) {
this.game = game;
this.player = player;
this.identity = identity;
this.party = Identity.getParty(identity);
}
/** 有特殊技能 */
get isExpert() {
return Identity.Expert.includes(this.identity);
}
get isRevenger() {
return ['reimu', 'yuuka'].includes(this.identity);
}
get isDead() {
return this.isOut && (this.identity !== 'utsuho' || this.killer !== 'vote');
}
get isDying() {
return this.killer && !this.isOut;
}
/** 是否被视为人类 */
get isNingen() {
return this.party === 'ningen' && this.identity !== 'rinnosuke';
}
/** 能在投票前发言 */
get canSpeak() {
return !this.killer || this.identity === 'utsuho' && this.killer === 'vote';
}
render(result) {
const i = this.game.seats.indexOf(this);
const output = [`[${result.disabled ? ' ' : i + 1}] ${this.player.name}`];
const labels = [];
if (result.labels)
labels.push(...result.labels);
if (this.killer === 'offline') {
labels.push((0, exports.t)('general.offline'));
}
else if (this.isOut) {
labels.push((0, exports.t)('general.is-dead'));
}
if (labels.length) {
output[0] += ' (';
labels.forEach((label, i) => {
if (i)
output.push(', ');
output.push(label);
});
output.push(')');
}
return (0, koishi_1.h)('p', output);
}
async select(predicate, timeout, optional) {
const choices = optional ? ['.', '。'] : [];
const output = this.game.seats.map((c, i) => {
const result = predicate(c);
if (!result.disabled)
choices.push(String(i + 1));
return c.render(result);
});
await this.player.send(output);
const result = await this.player.select(choices, timeout);
return this.game.seats[+result - 1];
}
toString() {
return `${this.identity} (${this.player.name})`;
}
}
exports.Character = Character;
function rotate(source, offset = 0) {
const result = source.slice();
if (!offset)
return result;
if (offset < 0) {
result.unshift(...result.splice(offset, Infinity));
}
else {
result.push(...result.splice(0, offset));
}
return result;
}
exports.rotate = rotate;