@bot-shiki/koishi-plugin-werewolf
Version:
Touhou werewolf game
84 lines (83 loc) • 3.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VoteAction = exports.ExpertAction = exports.Action = void 0;
const koishi_1 = require("koishi");
const utils_1 = require("../utils");
class Action {
game;
constructor(game) {
this.game = game;
}
}
exports.Action = Action;
class ExpertAction extends Action {
character;
player;
async action() {
this.character = this.game.getChar(this.identity);
if (!this.character)
return;
this.player = this.character.player;
utils_1.logger.debug('%s action', this.identity);
const others = this.game.room.filter(player => player !== this.player);
await Promise.all([
others.broadcast((0, utils_1.t)('general.expert-action', [(0, utils_1.t)(`character.${this.identity}.name`)])),
(async () => {
if (this.character.isDead) {
return this.player.pause(10000, (0, utils_1.t)('general.expert-dead'));
}
return this.callback();
})(),
]);
}
retsujitsu() {
if (this.game.weather !== 'retsujitsu')
return;
const result = koishi_1.Random.bool(0.5);
if (result)
utils_1.logger.debug('weather retsujitsu take effect');
return result;
}
}
exports.ExpertAction = ExpertAction;
class VoteAction extends Action {
async vote(round, voters, candidates, hint, force = false) {
this.game.seats.forEach((char) => {
char.votes = 0;
char.taifuu = false;
char.target = null;
});
await Promise.all(voters.map(async (char) => {
await char.player.send(hint);
let target = await char.select((c) => ({
disabled: !candidates.includes(c),
}), 60000, !force);
if (!target) {
if (!force)
return;
target = char;
}
char.taifuu = this.game.weather === 'taifuu' && koishi_1.Random.bool(0.5);
if (char.taifuu)
return;
char.target = target;
target.votes += char.isSage && this.game.weather !== 'tenkiame' ? 1.5 : 1;
}));
const output = [(0, utils_1.t)('vote.round', [round])];
if (this.game.weather === 'kousa') {
for (const char of candidates) {
output.push((0, utils_1.t)('vote.candidate', [char.player.name, char.votes]));
}
}
else {
for (const char of voters) {
const type = char.taifuu ? 'taifuu' : char.target ? 'voter-1' : 'voter-2';
output.push((0, utils_1.t)('vote.' + type, [char.player.name, char.target?.player.name]));
}
}
await this.game.room.broadcast(output.map(el => (0, koishi_1.h)('p', el)));
const max = Math.max(...candidates.map(c => c.votes));
return candidates.filter(c => c.votes === max);
}
}
exports.VoteAction = VoteAction;