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: Fix bug where player parties were shown incorrectly on investigation #86

Merged
merged 4 commits into from
Sep 30, 2023
Merged
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
4 changes: 1 addition & 3 deletions backend/src/main/java/game/SecretHitlerGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ private void assignRoles() {
throw new IllegalStateException("Cannot assign roles with too many players.");
}

// 5 6 7 8 9 10
int[] fascistsFromPlayers = new int[] { 1, 1, 2, 2, 3, 3 };
int numFascistsToSet = fascistsFromPlayers[players - MIN_PLAYERS];
int numFascistsToSet = NUM_FASCISTS_FOR_PLAYERS[players];

// Set all players to default state
for (Player player : playerList) {
Expand Down
1 change: 1 addition & 0 deletions backend/src/main/java/server/SecretHitlerServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ private static void onWebSocketMessage(WsMessageContext ctx) {
} else {
obj.put(PARAM_INVESTIGATION, LIBERAL);
}
obj.put(PARAM_TARGET, message.getString(PARAM_TARGET));
ctx.send(obj.toString());
break;

Expand Down
27 changes: 14 additions & 13 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
WEBSOCKET_HEADER,
DEBUG,
PACKET_PONG,
PING_INTERVAL, COMMAND_PING, SERVER_PING, PARAM_ICON, PARAM_DID_VETO_OCCUR
PING_INTERVAL, COMMAND_PING, SERVER_PING, PARAM_ICON, PARAM_DID_VETO_OCCUR, PARAM_INVESTIGATION
} from "./GlobalDefinitions";

import PlayerDisplay, {
Expand Down Expand Up @@ -415,7 +415,17 @@ class App extends Component {
break;

case PACKET_INVESTIGATION:

// Trigger investigation screen when the server responds.
console.log("Investigated player role: " + message[PARAM_INVESTIGATION]);
// Set party to liberal/fascist using sent packet
const party = (message[PARAM_INVESTIGATION]);

this.queueAlert(
<InvestigationAlert party={party}
target={message[PARAM_TARGET]}
hideAlert={this.hideAlertAndFinish}
/>
, false);
break;
case PACKET_PONG:
default:
Expand Down Expand Up @@ -1154,17 +1164,8 @@ class App extends Component {
</ButtonPrompt>
, true);
} else {
// Is President
let target = newState[PARAM_TARGET];
// Set party according to liberal/fascist
let party = (newState[PARAM_PLAYERS][target][PLAYER_IDENTITY] === LIBERAL ? LIBERAL : FASCIST);

this.queueAlert(
<InvestigationAlert party={party}
target={target}
hideAlert={this.hideAlertAndFinish}
/>
, false);
// Is President; do nothing because we handle the
// response directly from the server.
}
break;
case STATE_PP_PEEK: // No additional case is necessary for peeking.
Expand Down
Loading