Make spawn protection work

This commit is contained in:
Sofia 2026-07-29 22:26:21 +03:00
parent 6a2d8564d5
commit a71bc513ac
4 changed files with 32 additions and 0 deletions

View File

@ -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)]

View File

@ -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]

View File

@ -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<CharacterBody3D, dyn IPlayer>;
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<T: IPlayer + ICharacterBody3D + WithBaseField> 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))

View File

@ -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]