Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "frontend",
"url": "http://localhost:3001",
"webRoot": "${workspaceFolder}/react_main"
},
{
"type": "node",
"request": "launch",
Expand Down
9 changes: 9 additions & 0 deletions Games/core/ArrayHash.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ module.exports = class ArrayHash {
return this.array()[index];
}

indexOf(item) {
let arr = this.array()
for (let i in arr)
if (arr[i] == item)
return i

return -1
}

get length() {
return Object.values(this).length;
}
Expand Down
9 changes: 9 additions & 0 deletions Games/types/Ghost/Action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Action = require("../../core/Action");

module.exports = class GhostAction extends Action {

constructor(options) {
super(options);
}

}
9 changes: 9 additions & 0 deletions Games/types/Ghost/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Card = require("../../core/Card");

module.exports = class GhostCard extends Card {

constructor(role) {
super(role);
}

}
218 changes: 218 additions & 0 deletions Games/types/Ghost/Game.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
const Game = require("../../core/Game");
const Player = require("./Player");
const Action = require("./Action");
const Queue = require("../../core/Queue");
const Winners = require("../../core/Winners");

const Random = require("../../../lib/Random");
const wordList = require("./data/words");

module.exports = class GhostGame extends Game {

constructor(options) {
super(options);

this.type = "Ghost";
this.Player = Player;
this.states = [
{
name: "Postgame"
},
{
name: "Pregame"
},
{
name: "Night",
length: options.settings.stateLengths["Night"],
skipChecks: [
() => this.playerGivingClue
]
},
{
name: "Give Clue",
length: options.settings.stateLengths["Give Clue"],
},
{
name: "Day",
length: options.settings.stateLengths["Day"],
skipChecks: [
() => this.playerGivingClue
]
},
{
name: "Guess Word",
length: options.settings.stateLengths["Guess Word"],
skipChecks: [
() => this.playerGivingClue
]
}
];

// game settings
this.configureWords = options.settings.configureWords;
this.wordLength = options.settings.wordLength;
this.townWord = options.settings.townWord;
this.foolWord = options.settings.townWord;

// giving clue
this.playerGivingClue = false;
this.currentPlayerList = [];
this.startIndex = -1;
this.currentIndex = -1;

this.responseHistory = [];
this.currentClueHistory = [];
}

start() {
if (!this.configureWords) {
let wordPack = Random.randArrayVal(wordList);
let shuffledWordPack = Random.randomizeArray(wordPack);
this.townWord = shuffledWordPack[0];
this.foolWord = shuffledWordPack[1];
this.wordLength = this.townWord.length;
}

super.start();
}

startRoundRobin(firstPick) {
if (this.currentClueHistory.length > 0) {
this.responseHistory.push({
"type": "clue",
"data": this.currentClueHistory,
})
this.currentClueHistory = [];
}

this.currentPlayerList = this.alivePlayers();
this.startIndex = this.currentPlayerList.indexOf(firstPick);
this.currentIndex = this.startIndex;

firstPick.holdItem("Microphone");
this.playerGivingClue = true;
}

incrementCurrentIndex() {
this.currentIndex = (this.currentIndex + 1) % this.currentPlayerList.length;
}

incrementState() {
let previousState = this.getStateName();

if (previousState == "Give Clue") {
this.incrementCurrentIndex();
while (true) {
if (this.currentIndex == this.startIndex) {
this.playerGivingClue = false;
break;
}

let nextPlayer = this.currentPlayerList[this.currentIndex];
if (nextPlayer.alive) {
nextPlayer.holdItem("Microphone");
break
}
this.incrementCurrentIndex();
}
}

super.incrementState();
}

recordClue(player, clue) {
this.currentClueHistory.push({
"name": player.name,
"clue": clue
})
}

recordGuess(player, guess) {
let data = {
"name": player.name,
"guess": guess,
};

this.responseHistory.push({
"type": "guess",
"data": data
})
}

// send player-specific state
broadcastState() {
for (let p of this.players) {
p.sendStateInfo();
}
}

getStateInfo(state) {
var info = super.getStateInfo(state);
info.extraInfo = {
"responseHistory": this.responseHistory,
"currentClueHistory": this.currentClueHistory
}
return info;
}

// process player leaving immediately
async playerLeave(player) {
if (this.started) {
let action = new Action({
actor: player,
target: player,
game: this,
run: function () {
this.target.kill("leave", this.actor, true);
}
});

this.instantAction(action);
}

await super.playerLeave(player);
}

checkWinConditions() {
var finished = false;
var counts = {};
var winQueue = new Queue();
var winners = new Winners(this);
var aliveCount = this.alivePlayers().length;

for (let player of this.players) {
let alignment = player.role.alignment;

if (!counts[alignment])
counts[alignment] = 0;

if (player.alive)
counts[alignment]++;

winQueue.enqueue(player.role.winCheck);
}

for (let winCheck of winQueue) {
winCheck.check(counts, winners, aliveCount);
}

if (winners.groupAmt() > 0)
finished = true;
else if (aliveCount == 0) {
winners.addGroup("No one");
finished = true;
}

winners.determinePlayers();
return [finished, winners];
}

getGameTypeOptions() {
return {
disableRehost: true,
};
}



}
9 changes: 9 additions & 0 deletions Games/types/Ghost/Item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Item = require("../../core/Item");

module.exports = class GhostItem extends Item {

constructor(role) {
super(role);
}

}
9 changes: 9 additions & 0 deletions Games/types/Ghost/Meeting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const Meeting = require("../../core/Meeting");

module.exports = class GhostMeeting extends Meeting {

constructor(game, name) {
super(game, name);
}

};
17 changes: 17 additions & 0 deletions Games/types/Ghost/Player.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Player = require("../../core/Player");

module.exports = class GhostPlayer extends Player {

constructor(user, game, isBot) {
super(user, game, isBot);
}

// add player-specific state info
sendStateInfo() {
let info = this.game.getStateInfo();
info.extraInfo.word = this.role?.word;
info.extraInfo.wordLength = this.game.wordLength;
this.send("state", info);
}

}
8 changes: 8 additions & 0 deletions Games/types/Ghost/Role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Role = require("../../core/Role");

module.exports = class GhostRole extends Role {

constructor(name, player, data) {
super(name, player, data);
}
}
8 changes: 8 additions & 0 deletions Games/types/Ghost/Winners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Winners = require("../../core/Winners");

module.exports = class GhostWinners extends Winners {

constructor(game) {
super(game);
}
}
Loading