add bots to a game

This commit is contained in:
AlecM33
2023-01-30 12:40:28 -05:00
parent e362f6bdb2
commit 79309f5062
16 changed files with 106 additions and 43 deletions

View File

@@ -86,7 +86,9 @@ const Events = [
stateChange: async (game, socketArgs, vars) => {
const person = game.people.find((person) => person.id === socketArgs.personId);
if (person && !person.out) {
person.userType = globals.USER_TYPES.KILLED_PLAYER;
person.userType = person.userType === globals.USER_TYPES.BOT
? globals.USER_TYPES.KILLED_BOT
: globals.USER_TYPES.KILLED_PLAYER;
person.out = true;
person.killed = true;
}

View File

@@ -59,8 +59,10 @@ class GameManager {
gameParams.hasTimer,
gameParams.timerParams,
gameParams.moderatorName,
gameParams.hasDedicatedModerator
gameParams.hasDedicatedModerator,
gameParams.isTestGame
);
console.log(req.isTestGame);
const newAccessCode = await this.generateAccessCode(globals.ACCESS_CODE_CHAR_POOL);
if (newAccessCode === null) {
return Promise.reject(globals.ERROR_MESSAGE.NO_UNIQUE_ACCESS_CODE);
@@ -76,14 +78,15 @@ class GameManager {
const newGame = new Game(
newAccessCode,
globals.STATUS.LOBBY,
initializePeopleForGame(req.deck, moderator, this.shuffle),
initializePeopleForGame(req.deck, moderator, this.shuffle, req.isTestGame),
req.deck,
req.hasTimer,
moderator.id,
req.hasDedicatedModerator,
moderator.id,
new Date().toJSON(),
req.timerParams
req.timerParams,
req.isTestGame
);
await this.eventManager.publisher.set(newAccessCode, JSON.stringify(newGame), {
EX: globals.STALE_GAME_SECONDS
@@ -242,6 +245,10 @@ class GameManager {
game.people[i].userType = globals.USER_TYPES.PLAYER;
game.people[i].out = false;
}
if (game.people[i].userType === globals.USER_TYPES.KILLED_BOT) {
game.people[i].userType = globals.USER_TYPES.BOT;
game.people[i].out = false;
}
game.people[i].revealed = false;
game.people[i].killed = false;
if (game.people[i].gameRole) {
@@ -314,7 +321,7 @@ function initializeModerator (name, hasDedicatedModerator) {
return new Person(createRandomId(), createRandomId(), name, userType);
}
function initializePeopleForGame (uniqueRoles, moderator, shuffle) {
function initializePeopleForGame (uniqueRoles, moderator, shuffle, isTestGame) {
const people = [];
const cards = [];
@@ -335,10 +342,11 @@ function initializePeopleForGame (uniqueRoles, moderator, shuffle) {
createRandomId(),
createRandomId(),
UsernameGenerator.generate(),
globals.USER_TYPES.PLAYER,
isTestGame ? globals.USER_TYPES.BOT : globals.USER_TYPES.PLAYER,
cards[j].role,
cards[j].description,
cards[j].team
cards[j].team,
isTestGame
);
person.customRole = cards[j].custom;
person.hasEnteredName = false;