Skip to content

Commit

Permalink
counterfeiter migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Dec 9, 2024
1 parent ee0e52d commit c342e72
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 98 deletions.
1 change: 0 additions & 1 deletion client/src/game/gameManager.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export type GameManager = {
youWerePossessedMessage: boolean,
yourTargetWasJailedMessage: boolean
): void
sendSetForgerWill(role: Role | null, will: string): void;
sendSetCounterfeiterAction(action: "forge" | "noForge"): void;
sendSetPuppeteerAction(action: PuppeteerAction): void;
sendSetRecruiterAction(action: RecruiterAction): void;
Expand Down
8 changes: 0 additions & 8 deletions client/src/game/gameManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { RoleOutline } from "./roleListState.d";
import translate from "./lang";
import PlayMenu from "../menu/main/PlayMenu";
import { createGameState, createLobbyState } from "./gameState";
import { Role } from "./roleState.d";
import DUMMY_NAMES from "../resources/dummyNames.json";
import { deleteReconnectData } from "./localStorage";
import AudioController from "../menu/AudioController";
Expand Down Expand Up @@ -517,13 +516,6 @@ export function createGameManager(): GameManager {
yourTargetWasJailedMessage: yourTargetWasJailedMessage ?? false
});
},
sendSetForgerWill(role: Role | null, will: string) {
this.server.sendPacket({
type: "setForgerWill",
role: role,
will: will
});
},
sendSetCounterfeiterAction(action: "forge" | "noForge") {
this.server.sendPacket({
type: "setCounterfeiterAction",
Expand Down
8 changes: 0 additions & 8 deletions client/src/game/packet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ export type ToServerPacket = {
} | {
type: "abilityInput",
abilityInput: AbilityInput
} | {
type: "setForgerWill",
role: Role,
will: string
} | {
type: "setCounterfeiterAction",
action: "forge" | "noForge"
Expand Down Expand Up @@ -312,10 +308,6 @@ export type ToServerPacket = {
youWereTransportedMessage: boolean,
youWerePossessedMessage: boolean,
yourTargetWasJailedMessage: boolean
} | {
type: "setForgerWill",
role: Role | null,
will: string
} | {
type: "setPuppeteerAction",
action: PuppeteerAction
Expand Down
6 changes: 0 additions & 6 deletions client/src/game/roleState.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,12 @@ export type RoleState = {
interviewedTarget: PlayerIndex | null
} | {
type: "godfather"
backup: PlayerIndex | null
} | {
type: "impostor"
backup: PlayerIndex | null,
fakeRole: Role
} | {
type: "counterfeiter",
action: "forge" | "noForge",
fakeRole: Role,
fakeWill: string
forgesRemaining: number,
backup: PlayerIndex | null
} | {
type: "recruiter",
action: RecruiterAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ function useDayTargetedPlayers(): PlayerIndex[] {
);

switch (roleState?.type){
case "godfather":
case "counterfeiter":
if (roleState.backup !== null) return [roleState.backup]
break;
case "jailor":
case "kidnapper":
if (roleState.jailedTargetRef !== null) return [roleState.jailedTargetRef]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function RoleSpecificSection(){
case "marksman":
return <MarksmanRoleSpecificMenu roleState={roleState} />;
case "counterfeiter":
return <CounterfeiterMenu/>;
return <CounterfeiterMenu roleState={roleState}/>;
case "forger":
return <Counter
max={3}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
import { ReactElement } from "react";
import React from "react";
import { usePlayerState } from "../../../../../components/useHooks";
import { Role, roleJsonData } from "../../../../../game/roleState.d";
import { Role, roleJsonData, RoleState } from "../../../../../game/roleState.d";
import translate from "../../../../../game/lang";
import StyledText from "../../../../../components/StyledText";
import GAME_MANAGER from "../../../../..";
import { TextDropdownArea } from "../../../../../components/TextAreaDropdown";
import Counter from "../../../../../components/Counter";
import { defaultAlibi } from "../../WillMenu";

export default function CounterfeiterMenu (props: {}): ReactElement {

const action = usePlayerState<"forge"|"noForge">(
playerState => playerState.roleState.type === "counterfeiter" ? playerState.roleState.action : "noForge",
["yourRoleState"]
)!;
const forgesRemaining = usePlayerState<number>(
playerState => playerState.roleState.type === "counterfeiter" ? playerState.roleState.forgesRemaining : 0,
["yourRoleState"]
)!;
const savedRole = usePlayerState<Role>(
playerState => playerState.roleState.type === "counterfeiter" ? playerState.roleState.fakeRole : "jester",
["yourRoleState"]
)!;
const savedWill = usePlayerState<string>(
playerState => playerState.roleState.type === "counterfeiter" ? playerState.roleState.fakeWill : "",
["yourRoleState"]
)!;
export default function CounterfeiterMenu (props: Readonly<{
roleState: RoleState & {type: "counterfeiter"}
}>): ReactElement {
const action = props.roleState.action;
const forgesRemaining = props.roleState.forgesRemaining;

let forgerRoleOptions: JSX.Element[] = [];
for(let role of Object.keys(roleJsonData()) as Role[]){
Expand All @@ -51,28 +35,8 @@ export default function CounterfeiterMenu (props: {}): ReactElement {
}
</select>
</div>
<div className="large-forger-menu-option">
<StyledText>{translate("role.counterfeiter.roleDataText", translate("role."+savedRole+".name"))}</StyledText>
<select
value={savedRole}
onChange={(e)=>{
GAME_MANAGER.sendSetForgerWill(e.target.value as Role, savedWill);
}}
>
{forgerRoleOptions}
</select>
</div>
<Counter max={3} current={forgesRemaining}>
{translate("role.forger.roleDataText", forgesRemaining)}
</Counter>
<TextDropdownArea
open={true}
titleString={translate("forge")}
savedText={savedWill}
onSave={(text)=>{
GAME_MANAGER.sendSetForgerWill(savedRole, text===""?defaultAlibi():text);
}}
cantPost={false}
/>
</div>;
}
5 changes: 3 additions & 2 deletions client/src/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,10 @@

"role.counterfeiter.name": "Counterfeiter",
"role.counterfeiter.name:var.0": "Counterfeiters",
"role.counterfeiter.target": "Attack",
"role.counterfeiter.dayTarget": "Backup",
"role.counterfeiter.roleDataText": "You choose \\0",
"controllerId.counterfeiter.0.name": "Attack",
"controllerId.counterfeiter.1.name": "Role",
"controllerId.counterfeiter.2.name": "Alibi",

"role.recruiter.name": "Recruiter",
"role.recruiter.name:var.0": "Recruiters",
Expand Down
7 changes: 0 additions & 7 deletions server/src/game/on_client_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,6 @@ impl Game {
sender_player_ref.set_role_state(self, RoleState::Hypnotist(hypnotist));
}
},
ToServerPacket::SetForgerWill { role, will } => {
if let RoleState::Counterfeiter(mut counterfeiter) = sender_player_ref.role_state(self).clone(){
counterfeiter.fake_role = role;
counterfeiter.fake_will = will;
sender_player_ref.set_role_state(self, RoleState::Counterfeiter(counterfeiter));
}
},
ToServerPacket::SetCounterfeiterAction {action} => {
if let RoleState::Counterfeiter(mut counterfeiter) = sender_player_ref.role_state(self).clone(){
counterfeiter.action = action;
Expand Down
83 changes: 66 additions & 17 deletions server/src/game/role/counterfeiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ use crate::game::role_list::RoleSet;
use crate::game::visit::Visit;

use crate::game::Game;
use super::{ControllerID, GetClientRoleState, PlayerListSelection, Priority, Role, RoleStateImpl};
use crate::vec_set;
use super::{AbilitySelection, AvailableAbilitySelection, ControllerID, ControllerParametersMap, GetClientRoleState, PlayerListSelection, Priority, Role, RoleOptionSelection, RoleStateImpl, StringSelection};


#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct Counterfeiter{
pub fake_role: Role,
pub fake_will: String,
pub forges_remaining: u8,
pub forged_ref: Option<PlayerReference>,

Expand All @@ -27,8 +26,6 @@ pub struct Counterfeiter{
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClientRoleState{
pub fake_role: Role,
pub fake_will: String,
pub forges_remaining: u8,

pub action: CounterfeiterAction
Expand All @@ -45,8 +42,6 @@ impl Default for Counterfeiter {
Counterfeiter {
forges_remaining: 3,
forged_ref: None,
fake_role: Role::Jester,
fake_will: "".to_owned(),

action: CounterfeiterAction::NoForge,
}
Expand All @@ -65,13 +60,29 @@ impl RoleStateImpl for Counterfeiter {
match priority {
Priority::Deception => {
if self.forges_remaining == 0 || self.action == CounterfeiterAction::NoForge {return}

let actor_visits = actor_ref.untagged_night_visits_cloned(game);
let Some(visit) = actor_visits.first() else{return};

let target_ref = visit.target;

target_ref.set_night_grave_role(game, Some(self.fake_role));
target_ref.set_night_grave_will(game, self.fake_will.clone());
let fake_role = if let Some(RoleOptionSelection(fake_role)) = game.saved_controllers
.get_controller_current_selection_role_option(ControllerID::role(actor_ref, Role::Counterfeiter, 1)) {
fake_role
} else {
None
};

target_ref.set_night_grave_role(game, fake_role);

let fake_alibi = if let Some(StringSelection(string)) = game.saved_controllers
.get_controller_current_selection_string(ControllerID::role(actor_ref, Role::Counterfeiter, 2)) {
string
} else {
"".to_owned()
};
target_ref.set_night_grave_will(game, fake_alibi);

actor_ref.set_role_state(game, Counterfeiter {
forges_remaining: self.forges_remaining.saturating_sub(1),
forged_ref: Some(target_ref),
Expand Down Expand Up @@ -102,12 +113,52 @@ impl RoleStateImpl for Counterfeiter {
_ => {}
}
}
fn can_select(self, game: &Game, actor_ref: PlayerReference, target_ref: PlayerReference) -> bool {
crate::game::role::common_role::can_night_select(game, actor_ref, target_ref) &&
game.day_number() > 1
fn convert_selection_to_visits(self, game: &Game, actor_ref: PlayerReference, _target_refs: Vec<PlayerReference>) -> Vec<Visit> {
crate::game::role::common_role::convert_controller_selection_to_visits(
game,
actor_ref,
ControllerID::role(actor_ref, Role::Counterfeiter, 0),
true
)
}
fn convert_selection_to_visits(self, game: &Game, actor_ref: PlayerReference, target_refs: Vec<PlayerReference>) -> Vec<Visit> {
crate::game::role::common_role::convert_selection_to_visits(game, actor_ref, target_refs, true)
fn controller_parameters_map(self, game: &Game, actor_ref: PlayerReference) -> super::ControllerParametersMap {
crate::game::role::common_role::controller_parameters_map_player_list_night_typical(
game,
actor_ref,
false,
game.day_number() <= 1,
ControllerID::role(actor_ref, Role::Counterfeiter, 0)
).combine_overwrite_owned(
//role
ControllerParametersMap::new_controller_fast(
game,
ControllerID::role(actor_ref, Role::Counterfeiter, 1),
AvailableAbilitySelection::new_role_option(
Role::values().into_iter()
.map(|role| Some(role))
.collect()
),
AbilitySelection::new_role_option(Some(Role::Counterfeiter)),
self.forges_remaining == 0 ||
!actor_ref.alive(game),
None,
false,
vec_set![actor_ref]
)
).combine_overwrite_owned(
//alibi
ControllerParametersMap::new_controller_fast(
game,
ControllerID::role(actor_ref, Role::Counterfeiter, 2),
AvailableAbilitySelection::new_string(),
AbilitySelection::new_string(String::new()),
self.forges_remaining == 0 ||
!actor_ref.alive(game),
None,
false,
vec_set![actor_ref]
)
)
}
fn on_phase_start(self, game: &mut Game, actor_ref: PlayerReference, _phase: PhaseType){
actor_ref.set_role_state(game, Counterfeiter{
Expand Down Expand Up @@ -136,8 +187,6 @@ impl RoleStateImpl for Counterfeiter {
impl GetClientRoleState<ClientRoleState> for Counterfeiter {
fn get_client_role_state(self, _game: &Game, _actor_ref: PlayerReference) -> ClientRoleState {
ClientRoleState{
fake_role: self.fake_role,
fake_will: self.fake_will,
forges_remaining: self.forges_remaining,
action: self.action,
}
Expand Down
2 changes: 0 additions & 2 deletions server/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,6 @@ pub enum ToServerPacket{
you_were_possessed_message: bool,
your_target_was_jailed_message: bool,
},
#[serde(rename_all = "camelCase")]
SetForgerWill{ role: Role, will: String },
SetCounterfeiterAction{action: CounterfeiterAction},
SetPuppeteerAction{action: PuppeteerAction},
SetRecruiterAction{action: RecruiterAction},
Expand Down

0 comments on commit c342e72

Please sign in to comment.