@bot-shiki/koishi-plugin-werewolf
Version:
Touhou werewolf game
91 lines (90 loc) • 3.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const koishi_1 = require("koishi");
const _1 = require(".");
const utils_1 = require("../utils");
class IkuAction extends _1.ExpertAction {
identity = 'iku';
exhaused;
predict;
isEffective(weather, dayCount = this.game.dayCount) {
// kyokkou 固定概率 1/20,不计入天气生成机制
switch (weather) {
case 'donten':
case 'souten':
case 'hanagumori':
// case 'noumu':
// eslint-disable-next-line no-fallthrough
case 'kawagiri':
case 'nagi':
case 'kousa':
return true;
case 'kaisei':
case 'taifuu':
case 'retsujitsu':
case 'baiu':
return dayCount > 1;
case 'tenkiame':
return this.game.options.sage;
default:
return false;
}
}
generate(dayCount = this.game.dayCount) {
return koishi_1.Random.pick(utils_1.Weather.filter(w => this.isEffective(w, dayCount)));
}
async action() {
if (!this.game.options.weather)
return;
await this.before();
await super.action();
await this.after();
}
async before() {
this.game.weather = this.predict || this.generate();
utils_1.logger.debug('weather %s', this.game.weather);
}
async after() {
if (!this.game.weather) {
await this.game.room.broadcast((0, utils_1.t)('general.weather-iku'));
return;
}
let weather = this.game.weather;
if (koishi_1.Random.bool(0.05)) {
weather = 'kyokkou';
}
const output = [(0, utils_1.t)('general.weather', [(0, utils_1.t)(`weather.${weather}.name`)])];
if (weather === 'kyokkou' || this.isEffective(weather)) {
output.push((0, utils_1.t)(`weather.${weather}.effect`));
}
else {
output.push((0, utils_1.t)(`general.no-effect`));
}
await this.game.room.broadcast(output.map(el => (0, koishi_1.h)('p', el)));
if (this.game.weather === 'kawagiri') {
this.game.seats = koishi_1.Random.shuffle(this.game.seats);
await this.game.room.broadcast((0, utils_1.t)('weather.kawagiri.hint', [
this.game.seats.filter(c => !c.isDead).map(c => c.player.name).join(', '),
]));
}
await Promise.all(this.game.seats.filter(c => !c.isDead).map(async (c) => c.player.pause(30000)));
}
async callback() {
this.predict = null;
if (this.exhaused) {
await this.player.pause(60000, (0, utils_1.t)('character.iku.exhausted'));
return;
}
await this.player.send((0, utils_1.t)('character.iku.action'));
const result = await this.player.select(['.', '。', '1', '2'], 60000);
if (result === '1') {
this.game.weather = null;
this.exhaused = true;
}
else {
this.predict = this.generate(this.game.dayCount + 1);
await this.player.send((0, utils_1.t)('character.iku.prediect', [this.predict]));
}
}
}
exports.default = IkuAction;