diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index c4c5733..b1be4f2 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -167,6 +167,10 @@ impl Default for GameOptions { opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false)); opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true)); opts.insert(GameOption::GoalsNeededToWin, GameOptionValue::Number(10.)); + opts.insert( + GameOption::TelegrenadesAllowed, + GameOptionValue::Boolean(true), + ); Self { values: opts } } } @@ -195,6 +199,8 @@ pub enum GameOption { FriendlyFire, /// The number of goals needed to win a match GoalsNeededToWin, + /// Whether telegrenades are allowed or not. + TelegrenadesAllowed, } impl ToString for GameOption { @@ -204,6 +210,7 @@ impl ToString for GameOption { GameOption::AllowAnyTeam => "Allow anyone to select any teams", GameOption::FriendlyFire => "Friendly fire", GameOption::GoalsNeededToWin => "Goals needed to win", + GameOption::TelegrenadesAllowed => "Telegrenades allowed", } .to_owned() } diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index 3f22285..2846067 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -10,7 +10,7 @@ use godot::{ }; use crate::{ - game_manager::{Game, GameManager}, + game_manager::{Game, GameManager, GameOption}, game_settings::{GameSettings, GameSettingsManager}, killbox::KillboxKind, net::{ @@ -92,6 +92,7 @@ pub struct LocalPlayer { telegrenade_cd: f64, telegrenade: Option>, telegrenade_cd_remaining: f64, + telegrenades_allowed: bool, base: Base, } @@ -170,6 +171,10 @@ impl IPlayer for LocalPlayer { fn apply_look_up(&mut self, _look: f32) {} fn try_throw_telegrenade(&mut self, to: Vector3) -> bool { + if !self.telegrenades_allowed { + return false; + } + if self.telegrenade_cd_remaining > 0. { return false; } @@ -385,6 +390,12 @@ impl ICharacterBody3D for LocalPlayer { .on_lock_changed() .connect_other(self, |s, lock| s.set_lock(lock)); } + + self.telegrenades_allowed = if let Some(game) = Game::singleton() { + game.bind().opts.is_true(GameOption::TelegrenadesAllowed) + } else { + false + }; } fn process(&mut self, delta: f64) { @@ -499,7 +510,7 @@ impl ICharacterBody3D for LocalPlayer { fn input(&mut self, event: Gd) { if self.locked { - if event.is_action_pressed("throw_telegrenade") { + if event.is_action_pressed("throw_telegrenade") && self.telegrenades_allowed { if let Some(telegrenade) = &mut self.telegrenade { if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer { match peer { diff --git a/rust/src/player/remote_player.rs b/rust/src/player/remote_player.rs index 53fd124..5840b5e 100644 --- a/rust/src/player/remote_player.rs +++ b/rust/src/player/remote_player.rs @@ -8,6 +8,7 @@ use godot::{ }; use crate::{ + game_manager::{Game, GameOption}, killbox::KillboxKind, pickup::PickupKind, player::{ @@ -68,6 +69,7 @@ pub struct RemotePlayer { telegrenade_cd: f64, telegrenade: Option>, telegrenade_cd_remaining: f64, + telegrenades_allowed: bool, base: Base, } @@ -141,6 +143,10 @@ impl IPlayer for RemotePlayer { } fn try_throw_telegrenade(&mut self, to: Vector3) -> bool { + if !self.telegrenades_allowed { + return false; + } + if self.telegrenade_cd_remaining > 0. { return false; } @@ -302,6 +308,12 @@ impl ICharacterBody3D for RemotePlayer { self.swap_weapon(WeaponType::Raygun, false); self.update_health_bar(); + + self.telegrenades_allowed = if let Some(game) = Game::singleton() { + game.bind().opts.is_true(GameOption::TelegrenadesAllowed) + } else { + false + }; } fn process(&mut self, delta: f64) {