Compare commits
2
Commits
b1f3f955c1
...
1360fbb5c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1360fbb5c7 | ||
|
|
9a802b358d |
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.30.11",
|
"version": "1.30.12",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.30.11",
|
"version": "1.30.12",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^8.3.0",
|
"better-sqlite3": "^8.3.0",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.30.11",
|
"version": "1.30.12",
|
||||||
"description": "Game host for SChat 2-powered chat sites",
|
"description": "Game host for SChat 2-powered chat sites",
|
||||||
"main": "src/app.js",
|
"main": "src/app.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
+12
-13
@@ -18,6 +18,7 @@ const availableLetters = {
|
|||||||
const types = { v: 'vowel', c: 'consonant' };
|
const types = { v: 'vowel', c: 'consonant' };
|
||||||
|
|
||||||
const settings = { ...config.letters };
|
const settings = { ...config.letters };
|
||||||
|
const minReminderInterval = 10; // seconds
|
||||||
const games = new Map();
|
const games = new Map();
|
||||||
|
|
||||||
function getBoard(context) {
|
function getBoard(context) {
|
||||||
@@ -106,22 +107,20 @@ async function play(context) {
|
|||||||
game.state = 'words';
|
game.state = 'words';
|
||||||
game.counts = countLetters(game.word);
|
game.counts = countLetters(game.word);
|
||||||
|
|
||||||
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(settings.timeout))} seconds, let's start!`, context.room.id);
|
// lock in the timeout so changing it mid-round doesn't skew the countdown
|
||||||
|
const { timeout } = settings;
|
||||||
|
const steps = Math.max(1, Math.min(5, Math.floor(timeout / minReminderInterval))); // don't repeat the board too often on short timeouts
|
||||||
|
|
||||||
|
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(timeout))} seconds, let's start!`, context.room.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
for (let step = 1; step <= steps; step += 1) {
|
||||||
|
await timers.setTimeout((timeout / steps) * 1000, null, { signal: game.ac.signal }); // eslint-disable-line no-await-in-loop
|
||||||
|
|
||||||
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 4)} seconds`))} left`, context.room.id);
|
if (step < steps) {
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id);
|
||||||
|
}
|
||||||
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 3)} seconds`))} left`, context.room.id);
|
}
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
|
||||||
|
|
||||||
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round((settings.timeout / 5) * 2)} seconds`))} left`, context.room.id);
|
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
|
||||||
|
|
||||||
context.sendMessage(`${getBoard(context)} You have ${style.bold(style.green(`${Math.round(settings.timeout / 5)} seconds`))} left`, context.room.id);
|
|
||||||
await timers.setTimeout((settings.timeout / 5) * 1000, null, { signal: game.ac.signal });
|
|
||||||
|
|
||||||
stop(context);
|
stop(context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
+12
-7
@@ -41,6 +41,7 @@ limitedMath.import({
|
|||||||
}, { override: true });
|
}, { override: true });
|
||||||
|
|
||||||
const settings = { ...config.numbers };
|
const settings = { ...config.numbers };
|
||||||
|
const minReminderInterval = 10; // seconds
|
||||||
const games = new Map();
|
const games = new Map();
|
||||||
|
|
||||||
/* eslint-disable no-irregular-whitespace */
|
/* eslint-disable no-irregular-whitespace */
|
||||||
@@ -177,17 +178,21 @@ async function play(context) {
|
|||||||
|
|
||||||
game.state = 'solutions';
|
game.state = 'solutions';
|
||||||
|
|
||||||
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(settings.timeout))} seconds, let's start!`, context.room.id);
|
// lock in the timeout so changing it mid-round doesn't skew the countdown
|
||||||
|
const { timeout } = settings;
|
||||||
|
const steps = Math.max(1, Math.min(3, Math.floor(timeout / minReminderInterval))); // don't repeat the board too often on short timeouts
|
||||||
|
|
||||||
|
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(timeout))} seconds, let's start!`, context.room.id);
|
||||||
context.logger.info(`Numbers game started by ${context.user.username}, numbers ${game.numbers.join('|')}, target ${game.target}, ${game.solution.answer === game.target ? 'exact' : 'closest'} solution for ${game.solution.answer} is: ${game.solution.solution}`);
|
context.logger.info(`Numbers game started by ${context.user.username}, numbers ${game.numbers.join('|')}, target ${game.target}, ${game.solution.answer === game.target ? 'exact' : 'closest'} solution for ${game.solution.answer} is: ${game.solution.solution}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal });
|
for (let step = 1; step <= steps; step += 1) {
|
||||||
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((settings.timeout / 3) * 2)} seconds`))} left`, context.room.id);
|
await timers.setTimeout((timeout / steps) * 1000, null, { signal: game.ac.signal }); // eslint-disable-line no-await-in-loop
|
||||||
|
|
||||||
await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal });
|
if (step < steps) {
|
||||||
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round(settings.timeout / 3)} seconds`))} left`, context.room.id);
|
context.sendMessage(`${getBoard(context)}. You have ${style.bold(style.green(`${Math.round((timeout / steps) * (steps - step))} seconds`))} left`, context.room.id);
|
||||||
|
}
|
||||||
await timers.setTimeout((settings.timeout / 3) * 1000, null, { signal: game.ac.signal });
|
}
|
||||||
|
|
||||||
stop(context);
|
stop(context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user