Skip to content

Commit

Permalink
more roles done
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsSammyM committed Dec 4, 2024
1 parent 13d106f commit 9f6d3b0
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,15 @@ function SwitchSingleAbilityMenuType(props: Readonly<{

switch(available.type) {
case "unit":
return <Button key={key}>
return <Button
key={key}
onClick={()=>{
GAME_MANAGER.sendAbilityInput({
id,
selection: {type: "unit"}
});
}}
>
{translateControllerID(props.id)}
</Button>
case "boolean":{
Expand Down
12 changes: 12 additions & 0 deletions client/src/resources/abilityId.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"role/armorsmith/0": {
"midnight": true
},
"role/vigilante/0": {
"midnight": true
},
"role/veteran/0": {
"midnight": true
},
Expand All @@ -35,6 +38,9 @@
"role/escort/0": {
"midnight": true
},
"role/mayor/0": {
"midnight": false
},
"role/informant/0": {
"midnight": true
},
Expand All @@ -47,6 +53,9 @@
"role/consort/0": {
"midnight": true
},
"role/politician/0": {
"midnight": false
},
"role/scarecrow/0": {
"midnight": true
},
Expand All @@ -56,6 +65,9 @@
"role/kira/0": {
"midnight": true
},
"role/zealot/0": {
"midnight": true
},
"syndicateGunItemShoot": {
"midnight": true
}
Expand Down
9 changes: 4 additions & 5 deletions client/src/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@
"role.mayor.name": "Mayor",
"role.mayor.name:var.0": "Mayors",
"controllerId.mayor.0.name": "Mayor Enfranchise",
"role.mayor.dayTarget": "Enfranchise",

"role.transporter.name": "Transporter",
"role.transporter.name:var.0": "Transporters",
Expand Down Expand Up @@ -335,12 +334,12 @@

"role.vigilante.name": "Vigilante",
"role.vigilante.name:var.0": "Vigilantes",
"role.vigilante.target": "Shoot",
"role.vigilante.roleDataText.suicide": "You killed an innocent townie and will commit suicide tonight",
"role.vigilante.roleDataText": "\\0 bullets remaining",
"role.vigilante.roleDataText.notLoaded": "You are reloading your gun. You can not shoot yet.",
"role.vigilante.youAreSelecting": "You are shooting \\0.",
"role.vigilante.youAreSelecting.null": "You aren't shooting anyone.",
"controllerId.vigilante.0.name": "Vigilante Shoot",

"role.veteran.name": "Veteran",
"role.veteran.name:var.0": "Veterans",
Expand Down Expand Up @@ -419,9 +418,9 @@

"role.consort.name": "Consort",
"role.consort.name:var.0": "Consorts",
"role.consort.target": "Roleblock",
"role.consort.youAreSelecting": "You are roleblocking \\0.",
"role.consort.youAreSelecting.null": "You aren't roleblocking anyone.",
"controllerId.consort.0.name": "Consort Roleblock",

"role.blackmailer.name": "Blackmailer",
"role.blackmailer.name:var.0": "Blackmailers",
Expand Down Expand Up @@ -525,7 +524,7 @@

"role.politician.name": "Politician",
"role.politician.name:var.0": "Politicians",
"role.politician.dayTarget": "Enfranchise",
"controllerId.politician.0.name": "Politician Enfranchise",

"role.drunk.name": "Drunk",
"role.drunk.name:var.0": "Drunks",
Expand Down Expand Up @@ -599,9 +598,9 @@

"role.zealot.name": "Zealot",
"role.zealot.name:var.0": "Zealots",
"role.zealot.target": "Attack",
"role.zealot.youAreSelecting": "You are attacking \\0.",
"role.zealot.youAreSelecting.null": "You aren't attacking anyone.",
"controllerId.zealot.0.name": "Zealot Attack",

"role.martyr.name": "Martyr",
"role.martyr.name:var.0": "Martyrs",
Expand Down
7 changes: 3 additions & 4 deletions server/src/game/ability_input/saved_controllers_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use crate::{
forfeit_vote::ForfeitVote, insider_group::InsiderGroupID,
pitchfork::Pitchfork, syndicate_gun_item::SyndicateGunItem
}, event::on_validated_ability_input_received::OnValidatedAbilityInputReceived, phase::PhaseType, player::PlayerReference, Game
},
packet::ToClientPacket,
vec_map::VecMap, vec_set::VecSet
}, log, packet::ToClientPacket, vec_map::VecMap, vec_set::VecSet
};

use super::*;
Expand Down Expand Up @@ -111,8 +109,9 @@ impl SavedControllersMap{
!available_ability_data.validate_selection(game, &selection) ||
(!overwrite_gray_out && available_ability_data.grayed_out()) ||
!available_ability_data.allowed_players().contains(&actor) ||
*saved_selection == selection
(*saved_selection == selection && selection != AbilitySelection::new_unit())
{
log!(error "saved_controllers_map"; "Invalid input id:{:?} selection:{:?} controller_param:{:?}", id, selection, available_ability_data);
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/game/role/consort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl RoleStateImpl for Consort {
false
)
}
fn default_revealed_groups(self) -> crate::vec_set::VecSet<crate::game::components::insider_group::InsiderGroupID> {
fn default_revealed_groups(self) -> crate::vec_set::VecSet<crate::game::components::insider_group::InsiderGroupID> {
vec![
crate::game::components::insider_group::InsiderGroupID::Mafia
].into_iter().collect()
Expand Down
34 changes: 22 additions & 12 deletions server/src/game/role/mayor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::game::player::PlayerReference;

use crate::game::tag::Tag;
use crate::game::Game;
use super::{GetClientRoleState, RoleState, RoleStateImpl};
use crate::vec_set;
use super::{ControllerID, ControllerParametersMap, GetClientRoleState, Role, RoleStateImpl};

#[derive(Clone, Debug, Default)]
pub struct Mayor {
Expand All @@ -25,28 +26,37 @@ pub(super) const DEFENSE: DefensePower = DefensePower::None;

impl RoleStateImpl for Mayor {
type ClientRoleState = ClientRoleState;
fn do_day_action(self, game: &mut Game, actor_ref: PlayerReference, _target_ref: PlayerReference) {

if !actor_ref.alive(game) || !game.current_phase().is_day() {
fn on_validated_ability_input_received(self, game: &mut Game, actor_ref: PlayerReference, input_player: PlayerReference, ability_input: super::AbilityInput) {
if actor_ref != input_player {return;}
if ability_input.id() != ControllerID::role(actor_ref, Role::Mayor, 0) {
return;
}


game.add_message_to_chat_group(ChatGroup::All, ChatMessageVariant::MayorRevealed { player_index: actor_ref.index() });

actor_ref.set_role_state(game, RoleState::Mayor(Mayor{
actor_ref.set_role_state(game, Mayor{
revealed: true
}));
});
for player in PlayerReference::all_players(game){
player.push_player_tag(game, actor_ref, Tag::Enfranchised);
}
game.count_votes_and_start_trial();
}
fn can_day_target(self, game: &Game, actor_ref: PlayerReference, target_ref: PlayerReference) -> bool{
game.current_phase().is_day() &&
!self.revealed &&
actor_ref == target_ref &&
actor_ref.alive(game) &&
PhaseType::Night != game.current_phase().phase()
fn controller_parameters_map(self, game: &Game, actor_ref: PlayerReference) -> ControllerParametersMap {
ControllerParametersMap::new_controller_fast(
game,
ControllerID::role(actor_ref, Role::Mayor, 0),
super::AvailableAbilitySelection::Unit,
super::AbilitySelection::new_unit(),
!actor_ref.alive(game) ||
self.revealed ||
PhaseType::Night == game.current_phase().phase() ||
PhaseType::Briefing == game.current_phase().phase(),
None,
true,
vec_set![actor_ref]
)
}
}
impl GetClientRoleState<ClientRoleState> for Mayor {
Expand Down
30 changes: 20 additions & 10 deletions server/src/game/role/politician.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use crate::game::player::PlayerReference;
use crate::game::tag::Tag;
use crate::game::win_condition::WinCondition;
use crate::game::Game;
use crate::vec_set;

use super::{GetClientRoleState, RoleState, RoleStateImpl};
use super::{ControllerID, ControllerParametersMap, GetClientRoleState, Role, RoleState, RoleStateImpl};


#[derive(Debug, Clone, Default)]
Expand Down Expand Up @@ -61,11 +62,12 @@ pub(super) const DEFENSE: DefensePower = DefensePower::Armor;

impl RoleStateImpl for Politician {
type ClientRoleState = ClientRoleState;
fn do_day_action(self, game: &mut Game, actor_ref: PlayerReference, _target_ref: PlayerReference) {

if !actor_ref.alive(game) || !game.current_phase().is_day() {
fn on_validated_ability_input_received(self, game: &mut Game, actor_ref: PlayerReference, input_player: PlayerReference, ability_input: super::AbilityInput) {
if actor_ref != input_player {return;}
if ability_input.id() != ControllerID::role(actor_ref, Role::Mayor, 0) {
return;
}


game.add_message_to_chat_group(ChatGroup::All, ChatMessageVariant::MayorRevealed { player_index: actor_ref.index() });

Expand All @@ -78,12 +80,20 @@ impl RoleStateImpl for Politician {
}
game.count_votes_and_start_trial();
}
fn can_day_target(self, game: &Game, actor_ref: PlayerReference, target_ref: PlayerReference) -> bool{
game.current_phase().is_day() &&
!self.revealed &&
actor_ref == target_ref &&
actor_ref.alive(game) &&
PhaseType::Night != game.current_phase().phase()
fn controller_parameters_map(self, game: &Game, actor_ref: PlayerReference) -> ControllerParametersMap {
ControllerParametersMap::new_controller_fast(
game,
ControllerID::role(actor_ref, Role::Politician, 0),
super::AvailableAbilitySelection::Unit,
super::AbilitySelection::new_unit(),
!actor_ref.alive(game) ||
self.revealed ||
PhaseType::Night == game.current_phase().phase() ||
PhaseType::Briefing == game.current_phase().phase(),
None,
true,
vec_set![actor_ref]
)
}

fn on_phase_start(mut self, game: &mut Game, actor_ref: PlayerReference, phase: PhaseType){
Expand Down
26 changes: 19 additions & 7 deletions server/src/game/role/vigilante.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::game::player::PlayerReference;
use crate::game::visit::Visit;

use crate::game::Game;
use super::{Priority, RoleStateImpl, Role, RoleState};
use super::{ControllerID, ControllerParametersMap, Priority, Role, RoleState, RoleStateImpl};

#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -77,15 +77,27 @@ impl RoleStateImpl for Vigilante {
}
actor_ref.set_role_state(game, RoleState::Vigilante(self));
}
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) &&
if let VigilanteState::Loaded { bullets } = &self.state {
fn controller_parameters_map(self, game: &Game, actor_ref: PlayerReference) -> ControllerParametersMap {
let can_shoot = if let VigilanteState::Loaded { bullets } = &self.state {
*bullets >=1
} else {
false
}
};

crate::game::role::common_role::controller_parameters_map_one_player_night(
game,
actor_ref,
false,
!can_shoot,
ControllerID::role(actor_ref, Role::Vigilante, 0)
)
}
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 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::Vigilante, 0),
true
)
}
}
23 changes: 16 additions & 7 deletions server/src/game/role/zealot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::game::player::PlayerReference;
use crate::game::role_list::RoleSet;
use crate::game::visit::Visit;
use crate::game::Game;
use super::{Priority, RoleStateImpl};
use super::{ControllerID, ControllerParametersMap, Priority, Role, RoleStateImpl};


#[derive(Clone, Debug, Default, Serialize)]
Expand All @@ -35,13 +35,22 @@ impl RoleStateImpl for Zealot {
Cult::set_ability_used_last_night(game, Some(CultAbility::Kill));
}
}
fn can_select(self, game: &Game, actor_ref: PlayerReference, target_ref: PlayerReference) -> bool {
if Cult::next_ability(game) != CultAbility::Kill {return false}

crate::game::role::common_role::can_night_select(game, actor_ref, target_ref)
fn controller_parameters_map(self, game: &Game, actor_ref: PlayerReference) -> ControllerParametersMap {
crate::game::role::common_role::controller_parameters_map_one_player_night(
game,
actor_ref,
false,
Cult::next_ability(game) != CultAbility::Kill,
ControllerID::role(actor_ref, Role::Zealot, 0)
)
}
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 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::Zealot, 0),
true
)
}
fn default_revealed_groups(self) -> crate::vec_set::VecSet<crate::game::components::insider_group::InsiderGroupID> {
vec![
Expand Down
10 changes: 10 additions & 0 deletions server/tests/kit/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ impl TestPlayer {
);
}

pub fn send_ability_input_unit_typical(&self)->bool{
self.send_ability_input(
AbilityInput::new(
ControllerID::role(self.player_ref(), self.role(), 0),
AbilitySelection::new_unit()
)
);
true
}

pub fn send_ability_input_one_player_typical(&self, selection: TestPlayer)->bool{
self.send_ability_input(
AbilityInput::new(
Expand Down
Loading

0 comments on commit 9f6d3b0

Please sign in to comment.