diff --git a/rust/src/player/buffs.rs b/rust/src/player/buffs.rs index 3b1671c..3fd598c 100644 --- a/rust/src/player/buffs.rs +++ b/rust/src/player/buffs.rs @@ -41,6 +41,15 @@ impl Buffs { } player.set_bubble_color(new_bubble_color); } + + pub fn can_take_damage(&self) -> bool { + for buff in &self.buffs { + match buff.kind { + BuffKind::SpawnProtection => return false, + } + } + true + } } #[derive(Debug, Clone)] diff --git a/rust/src/player/local_player.rs b/rust/src/player/local_player.rs index 60cca4b..aabeb94 100644 --- a/rust/src/player/local_player.rs +++ b/rust/src/player/local_player.rs @@ -366,6 +366,14 @@ impl IPlayer for LocalPlayer { fn set_bubble_color(&mut self, color: Color) { self.set_vignette_color(color); } + + fn get_buffs(&self) -> &Buffs { + &self.buffs + } + + fn get_buffs_mut(&mut self) -> &mut Buffs { + &mut self.buffs + } } #[godot_api] diff --git a/rust/src/player/mod.rs b/rust/src/player/mod.rs index 138a059..bc62f8c 100644 --- a/rust/src/player/mod.rs +++ b/rust/src/player/mod.rs @@ -16,6 +16,7 @@ use crate::{ }, pickup::PickupKind, player::{ + buffs::Buffs, shootable::Shootable, telegrenade::Telegrenade, weapon::{BallWeapon, Weapon, WeaponType}, @@ -75,6 +76,8 @@ pub trait IPlayer { fn telegrenade_teleport(&mut self, to: Vector3) -> bool; fn as_gd(&self) -> DynGd; fn set_bubble_color(&mut self, color: Color); + fn get_buffs(&self) -> &Buffs; + fn get_buffs_mut(&mut self) -> &mut Buffs; } pub trait PlayerCommon { @@ -176,6 +179,10 @@ impl PlayerCommon for T { fn can_take_damage(&self, source: &DamageSource) -> bool { match source { DamageSource::Player(source_player_id) => { + if !self.get_buffs().can_take_damage() { + return false; + } + if let Some(game) = Game::singleton() { let (self_team, source_team) = if let Some(self_player) = game.bind().find_player(self.get_player_id().unwrap_or(0)) diff --git a/rust/src/player/remote_player.rs b/rust/src/player/remote_player.rs index ca1bfb7..a13d64e 100644 --- a/rust/src/player/remote_player.rs +++ b/rust/src/player/remote_player.rs @@ -307,6 +307,14 @@ impl IPlayer for RemotePlayer { mesh.bind_mut().set_bubble_color(color); } } + + fn get_buffs(&self) -> &Buffs { + &self.buffs + } + + fn get_buffs_mut(&mut self) -> &mut Buffs { + &mut self.buffs + } } #[godot_api]