Add friendly fire option
This commit is contained in:
parent
d3e082084a
commit
f732472f7c
@ -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()
|
||||
}
|
||||
|
||||
@ -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::<dyn IPlayer>() {
|
||||
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,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user