Bot personalities!
This commit is contained in:
1 parent
e1d059d72c
commit
6a91d2242a
3 files changed
+122
-4
No files matched your search
@@ -2,6 +2,7 @@ const express = require('express');
|
||||
const http = require('http');
|
||||
const { Server } = require('socket.io');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const cookieParser = require('cookie-parser');
|
||||
//const { v4: uuidv4 } = require('uuid');
|
||||
const { randomUUID } = require('node:crypto');
|
||||
@@ -269,6 +270,18 @@ class YarnGame {
|
||||
}
|
||||
}
|
||||
|
||||
saveStory() {
|
||||
const story_text = this.getStoryText();
|
||||
const now = new Date();
|
||||
const dateStamp = now.toISOString().slice(0, 10); // YYYY-MM-DD
|
||||
const timeStamp = now.toTimeString().slice(0, 8).replace(/:/g, '-'); // HH-MM-SS
|
||||
const fileName = `${this.roomName} - ${dateStamp} ${timeStamp}.txt`;
|
||||
const filePath = path.join('stories', fileName);
|
||||
|
||||
fs.mkdirSync('stories', { recursive: true }); // ensure dir exists
|
||||
fs.writeFileSync(filePath, story_text, 'utf8');
|
||||
}
|
||||
|
||||
botBanter() {
|
||||
for (const botObj of this.bots) {
|
||||
if (Math.random() > 0.8) {
|
||||
@@ -468,6 +481,7 @@ io.on('connection', (socket) => {
|
||||
const game = games[currentRoom];
|
||||
if (!game || game.gameHost !== playerId) return;
|
||||
|
||||
game.saveStory();
|
||||
game.resetGame();
|
||||
io.to(currentRoom).emit('gameReset', game.getState());
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user