diff --git a/godot/scenes/misc/goal.tscn b/godot/scenes/misc/goal.tscn index 5e09c53..cb0086d 100644 --- a/godot/scenes/misc/goal.tscn +++ b/godot/scenes/misc/goal.tscn @@ -22,7 +22,7 @@ radius = 2.0 [node name="goal" type="Goal" unique_id=177528504 node_paths=PackedStringArray("mesh")] mesh = NodePath("mesh_instance_3d") collision_layer = 8 -collision_mask = 8 +collision_mask = 11 [node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=587608036] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) diff --git a/rust/src/map/goal.rs b/rust/src/map/goal.rs index 688c1db..3e6775c 100644 --- a/rust/src/map/goal.rs +++ b/rust/src/map/goal.rs @@ -4,7 +4,9 @@ use godot::{ }; use crate::{ - game::Game, net::network_manager::NetworkManager, player::ball::Ball, + game::Game, + net::network_manager::NetworkManager, + player::{IPlayer, ball::Ball, weapon::WeaponType}, replay::StandaloneReplayManager, }; @@ -55,10 +57,23 @@ impl Goal { } fn on_enter(&self, node: Gd) { - if let Ok(mut ball) = node.try_cast::() + if !NetworkManager::singleton().bind().is_host() { + return; + } + let mut is_goal = None; + if let Ok(mut ball) = node.clone().try_cast::() && !ball.bind().entered_goal { ball.bind_mut().entered_goal = true; + is_goal = Some(ball.bind().dropper.unwrap_or(0)); + } else if let Ok(player) = node.clone().try_dynify::() + && let Some(weapon) = player.dyn_bind().get_weapon() + && weapon.dyn_bind().get_type() == WeaponType::Ball + { + is_goal = Some(player.dyn_bind().get_player_id().unwrap_or(0)); + } + + if let Some(player_id) = is_goal { if let Some(mut game) = Game::singleton() { let teams = game .bind() @@ -68,11 +83,8 @@ impl Goal { .map(|(id, _)| id as u8) .filter(|id| *id != self.team) .collect(); - if NetworkManager::singleton().bind().is_host() { - game.bind_mut().respawn_ball(); - game.bind_mut() - .handle_goal(ball.bind().dropper.unwrap_or(0), teams); - } + game.bind_mut().respawn_ball(); + game.bind_mut().handle_goal(player_id, teams); } } }