diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index 568ad8f..3f328e9 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -91,6 +91,7 @@ impl Default for GameOptions { let mut opts = HashMap::new(); opts.insert(GameOption::AllowAnyMap, GameOptionValue::Boolean(false)); opts.insert(GameOption::AllowAnyTeam, GameOptionValue::Boolean(false)); + opts.insert(GameOption::FriendlyFire, GameOptionValue::Boolean(true)); Self { values: opts } } } @@ -115,6 +116,8 @@ pub enum GameOption { AllowAnyMap, /// Allow anyone to select anyone's team, not just themselves and the host AllowAnyTeam, + /// Allow anyone to shoot anyone, not just other team's members + FriendlyFire, } impl ToString for GameOption { @@ -122,6 +125,7 @@ impl ToString for GameOption { match self { GameOption::AllowAnyMap => "Allow anyone to select the map", GameOption::AllowAnyTeam => "Allow anyone to select any teams", + GameOption::FriendlyFire => "Friendly fire", } .to_owned() } diff --git a/rust/src/weapon.rs b/rust/src/weapon.rs index e131889..14cfd9f 100644 --- a/rust/src/weapon.rs +++ b/rust/src/weapon.rs @@ -2,7 +2,7 @@ use godot::{classes::AudioStreamPlayer3D, prelude::*}; use serde::{Deserialize, Serialize}; use crate::{ - game_manager::Game, + game_manager::{Game, GameOption}, net::util::cast_ray, player::{DamageSource, IPlayer}, }; @@ -69,9 +69,17 @@ impl Weapon for Raygun { if deal_damage && let Some(target) = target { if let Ok(mut player) = target.collider.try_dynify::() { - player - .dyn_bind_mut() - .take_damage(DamageSource::Player(player_id), 100, true); + self.run_deferred(move |_| { + if let Some(game) = Game::singleton() + && game.bind().opts.is_true(GameOption::FriendlyFire) + { + player.dyn_bind_mut().take_damage( + DamageSource::Player(player_id), + 100, + true, + ); + } + }); } } }