diff --git a/godot/maps/diner.tres b/godot/maps/diner.tres index 8f8741b..508e69d 100644 --- a/godot/maps/diner.tres +++ b/godot/maps/diner.tres @@ -1,6 +1,6 @@ [gd_resource type="MapResource" format=3 uid="uid://bsjoandgu476y"] -[ext_resource type="PackedScene" uid="uid://ylj40hkjsgjc" path="res://maps/diner.tscn" id="1_yteo6"] +[ext_resource type="PackedScene" uid="uid://ylj40hkjsgjc" path="res://maps/diner/diner.tscn" id="1_yteo6"] [resource] name = "Diner" diff --git a/godot/maps/diner/diner.tscn b/godot/maps/diner/diner.tscn index a1761f4..aa26718 100644 --- a/godot/maps/diner/diner.tscn +++ b/godot/maps/diner/diner.tscn @@ -143,6 +143,9 @@ volumetric_fog_albedo = Color(0.8156863, 0.6392157, 0.29803923, 1) [sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_j6hgl"] exposure_multiplier = 2.641 +[sub_resource type="BoxShape3D" id="BoxShape3D_1cgct"] +size = Vector3(1000, 1, 1000) + [node name="diner" type="Map" unique_id=1971127396 node_paths=PackedStringArray("spawner")] spawner = NodePath("spawner") local_player = ExtResource("1_wffmg") @@ -252,3 +255,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) [node name="spawner" type="Node3D" parent="." unique_id=2117785064] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.739436, 0.76123095, 5.0619516) + +[node name="killbox" type="Killbox" parent="." unique_id=1750431583] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -7.531834, 0) + +[node name="collision_shape_3d" type="CollisionShape3D" parent="killbox" unique_id=55584443] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.1150565, 0) +shape = SubResource("BoxShape3D_1cgct") diff --git a/rust/src/killbox.rs b/rust/src/killbox.rs new file mode 100644 index 0000000..721dbd7 --- /dev/null +++ b/rust/src/killbox.rs @@ -0,0 +1,32 @@ +use godot::{ + classes::{Area3D, IArea3D}, + prelude::*, +}; + +use crate::{net::network_manager::NetworkManager, player::IPlayer}; + +#[derive(GodotClass)] +#[class(base=Area3D, init)] +pub struct Killbox { + base: Base, +} + +#[godot_api] +impl IArea3D for Killbox { + fn ready(&mut self) { + self.base() + .signals() + .body_entered() + .connect_other(self, |s, body| s.kill(body)); + } +} + +impl Killbox { + pub fn kill(&mut self, node: Gd) { + if let Ok(mut player) = node.try_dynify::() { + if NetworkManager::singleton().bind().is_host() { + player.dyn_bind_mut().take_damage(0, 1000, true); + } + } + } +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 472b199..01fd242 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1,6 +1,7 @@ use godot::prelude::*; pub mod game_manager; +pub mod killbox; pub mod map; pub mod map_resource; pub mod net; diff --git a/rust/src/net/network_manager.rs b/rust/src/net/network_manager.rs index ffd65e7..8eb4e0a 100644 --- a/rust/src/net/network_manager.rs +++ b/rust/src/net/network_manager.rs @@ -449,6 +449,18 @@ impl NetworkManager { get_autoload_by_name::(NETWORK_SINGLETON_NAME) } + pub fn is_host(&self) -> bool { + if let Some(peer) = &self.peer { + if let PeerKind::Server(_, _) = peer { + true + } else { + false + } + } else { + false + } + } + pub fn host(&mut self, port: u16) { if self.peer.is_none() { let mut cli = CommandLinePanel::singleton();