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
62 changes: 62 additions & 0 deletions src/gameplay/gameEngine/cards/avalon/norebo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Card, ICard } from '../types';
import { SocketUser } from '../../../../sockets/types';
import { Alliance } from '../../types';
import shuffleArray from '../../../../util/shuffleArray';



class Norebo implements ICard {
private thisRoom: any;

static card = Card.Norebo;
card = Card.Norebo;

indexOfPlayerHolding = -1; //TODO not sure if should be 0 like other cards.

description =
'A random resistance member who unknowingly appears as a spy to other spies. Card does not change hands.';
constructor(thisRoom: any) {
this.thisRoom = thisRoom;
}

initialise(): void {
this.setHolder(0)
//the number 0 doesn't matter
;
}

setHolder(index: number): void {
//assign to a random Resistance member
let resPlayersIndexes=[];
for (let i = 0; i < this.thisRoom.playersInGame.length; i++) {
if (this.thisRoom.playersInGame[i].alliance === Alliance.Resistance) {
resPlayersIndexes.push(i);
this.indexOfPlayerHolding=i;
}
}
resPlayersIndexes = shuffleArray(resPlayersIndexes);
this.indexOfPlayerHolding=resPlayersIndexes[0];
// console.log("Norebo started with player", this.indexOfPlayerHolding);
}

checkSpecialMove(
socket: SocketUser,
buttonPressed: 'yes' | 'no',
selectedPlayers: string[],
): boolean {
return false;
}

getPublicGameData(): any {
/* TODO: (Can delete this function. Not absolutely necessary)
Public data to show the user(s) e.g. who holds the lady of the lake */
return {
norebo: {
index: this.indexOfPlayerHolding,
name: this.card,
},
};
}
}

export default Norebo;
2 changes: 2 additions & 0 deletions src/gameplay/gameEngine/cards/cards.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import LadyOfTheLake from './avalon/ladyOfTheLake';
import RefOfTheRain from './avalon/refOfTheRain';
import SireOfTheSea from './avalon/sireOfTheSea';
import Norebo from './avalon/norebo';

export const avalonCards = {
[LadyOfTheLake.card]: LadyOfTheLake,
[RefOfTheRain.card]: RefOfTheRain,
[SireOfTheSea.card]: SireOfTheSea,
[Norebo.card]: Norebo,
};
1 change: 1 addition & 0 deletions src/gameplay/gameEngine/cards/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum Card {
LadyOfTheLake = 'Lady of the Lake',
RefOfTheRain = 'Ref of the Rain',
SireOfTheSea = 'Sire of the Sea',
Norebo = 'Norebo',
}

