diff --git a/levels/prototype_scene.tscn b/levels/prototype_scene.tscn index 406877a..54f663d 100644 --- a/levels/prototype_scene.tscn +++ b/levels/prototype_scene.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=11 format=3 uid="uid://cqrh2cc7m2i7f"] +[gd_scene load_steps=17 format=3 uid="uid://cqrh2cc7m2i7f"] [ext_resource type="Environment" uid="uid://d0cfgtx2yxw13" path="res://environments/prototype_environment.tres" id="1_i6jab"] [ext_resource type="Script" uid="uid://ypgm3aplt78m" path="res://scripts/multiplayer/team_spawner.gd" id="4_pi0y7"] @@ -7,6 +7,9 @@ [ext_resource type="Script" uid="uid://dncldab5y4yod" path="res://scripts/item_spawner.gd" id="6_61ure"] [ext_resource type="PackedScene" uid="uid://cxdgk74ln5xpn" path="res://scenes/weapons/droppable_bomb.tscn" id="6_bno23"] [ext_resource type="Script" uid="uid://bqjv6l7hh0lix" path="res://scripts/multiplayer/spawn_system/dyn_objects_spawner.gd" id="6_oujx2"] +[ext_resource type="Script" uid="uid://dk1gjbuydemmb" path="res://scripts/multiplayer/plant_site/plant_site.gd" id="8_oujx2"] +[ext_resource type="Script" uid="uid://b4cpux52fmx5o" path="res://scripts/multiplayer/plant_site/plant_deadzone.gd" id="9_1wlgq"] +[ext_resource type="Material" uid="uid://c6xa4phihtya2" path="res://materials/Redmat.tres" id="9_ysk2e"] [sub_resource type="Animation" id="Animation_y6i55"] length = 0.001 @@ -22,6 +25,15 @@ _data = { &"main": SubResource("Animation_pi0y7") } +[sub_resource type="BoxShape3D" id="BoxShape3D_ysk2e"] +size = Vector3(15.324341, 1.4935913, 21.381592) + +[sub_resource type="BoxShape3D" id="BoxShape3D_1wlgq"] +size = Vector3(34.28946, 8.172485, 33.813843) + +[sub_resource type="BoxShape3D" id="BoxShape3D_5uqia"] +size = Vector3(9.06966, 8.172485, 13.86731) + [node name="PrototypeScene" type="Node3D"] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] @@ -224,3 +236,43 @@ script = ExtResource("6_oujx2") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -28.858309, 4.6431036, 12.873563) script = ExtResource("6_61ure") item = ExtResource("6_bno23") + +[node name="PlantA" type="Area3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.8366356, 1.4274807, -21.45604) +collision_layer = 0 +collision_mask = 16 +script = ExtResource("8_oujx2") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="PlantA"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 6.484192, 0.24679565, 3.1519775) +shape = SubResource("BoxShape3D_ysk2e") + +[node name="PlantADeadzone" type="Area3D" parent="." node_paths=PackedStringArray("bound_plant")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9.00709, -26.598661) +collision_layer = 0 +collision_mask = 2 +script = ExtResource("9_1wlgq") +bound_plant = NodePath("../PlantA") + +[node name="CollisionShape3D" type="CollisionShape3D" parent="PlantADeadzone"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.292345, -7.2330484, 1.2828445) +shape = SubResource("BoxShape3D_1wlgq") + +[node name="CollisionShape3D2" type="CollisionShape3D" parent="PlantADeadzone"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.8295212, -7.2330484, 25.29969) +shape = SubResource("BoxShape3D_5uqia") + +[node name="CSGBox3D" type="CSGBox3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.8463913, 0.33205223, -18.39247) +size = Vector3(0.49205017, 0.6567383, 21.270905) +material = ExtResource("9_ysk2e") + +[node name="CSGBox3D2" type="CSGBox3D" parent="."] +transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 8.300152, 0.33205223, -28.774506) +size = Vector3(0.49205017, 0.6567383, 15.680862) +material = ExtResource("9_ysk2e") + +[node name="CSGBox3D3" type="CSGBox3D" parent="."] +transform = Transform3D(-1.0000001, 0, 0, 0, 1, 0, 0, 0, -1.0000001, 15.965797, 0.33205223, -18.300764) +size = Vector3(0.49205017, 0.6567383, 21.278908) +material = ExtResource("9_ysk2e") diff --git a/materials/Redmat.tres b/materials/Redmat.tres new file mode 100644 index 0000000..9a41cf5 --- /dev/null +++ b/materials/Redmat.tres @@ -0,0 +1,4 @@ +[gd_resource type="ORMMaterial3D" format=3 uid="uid://c6xa4phihtya2"] + +[resource] +albedo_color = Color(0.9671871, 0, 0.44024095, 1) diff --git a/scenes/weapons/active_bomb.tscn b/scenes/weapons/active_bomb.tscn index b10a616..3f78dfc 100644 --- a/scenes/weapons/active_bomb.tscn +++ b/scenes/weapons/active_bomb.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=3 format=3 uid="uid://dtbpyfdawb02b"] +[gd_scene load_steps=4 format=3 uid="uid://dtbpyfdawb02b"] +[ext_resource type="Script" uid="uid://boftqgpgqf56g" path="res://scripts/weapon_system/bomb/active_bomb.gd" id="1_avh0g"] [ext_resource type="PackedScene" uid="uid://dftij0fdq3lbr" path="res://models/weapons/Bomb.glb" id="1_yh58y"] [sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_yh58y"] @@ -8,9 +9,15 @@ properties/0/spawn = true properties/0/replication_mode = 2 [node name="ActiveBomb" type="Node3D"] +script = ExtResource("1_avh0g") [node name="Bomb" parent="." instance=ExtResource("1_yh58y")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1307683, 0) [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] replication_config = SubResource("SceneReplicationConfig_yh58y") + +[node name="Timer" type="Timer" parent="."] +wait_time = 45.0 +one_shot = true +autostart = true diff --git a/scripts/multiplayer/plant_site/plant_deadzone.gd b/scripts/multiplayer/plant_site/plant_deadzone.gd new file mode 100644 index 0000000..9949e5f --- /dev/null +++ b/scripts/multiplayer/plant_site/plant_deadzone.gd @@ -0,0 +1,9 @@ +extends Area3D + +@export var bound_plant: Area3D + +func _ready() -> void: + if multiplayer.is_server(): + Session.plant_deadzones[bound_plant.name] = self + else: + queue_free() diff --git a/scripts/multiplayer/plant_site/plant_deadzone.gd.uid b/scripts/multiplayer/plant_site/plant_deadzone.gd.uid new file mode 100644 index 0000000..cfa7a00 --- /dev/null +++ b/scripts/multiplayer/plant_site/plant_deadzone.gd.uid @@ -0,0 +1 @@ +uid://b4cpux52fmx5o diff --git a/scripts/multiplayer/plant_site/plant_site.gd b/scripts/multiplayer/plant_site/plant_site.gd new file mode 100644 index 0000000..9c042e7 --- /dev/null +++ b/scripts/multiplayer/plant_site/plant_site.gd @@ -0,0 +1,23 @@ +extends Area3D + +class_name PlantSite + +var players_on_site: Array[int] + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + body_entered.connect(on_body_entered) + body_exited.connect(on_body_exited) + + Session.plants.append(self) + +func on_body_entered(body: Node3D): + if body is Player: + players_on_site.append(int(body.name)) + +func on_body_exited(body: Node3D): + if body is Player: + players_on_site.erase(int(body.name)) + +func is_player_on_site(id: int): + return players_on_site.has(id) diff --git a/scripts/multiplayer/plant_site/plant_site.gd.uid b/scripts/multiplayer/plant_site/plant_site.gd.uid new file mode 100644 index 0000000..aa43544 --- /dev/null +++ b/scripts/multiplayer/plant_site/plant_site.gd.uid @@ -0,0 +1 @@ +uid://dk1gjbuydemmb diff --git a/scripts/multiplayer/session.gd b/scripts/multiplayer/session.gd index e5febe8..6cd00d2 100644 --- a/scripts/multiplayer/session.gd +++ b/scripts/multiplayer/session.gd @@ -12,6 +12,8 @@ const DEFENCE_LAYER: int = 0b100000 var player_nodes: Dictionary[int,Player] = {} var dynamic_objects_spawner: MultiplayerSpawner +var plants: Array[PlantSite] +var plant_deadzones: Dictionary[StringName, Area3D] ## Spawns dynamic object at game scene [br] ## Dictionary keys: [br] @@ -76,4 +78,23 @@ func shoot_internal(id:int , damage: int) -> void: var collision = space.intersect_ray(ray) if collision != {} and collision["collider"] is Player: collision["collider"].take_damage.rpc_id(int(collision["collider"].name),damage) - + +func is_on_site() -> bool: + for plant in plants: + if plant.is_player_on_site(multiplayer.get_unique_id()): + return true + return false + +func get_site() -> PlantSite: + for plant in plants: + if plant.is_player_on_site(multiplayer.get_unique_id()): + return plant + return null + +func kill_site(site: StringName) -> void: + if multiplayer.is_server() == false: + return + + for body in plant_deadzones[site].get_overlapping_bodies(): + if body is Player: + body.die() diff --git a/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd b/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd index 01fd6e4..c7fd947 100644 --- a/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd +++ b/scripts/multiplayer/spawn_system/dyn_objects_spawner.gd @@ -15,5 +15,10 @@ func request_spawn(data: Variant) -> Node: node.slot = data.slot node.apply_impulse(data.impulse) + + for key in data.keys(): + if key in ["scene","ammo","remaining_ammo","slot","position","rotation"]: + continue + node.set(key,data[key]) return node diff --git a/scripts/weapon_system/bomb/active_bomb.gd b/scripts/weapon_system/bomb/active_bomb.gd new file mode 100644 index 0000000..12b8d7e --- /dev/null +++ b/scripts/weapon_system/bomb/active_bomb.gd @@ -0,0 +1,13 @@ +extends Node3D + +var plant: StringName + +func _ready() -> void: + if multiplayer.is_server(): + $Timer.timeout.connect(on_timeout) + +func on_timeout(): + if multiplayer.is_server() == false: + return + + Session.kill_site(plant) diff --git a/scripts/weapon_system/bomb/active_bomb.gd.uid b/scripts/weapon_system/bomb/active_bomb.gd.uid new file mode 100644 index 0000000..9c3e1d7 --- /dev/null +++ b/scripts/weapon_system/bomb/active_bomb.gd.uid @@ -0,0 +1 @@ +uid://boftqgpgqf56g diff --git a/scripts/weapon_system/bomb/bomb_idle_state.gd b/scripts/weapon_system/bomb/bomb_idle_state.gd index 319c383..0d2c89c 100644 --- a/scripts/weapon_system/bomb/bomb_idle_state.gd +++ b/scripts/weapon_system/bomb/bomb_idle_state.gd @@ -8,5 +8,5 @@ func exit() -> void: pass func state_input(event: InputEvent) -> void: - if event.is_action("plr_bomb"): + if event.is_action("plr_bomb") and Session.is_on_site(): transition.emit("Plant") diff --git a/scripts/weapon_system/bomb/bomb_main_state.gd b/scripts/weapon_system/bomb/bomb_main_state.gd index 786a185..5aac64e 100644 --- a/scripts/weapon_system/bomb/bomb_main_state.gd +++ b/scripts/weapon_system/bomb/bomb_main_state.gd @@ -14,7 +14,7 @@ func exit(): func on_animation_finished(animation: StringName): if animation == machine.animation_prefix + "plant": - Session.spawn({"scene": active_bomb, "position": machine.player_camera.get_parent().global_position}) + Session.spawn({"scene": active_bomb, "position": machine.player_camera.get_parent().global_position,"plant": Session.get_site().name}) machine.ammo -= 1 return_to_previous.emit()