Skip to content

Commit bf1e8da

Browse files
committed
excluded roles, witch and necromancer are mafia power
1 parent fb51325 commit bf1e8da

File tree

10 files changed

+78
-23
lines changed

10 files changed

+78
-23
lines changed

client/src/components/WikiSearch.tsx

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,26 @@ import React from "react";
22
import ROLES from "./../resources/roles.json";
33
import translate, { langText } from "../game/lang";
44
import "./wikiSearch.css";
5-
import { Role } from "../game/roleState.d";
6-
import { FactionAlignment, getRoleOutlineFromFactionAlignment, translateRoleOutline } from "../game/roleListState.d";
5+
import { Role, getFactionAlignmentFromRole, getFactionFromRole } from "../game/roleState.d";
6+
import { FactionAlignment, RoleOutline, getRoleOutlineFromFactionAlignment, translateRoleOutline } from "../game/roleListState.d";
77
import StyledText from "../components/StyledText";
88
import { HistoryQueue } from "../history";
99
import { regEscape } from "..";
1010

1111
type WikiSearchProps = {
1212
page?: WikiPage,
13+
excludedRoles?: RoleOutline[]
1314
pageChangeCallback?: (page: WikiPage) => void
1415
}
1516

1617
type WikiSearchState = ({
17-
type: "search"
18+
type: "search",
1819
} | {
1920
type: "page",
2021
page: WikiPage,
2122
}) & {
2223
searchQuery: string,
24+
excludedRoles: RoleOutline[]
2325
}
2426

2527
export type WikiPage =
@@ -33,25 +35,30 @@ const PAGES: WikiPage[] = Object.keys(ROLES).map(role => `role/${role}`)
3335
.concat(ARTICLES.map(article => `article/${article}`)) as WikiPage[];
3436