export interface ICard {
Expand Down
37 changes: 31 additions & 6 deletions src/gameplay/gameEngine/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class Game extends Room {
specialRoles: any;
specialPhases: any;
specialCards: any;
//cardKeysInPlay: any; //making public TODO maybe this line is useless

gameTimer: GameTimer;
dateTimerExpires: Date;
Expand Down Expand Up @@ -519,6 +520,12 @@ class Game extends Room {
}
}

// Initialise all the Cards
for (let i = 0; i < this.cardKeysInPlay.length; i++) {
this.specialCards[this.cardKeysInPlay[i]].initialise();
}


// Prepare the data for each person to see for the rest of the game.
// The following data do not change as the game goes on.
for (let i = 0; i < this.playersInGame.length; i++) {
Expand Down Expand Up @@ -601,11 +608,6 @@ class Game extends Room {
this.voteHistory[this.playersInGame[i].request.user.username] = [];
}

// Initialise all the Cards
for (let i = 0; i < this.cardKeysInPlay.length; i++) {
this.specialCards[this.cardKeysInPlay[i]].initialise();
}

this.distributeGameData();

this.botIndexes = [];
Expand Down Expand Up @@ -1289,7 +1291,7 @@ class Game extends Room {
this.sendText('The resistance wins!', 'gameplay-text-blue');
}

// Now announce Melron / Moregano illusions
// Now announce Melron / Moregano / Norebo illusions
this.announceIllusionsIfAny();

// Post results of Merlin guesses
Expand Down Expand Up @@ -1377,6 +1379,14 @@ class Game extends Room {
this.specialCards['sire of the sea'].sireHistoryUsernames;
}

let noreboUsername;
if (this.specialCards && this.specialCards[Card.Norebo]) {
const noreboIndex = this.specialCards[Card.Norebo].indexOfPlayerHolding;
if(noreboIndex!=-1) {
noreboUsername = this.anonymizer.anon(this.playersInGame[noreboIndex].username);
}
}

// console.log(this.gameMode);
let botUsernames;
if (this.botSockets !== undefined) {
Expand Down Expand Up @@ -1439,6 +1449,8 @@ class Game extends Room {
sireChain,
sireHistoryUsernames,

noreboUsername,

whoAssassinShot: this.whoAssassinShot,
whoAssassinShot2: this.whoAssassinShot2,

Expand Down Expand Up @@ -2101,6 +2113,19 @@ class Game extends Room {
);
}
}

//Norebo
const noreboIndex = this.specialCards[Card.Norebo].indexOfPlayerHolding;
if (noreboIndex!=-1) {
const noreboUsername = this.anonymizer.anon(this.playersInGame[noreboIndex].username);

console.log(noreboUsername);
this.sendText(
`Norebo was: ${noreboUsername}`,
'gameplay-text-blue',
);
}

}

private usernameIsPlayer(username: string) {
Expand Down
7 changes: 5 additions & 2 deletions src/gameplay/gameEngine/roles/avalon/assassin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Game from '../../game';
import { Phase } from '../../phases/types';
import { IRole, Role } from '../types';
import Assassination from '../../phases/avalon/assassination';
import { Card } from '../../cards/types';


class Assassin implements IRole {
room: Game;
Expand Down Expand Up @@ -30,9 +32,10 @@ class Assassin implements IRole {

if (this.room.gameStarted === true) {
const spies = [];

for (let i = 0; i < this.room.playersInGame.length; i++) {
if (this.room.playersInGame[i].alliance === Alliance.Spy) {
if (this.room.playersInGame[i].alliance === Alliance.Spy
|| i === this.room.specialCards[Card.Norebo].indexOfPlayerHolding
) {
if (this.room.playersInGame[i].role === Role.Oberon) {
// don't add oberon
} else {
Expand Down
5 changes: 4 additions & 1 deletion src/gameplay/gameEngine/roles/avalon/mordred.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Alliance, See } from '../../types';
import { IRole, Role } from '../types';
import Game from '../../game';
import { Card } from '../../cards/types';


class Mordred implements IRole {
room: Game;
Expand All @@ -26,7 +28,8 @@ class Mordred implements IRole {
const spies = [];

for (let i = 0; i < this.room.playersInGame.length; i++) {
if (this.room.playersInGame[i].alliance === Alliance.Spy) {
if (this.room.playersInGame[i].alliance === Alliance.Spy
|| i === this.room.specialCards[Card.Norebo].indexOfPlayerHolding) {
if (this.room.playersInGame[i].role === Role.Oberon) {
// don't add oberon
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/gameplay/gameEngine/roles/avalon/moregano.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Alliance, See } from '../../types';
import { IRole, Role } from '../types';
import Game from '../../game';
import shuffleArray from '../../../../util/shuffleArray';
import { Card } from '../../cards/types';

/**
* Moregano (Resistance) — believes they are Morgana.
Expand Down Expand Up @@ -58,6 +59,10 @@ class Moregano implements IRole {
visibleSpyCount++;
}
}
//add one more visible spy if norebo exists
if(this.room.specialCards[Card.Norebo].indexOfPlayerHolding != -1){
visibleSpyCount++;
}

const othersNeeded = visibleSpyCount - 1;

Expand Down
5 changes: 4 additions & 1 deletion src/gameplay/gameEngine/roles/avalon/morgana.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Alliance, See } from '../../types';
import { IRole, Role } from '../types';
import Game from '../../game';
import { Card } from '../../cards/types';


class Morgana implements IRole {
room: Game;
Expand All @@ -26,7 +28,8 @@ class Morgana implements IRole {
const spies = [];

for (let i = 0; i < this.room.playersInGame.length; i++) {
if (this.room.playersInGame[i].alliance === Alliance.Spy) {
if (this.room.playersInGame[i].alliance === Alliance.Spy
|| i === this.room.specialCards[Card.Norebo].indexOfPlayerHolding) {
if (this.room.playersInGame[i].role === Role.Oberon) {
// don't add oberon
} else {
Expand Down
4 changes: 3 additions & 1 deletion src/gameplay/gameEngine/roles/avalon/spy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alliance, See } from '../../types';
import { IRole, Role } from '../types';
import Game from '../../game';
import { Card } from '../../cards/types';

class Spy implements IRole {
room: Game;
Expand All @@ -27,7 +28,8 @@ class Spy implements IRole {
const spies = [];

for (let i = 0; i < this.room.playersInGame.length; i++) {
if (this.room.playersInGame[i].alliance === Alliance.Spy) {
if (this.room.playersInGame[i].alliance === Alliance.Spy
|| i === this.room.specialCards[Card.Norebo].indexOfPlayerHolding) {
if (this.room.playersInGame[i].role === Role.Oberon) {
// don't add oberon
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/models/gameRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const gameRecordSchema = new mongoose.Schema({
sireChain: [String],
sireHistoryUsernames: [String],

noreboUsername: String,

missionHistory: [String],
numFailsHistory: [Number],
voteHistory: Object,
Expand Down