Compare commits
2 Commits
09e78a8bbb
...
a45d00c105
Author | SHA1 | Date |
---|---|---|
|
a45d00c105 | |
|
00b92f445e |
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.26.7",
|
"version": "1.26.8",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.26.7",
|
"version": "1.26.8",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^8.3.0",
|
"better-sqlite3": "^8.3.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "schat2-clive",
|
"name": "schat2-clive",
|
||||||
"version": "1.26.7",
|
"version": "1.26.8",
|
||||||
"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": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
|
const { intervalToDuration } = require('date-fns');
|
||||||
|
|
||||||
const style = require('../utils/style');
|
const style = require('../utils/style');
|
||||||
const pickRandom = require('../utils/pick-random');
|
const pickRandom = require('../utils/pick-random');
|
||||||
|
@ -56,11 +57,18 @@ function onCommand(args, context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const hit = Math.random() > config.duck.missRatio;
|
const hit = Math.random() > config.duck.missRatio;
|
||||||
const time = ((new Date().getTime() - duck.getTime()) / 1000).toFixed(3);
|
const time = new Date().getTime() - duck.getTime();
|
||||||
|
|
||||||
|
const distance = time < 600 * 1000 // show exact time up to ten minutes
|
||||||
|
? `${(time / 1000).toFixed(3)} seconds`
|
||||||
|
: Object.entries(intervalToDuration({ start: duck, end: new Date() }))
|
||||||
|
.filter(([, value]) => value > 0)
|
||||||
|
.map(([key, value]) => `${value} ${key}`)
|
||||||
|
.join(', ');
|
||||||
|
|
||||||
if (['bang', 'shoot'].includes(context.command)) {
|
if (['bang', 'shoot'].includes(context.command)) {
|
||||||
if (hit) {
|
if (hit) {
|
||||||
context.sendMessage(`You shot a duck in ${style.bold(`${time} seconds`)}, ${context.user.prefixedUsername}`, context.room.id);
|
context.sendMessage(`${context.user.prefixedUsername}: You shot a duck in ${style.bold(style.red(distance))}`, context.room.id);
|
||||||
launchDuck(context);
|
launchDuck(context);
|
||||||
|
|
||||||
context.setPoints(context.user, 1, { key: 'bang' });
|
context.setPoints(context.user, 1, { key: 'bang' });
|
||||||
|
@ -83,7 +91,7 @@ function onCommand(args, context) {
|
||||||
|
|
||||||
if (['bef', 'befriend'].includes(context.command)) {
|
if (['bef', 'befriend'].includes(context.command)) {
|
||||||
if (hit) {
|
if (hit) {
|
||||||
context.sendMessage(`You befriended a duck in ${style.bold(style.green(`${time} seconds`))}, ${context.user.prefixedUsername}`, context.room.id);
|
context.sendMessage(`${context.user.prefixedUsername}: You befriended a duck in ${style.bold(style.sky(distance))}`, context.room.id);
|
||||||
launchDuck(context);
|
launchDuck(context);
|
||||||
|
|
||||||
context.setPoints(context.user, 1, { key: 'befriend' });
|
context.setPoints(context.user, 1, { key: 'befriend' });
|
||||||
|
|
Loading…
Reference in New Issue