Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Generic Evil Bug and Assassin Target Bug #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion server/actionHandlers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const enums = require('./enums');
const helpers = require('./helpers');
const otherUtils = require( "./otherUtils");
const roles = require("./roleAssignmentData");

/**
* Creates an array of player objects with roles assigned
Expand Down Expand Up @@ -165,7 +166,7 @@ const handleHandleMissionVoteResult = (room) => {
currentMission.status = enums.MissionStatus.SUCCESS;
}

const gameState = helpers.getGameStateBasedOnMissionStatus(newRoom.boardInfo.missions);
const gameState = helpers.getGameStateBasedOnMissionStatus(newRoom);
//Update the game state
newRoom = helpers.setStatus(newRoom, gameState);
// If the game is not over we need to move things along for the next mission
Expand Down
21 changes: 19 additions & 2 deletions server/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ const isFailedMission = (missionVotes, isDoubleFailRequired) => {
* Can be one of GameState.ASSASSINATION, EVIL_WIN, or TEAM_PROPOSAL if the game continues
* @param missions
*/
const getGameStateBasedOnMissionStatus = (missions) => {
const getGameStateBasedOnMissionStatus = (roomObj) => {
// Check if the game ends
const missions = roomObj.boardInfo.missions
const hasTargets = hasAssassinTargets(roomObj.selectedRoles)
let missionSuccessCount = 0;
let missionFailedCount = 0;
missions.forEach(mission => {
Expand All @@ -215,8 +217,10 @@ const getGameStateBasedOnMissionStatus = (missions) => {
}
});
// Game ends
if (missionSuccessCount >= 3) {
if (missionSuccessCount >= 3 && hasTargets) {
return enums.GameState.ASSASSINATION;
} else if(missionSuccessCount >= 3 && !hasTargets) {
return enums.GameState.GOOD_WIN;
} else if (missionFailedCount >= 3) {
return enums.GameState.EVIL_WIN;
}
Expand Down Expand Up @@ -351,6 +355,19 @@ const getAssassin = (roomObj) => {
return roomObj;
}

/**
* Returns true if the current room has assassinatable roles
* @param {[Role]} selectedRoles
*/
const hasAssassinTargets = (selectedRoles) => {
selectedRoles.forEach(role => {
if (role.isAssassinTarget){
return true
}
})
return false;
}

module.exports = {
setMissionCount, setVoteTrackCount, shufflePlayers: shuffleKingOrder, assignRoles,
setStatus, setKing, setLake, updateKing, reinitializeBoard, setTeamMembers, isFailedMission,
Expand Down
24 changes: 22 additions & 2 deletions server/roleAssignmentData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
merlin: {
roleTitle: 'Merlin',
alignment: 'good',
isAssassinTarget: true,
sees: {
morgana: {
roleTitle: 'Morgana',
Expand All @@ -27,10 +28,12 @@ module.exports = {
assassin: {
roleTitle: 'Assassin',
alignment: 'evil',
roleTitle: 'Agravaine',
alignment: 'evil',
knowsRole: false
},
oberon: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merlin should see both oberon and generic evil

roleTitle: 'Oberon',
genericEvil: {
roleTitle: 'Generic Evil',
alignment: 'evil',
knowsRole: false
}
Expand Down Expand Up @@ -58,6 +61,7 @@ module.exports = {
tristan: {
roleTitle: 'Tristan',
alignment: 'good',
isAssassinTarget: true,
sees: {
iseult: {
roleTitle: 'iseult',
Expand All @@ -70,6 +74,7 @@ module.exports = {
iseult: {
roleTitle: 'Iseult',
alignment: 'good',
isAssassinTarget: true,
sees: {
tristan: {
roleTitle: 'tristan',
Expand All @@ -82,12 +87,14 @@ module.exports = {
titania: {
roleTitle: 'Titania',
alignment: 'good',
isAssassinTarget: false,
sees: {},
description: 'appears as Evil to Evil roles (except Colgrevance).'
},
genericGood: {
roleTitle: 'Generic Good',
alignment: 'good',
isAssassinTarget: false,
sees: {},
description: 'doesn\'t see anyone. The loyalest servant of King Arthur'
},
Expand All @@ -96,6 +103,7 @@ module.exports = {
assassin: {
roleTitle: 'Assassin',
alignment: 'evil',
isAssassinTarget: false,
sees: {
mordred: {
roleTitle: 'Mordred',
Expand Down Expand Up @@ -128,6 +136,7 @@ module.exports = {
mordred: {
roleTitle: 'Mordred',
alignment: 'evil',
isAssassinTarget: false,
sees: {
morgana: {
roleTitle: 'Morgana',
Expand Down Expand Up @@ -160,6 +169,7 @@ module.exports = {
morgana: {
roleTitle: 'Morgana',
alignment: 'evil',
isAssassinTarget: false,
sees: {
mordred: {
roleTitle: 'Mordred',
Expand Down Expand Up @@ -192,6 +202,7 @@ module.exports = {
agravaine: {
roleTitle: 'Agravaine',
alignment: 'evil',
isAssassinTarget: false,
sees: {
mordred: {
roleTitle: 'Mordred',
Expand Down Expand Up @@ -224,6 +235,7 @@ module.exports = {
colgrevance: {
roleTitle: 'Colgrevance',
alignment: 'evil',
isAssassinTarget: false,
sees: {
mordred: {
roleTitle: 'Mordred',
Expand Down Expand Up @@ -261,6 +273,7 @@ module.exports = {
genericEvil: {
roleTitle: 'Generic Evil',
alignment: 'evil',
isAssassinTarget: false,
sees: {
mordred: {
roleTitle: 'Mordred',
Expand All @@ -286,19 +299,26 @@ module.exports = {
roleTitle: 'Titania',
alignment: 'evil',
knowsRole: false
},
genericEvil: {
roleTitle: 'Generic Evil',
alignment: 'evil',
knowsRole: true
}
},
description: 'An evil Minion of Mordred'
},
oberon: {
roleTitle: 'Oberon',
alignment: 'evil',
isAssassinTarget: false,
sees: {},
description: 'is hidden from other Evil roles, but is visible to Merlin'
},
noberon: {
roleTitle: 'NOberon',
alignment: 'evil',
isAssassinTarget: false,
sees: {},
description: 'is hidden from other Evil roles and is also hidden from Merlin'
}
Expand Down