3537
export default class WikiSearch extends React.Component<WikiSearchProps, WikiSearchState> {
38+
3639
private static activeWikis: WikiSearch[] = [];
3740
history: HistoryQueue<WikiSearchState> = new HistoryQueue(10);
41+
3842
constructor(props: WikiSearchProps) {
3943
super(props);
4044

4145
if (props.page !== undefined) {
4246
this.history.push({
4347
type: "search",
4448
searchQuery: "",
49+
excludedRoles: props.excludedRoles ? props.excludedRoles : [],
4550
});
4651
this.state = {
4752
type: "page",
4853
searchQuery: "",
49-
page: props.page
54+
page: props.page,
55+
excludedRoles: props.excludedRoles ? props.excludedRoles : [],
5056
}
5157
} else {
5258
this.state = {
5359
type: "search",
5460
searchQuery: "",
61+
excludedRoles: props.excludedRoles ? props.excludedRoles : [],
5562
};
5663
}
5764
}
@@ -75,6 +82,7 @@ export default class WikiSearch extends React.Component<WikiSearchProps, WikiSea
7582
this.setState({
7683
type: "page",
7784
searchQuery: this.state.searchQuery,
85+
excludedRoles: this.state.excludedRoles,
7886
page
7987
}, () => {
8088
if (this.props.pageChangeCallback !== undefined) {
@@ -84,9 +92,41 @@ export default class WikiSearch extends React.Component<WikiSearchProps, WikiSea
8492
}
8593

8694
renderOpenPageButton(page: WikiPage) {
87-
return <button key={page} onClick={()=>{this.setPage(page)}}>
88-
<StyledText noLinks={true}>{getPageTitle(page)}</StyledText>
89-
</button>
95+
96+
97+
let excludedRolesExact: Role[] = [];
98+
for(let role in ROLES){
99+
let faction = getFactionFromRole(role as Role);
100+
let factionAlignment = getFactionAlignmentFromRole(role as Role);
101+
102+
103+
for(let excludedRoleOutline of this.state.excludedRoles){
104+
switch(excludedRoleOutline.type){
105+
case "exact":
106+
if(excludedRoleOutline.role === role)
107+
excludedRolesExact.push(role as Role);
108+
break;
109+
case "factionAlignment":
110+
if(excludedRoleOutline.factionAlignment === factionAlignment)
111+
excludedRolesExact.push(role as Role);
112+
break;
113+
case "faction":
114+
if(excludedRoleOutline.faction === faction)
115+
excludedRolesExact.push(role as Role);
116+
break;
117+
}
118+
}
119+
}
120+
121+
if(!excludedRolesExact.map((role)=>{return `role/${role}`}).includes(page)){
122+
return <button key={page} onClick={()=>{this.setPage(page)}}>
123+
<StyledText noLinks={true}>{getPageTitle(page)}</StyledText>
124+
</button>
125+
}else{
126+
return <button key={page} onClick={()=>{this.setPage(page)}}>
127+
<span className="keyword-dead">{getPageTitle(page)}</span>
128+
</button>
129+
}
90130
}
91131

92132
getSearchResults(search: string): WikiPage[] {

client/src/components/styledText.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
.keyword-info {
3838
color: lightblue;
3939
}
40-
.keyword-hidden {
40+
.keyword-hiddenRole {
4141
color: whitesmoke;
4242
font-style: italic;
4343
font-weight: bold;

client/src/menu/game/gameScreenContent/WikiMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class WikiMenu extends React.Component<WikiMenuProps, WikiMenuSta
3838
<ContentTab close={ContentMenus.WikiMenu}>{translate("menu.wiki.title")}</ContentTab>
3939

4040
<div className="wiki-menu-search">
41-
<WikiSearch/>
41+
<WikiSearch excludedRoles={this.state.gameState.excludedRoles}/>
4242
</div>
4343
</div>)}
4444
}

client/src/resources/keywords.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"link": "article/phases_and_timeline"
1717
},
1818
"grave.role.cleaned": {
19-
"style": "keyword-hidden",
19+
"style": "keyword-hiddenRole",
2020
"link": "role/janitor"
2121
},
2222
"grave.role.petrified": {
23-
"style": "keyword-hidden"
23+
"style": "keyword-hiddenRole"
2424
},
2525
"suspicious": {
2626
"style": "keyword-evil",

client/src/resources/lang/en_us.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
"chatMessage.playerDied.noWill":"\\0 (\\1) died and was killed by \\2.",
310310
"chatMessage.deathNote": "A note left with the body reads:",
311311
"chatMessage.phaseChange":"\\0 \\1",
312-
"chatMessage.gameOver": "Game Over, win conditions not implemented yet",
312+
"chatMessage.gameOver": "Game Over",
313313

314314
"chatMessage.trialInformation":"\\0 votes needed for the \\1 trials left today.",
315315
"chatMessage.voted":"\\0 voted for \\1.",

client/src/resources/roles.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
"largeRoleSpecificMenu": false
221221
},
222222
"witch": {
223-
"factionAlignment": "mafiaSupport",
223+
"factionAlignment": "mafiaPower",
224224
"suspicious": true,
225225
"roleblockable": false,
226226
"defense": 0,
@@ -230,7 +230,7 @@
230230
"largeRoleSpecificMenu": false
231231
},
232232
"necromancer": {
233-
"factionAlignment": "mafiaSupport",
233+
"factionAlignment": "mafiaPower",
234234
"suspicious": true,
235235
"roleblockable": false,
236236
"defense": 0,

server/src/game/role/necromancer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::game::Game;
1010
use crate::game::team::Team;
1111
use super::{Priority, RoleState, RoleStateImpl};
1212

13-
pub(super) const FACTION_ALIGNMENT: FactionAlignment = FactionAlignment::MafiaSupport;
13+
pub(super) const FACTION_ALIGNMENT: FactionAlignment = FactionAlignment::MafiaPower;
1414
pub(super) const MAXIMUM_COUNT: Option<u8> = Some(1);
1515

1616
#[derive(Clone, Debug, Default, Serialize)]

server/src/game/role/witch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::game::team::Team;
1010
use crate::game::Game;
1111
use super::{Priority, RoleStateImpl, RoleState};
1212

13-
pub(super) const FACTION_ALIGNMENT: FactionAlignment = FactionAlignment::MafiaSupport;
13+
pub(super) const FACTION_ALIGNMENT: FactionAlignment = FactionAlignment::MafiaPower;
1414
pub(super) const MAXIMUM_COUNT: Option<u8> = Some(1);
1515

1616
#[derive(Clone, Debug, Default, Serialize)]

server/src/game/role_list.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,18 @@ impl RoleOutline{
127127
Some(m) => taken_roles.iter().filter(|r2|*r2==r).count() < m.into(),
128128
None => true,
129129
}
130-
131130
)
132131
.collect()
133132
},
134133
RoleOutline::Faction { faction } => {
135134
Role::values().into_iter()
136135
.filter(|r|r.faction_alignment().faction() == *faction)
137-
.filter(|r|!excluded_roles.contains(&RoleOutline::Exact { role: *r }))
136+
.filter(|r|
137+
!(
138+
excluded_roles.contains(&RoleOutline::Exact { role: *r }) ||
139+
excluded_roles.contains(&RoleOutline::FactionAlignment { faction_alignment: r.faction_alignment() })
140+
)
141+
)
138142
.filter(|r|
139143
match r.maximum_count() {
140144
Some(m) => taken_roles.iter().filter(|r2|*r2==r).count() < m.into(),
@@ -146,7 +150,13 @@ impl RoleOutline{
146150
},
147151
RoleOutline::Any => {
148152
Role::values().into_iter()
149-
.filter(|r|!excluded_roles.contains(&RoleOutline::Exact { role: *r }))
153+
.filter(|r|
154+
!(
155+
excluded_roles.contains(&RoleOutline::Exact { role: *r }) ||
156+
excluded_roles.contains(&RoleOutline::FactionAlignment { faction_alignment: r.faction_alignment() }) ||
157+
excluded_roles.contains(&RoleOutline::Faction { faction: r.faction_alignment().faction() })
158+
)
159+
)
150160
.filter(|r|
151161
match r.maximum_count() {
152162
Some(m) => taken_roles.iter().filter(|r2|*r2==r).count() < m.into(),

server/src/lobby.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl Lobby {
215215

216216

217217
let roles: HashSet<_> = roles.drain(..).collect();
218-
let roles: Vec<_> = roles.into_iter().collect();
218+
let roles: Vec<_> = roles.into_iter().filter(|e|*e!=RoleOutline::Any).map(|e|e.clone()).collect();
219219
settings.excluded_roles = roles.clone();
220220
self.send_to_all(ToClientPacket::ExcludedRoles { roles });
221221
}
@@ -301,7 +301,7 @@ impl Lobby {
301301

302302
match &mut self.lobby_state {
303303
LobbyState::Lobby {players, settings} => {
304-
players.remove(&id);
304+
let player = players.remove(&id);
305305

306306
if players.is_empty() {
307307
self.lobby_state = LobbyState::Closed;
@@ -313,24 +313,29 @@ impl Lobby {
313313
}
314314
}
315315

316-
settings.role_list.pop();
316+
if let Some(_player) = player {
317+
settings.role_list.pop();
318+
};
317319

318320
Self::send_players_lobby(players);
319321
for player in players.iter(){
320-
Self::send_settings(player.1, settings)
322+
Self::send_settings(player.1, settings);
321323
}
322324
},
323325
LobbyState::Game {game, players} => {
324326
//TODO proper disconnect from game
325327
let player_index = players.get(&id);
328+
326329
if let Some(game_player) = player_index {
327330
if let Ok(player_ref) = PlayerReference::new(game, game_player.player_index) {
328331
if !player_ref.has_left(game) {
329332
player_ref.lose_connection(game);
330333
}
331334
}
332335
}
336+
333337
players.remove(&id);
338+
334339
if !players.iter().any(|p|p.1.host) {
335340
if let Some(new_host) = players.values_mut().next(){
336341
new_host.host = true;

0 commit comments

Comments
 (0)