mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-20 03:54:47 +00:00
Extract MatchParticipantComponent from Player entity and fix HealthComponent tests
This commit is contained in:
parent
d238c29f76
commit
b339bf34f0
|
|
@ -14,9 +14,16 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
class_name ExplosiveDamageComponent extends Area3D
|
||||
|
||||
@export var damage : int = 100
|
||||
@export var damage : int = 35
|
||||
@export var impulse_force : int = 1000
|
||||
var damage_dealer : Player
|
||||
var damage_dealer : MatchParticipantComponent
|
||||
|
||||
func _ready() -> void:
|
||||
# this component only scans to apply explosion damage/impulse
|
||||
# at the moment layers: 1 Object, 3 Damage, 4 Objective
|
||||
monitorable = false
|
||||
monitoring = true
|
||||
collision_mask = 0b10000000_00000000_00000000_00001101
|
||||
|
||||
func _physics_process(_delta : float) -> void:
|
||||
for body in get_overlapping_bodies():
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ds1hekx1dq1bg"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/components/explosive_damage_component.gd" id="1_2uehk"]
|
||||
|
||||
[node name="ExplosiveDamage" type="Area3D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 13
|
||||
monitorable = false
|
||||
script = ExtResource("1_2uehk")
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://2t8ql8pkxv6c"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="1_b6ee8"]
|
||||
|
||||
[node name="FlagCarryComponent" type="Node3D"]
|
||||
script = ExtResource("1_b6ee8")
|
||||
|
|
@ -19,17 +19,21 @@ class_name HealthComponent extends Area3D
|
|||
set(value):
|
||||
health = value
|
||||
health_changed.emit(value)
|
||||
@export var _player : Player
|
||||
@export var match_participant_component : MatchParticipantComponent
|
||||
|
||||
signal health_zeroed(killer_id : int)
|
||||
signal health_changed(value : float)
|
||||
|
||||
func _ready() -> void:
|
||||
# only collide with the "Damage" layer, disable monitoring completely
|
||||
collision_layer = 0b00000000_00000000_00000000_00000100
|
||||
monitoring = false
|
||||
collision_mask = 0
|
||||
heal_full()
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func damage(amount : float, damage_dealer_player_id : int, damage_dealer_team_id : int) -> void:
|
||||
if (damage_dealer_team_id == _player.team_id) and (damage_dealer_player_id != _player.player_id):
|
||||
if (damage_dealer_team_id == match_participant_component.team_id) and (damage_dealer_player_id != match_participant_component.player_id):
|
||||
return
|
||||
|
||||
health = clampf(health - amount, 0.0, max_health)
|
||||
|
|
|
|||
|
|
@ -1,8 +0,0 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://bof3mg7wgxrmn"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/components/health_component.gd" id="1_00xis"]
|
||||
|
||||
[node name="HealthComponent" type="Area3D"]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
script = ExtResource("1_00xis")
|
||||
26
entities/components/match_participant_component.gd
Normal file
26
entities/components/match_participant_component.gd
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class_name MatchParticipantComponent extends MultiplayerSynchronizer
|
||||
|
||||
signal player_id_changed(new_player_id : int)
|
||||
signal nickname_changed(new_nickname : String)
|
||||
|
||||
@export var player_id : int:
|
||||
set(value):
|
||||
player_id = value
|
||||
player_id_changed.emit(player_id)
|
||||
@export var team_id : int = 1
|
||||
@export var nickname : String = "<Newblood>":
|
||||
set(value):
|
||||
nickname = value
|
||||
nickname_changed.emit(nickname)
|
||||
|
||||
func _ready() -> void:
|
||||
replication_config = SceneReplicationConfig.new()
|
||||
root_path = "."
|
||||
|
||||
_set_replication_for(NodePath("player_id").get_as_property_path())
|
||||
_set_replication_for(NodePath("team_id").get_as_property_path())
|
||||
_set_replication_for(NodePath("nickname").get_as_property_path())
|
||||
|
||||
func _set_replication_for(property_node_path : NodePath) -> void:
|
||||
replication_config.add_property(property_node_path)
|
||||
replication_config.property_set_replication_mode(property_node_path, SceneReplicationConfig.REPLICATION_MODE_ON_CHANGE)
|
||||
|
|
@ -35,12 +35,6 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
|
|||
|
||||
@export_group("State")
|
||||
@export var player_state : PlayerState = PlayerState.PLAYER_ALIVE
|
||||
@export var player_id : int = 1:
|
||||
set(id):
|
||||
player_id = id
|
||||
$PlayerInput.set_multiplayer_authority(id)
|
||||
@export var team_id : int = 1
|
||||
@export var nickname : String
|
||||
|
||||
@onready var input : PlayerInput = $PlayerInput
|
||||
@onready var camera : Camera3D = $Smoothing/SpringArm3D/Camera3D
|
||||
|
|
@ -56,6 +50,7 @@ enum PlayerState { PLAYER_ALIVE, PLAYER_DEAD }
|
|||
@onready var tp_player : Vanguard = $Smoothing/ThirdPerson/PlayerMesh
|
||||
@onready var _game_settings : Settings = get_node("/root/GlobalSettings")
|
||||
@onready var jetpack_particles : Array = $Smoothing/ThirdPerson/PlayerMesh/JetpackFX.get_children()
|
||||
@onready var match_participant_component : MatchParticipantComponent = $MatchParticipantComponent
|
||||
|
||||
signal died(player : Player, killer_id : int)
|
||||
signal energy_changed(energy : float)
|
||||
|
|
@ -65,17 +60,16 @@ var g : float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m
|
|||
var gravity : Vector3 = g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
|
||||
var _jumping : bool = false
|
||||
|
||||
@rpc("call_local", "reliable")
|
||||
func set_nickname(value : String) -> void:
|
||||
nickname = value
|
||||
|
||||
func _ready() -> void:
|
||||
energy_changed.connect(hud._on_energy_changed)
|
||||
match_participant_component.player_id_changed.connect(_setup_pawn)
|
||||
match_participant_component.player_id_changed.connect(input.update_multiplayer_authority)
|
||||
match_participant_component.nickname_changed.connect(iff.set_nickname)
|
||||
health_component.health_changed.connect(hud._on_health_changed)
|
||||
health_component.health_changed.connect(iff._on_health_changed)
|
||||
health_component.health_changed.emit(health_component.health)
|
||||
health_component.health_zeroed.connect(die)
|
||||
|
||||
energy_changed.connect(hud._on_energy_changed)
|
||||
input.fired_primary.connect(_fire_primary)
|
||||
input.jumped.connect(_jump)
|
||||
input.throwed_flag.connect(_throw_flag)
|
||||
|
|
@ -83,22 +77,22 @@ func _ready() -> void:
|
|||
input.MOUSE_SENSITIVITY = _game_settings.mouse_sensitivity
|
||||
input.inverted_y_axis = _game_settings.inverted_y_axis
|
||||
|
||||
func _setup_pawn(_new_player_id : int) -> void:
|
||||
if _is_pawn():
|
||||
camera.current = true
|
||||
camera.fov = _game_settings.fov
|
||||
pawn_player = self
|
||||
# set the spring arm translation to be about head height level
|
||||
$Smoothing/SpringArm3D.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
|
||||
$Smoothing.remove_child($Smoothing/ThirdPerson)
|
||||
$Smoothing/ThirdPerson.hide()
|
||||
else:
|
||||
# set the iff attachment translation to be about head height level
|
||||
$Smoothing/ThirdPerson/IFFAttachment.transform = Transform3D().translated(Vector3(0, collision_shape.shape.height / 2, 0) * 0.9)
|
||||
remove_child(hud)
|
||||
hud.hide()
|
||||
weapon.hide()
|
||||
|
||||
func _is_pawn() -> bool:
|
||||
return player_id == multiplayer.get_unique_id()
|
||||
return multiplayer.get_unique_id() == match_participant_component.player_id
|
||||
|
||||
func _fire_primary() -> void:
|
||||
if _is_player_dead():
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
[gd_scene load_steps=41 format=3 uid="uid://cbhx1xme0sb7k"]
|
||||
[gd_scene load_steps=42 format=3 uid="uid://cbhx1xme0sb7k"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/player/player.gd" id="1_mk68k"]
|
||||
[ext_resource type="PackedScene" uid="uid://drbefw6akui2v" path="res://entities/player/assets/vanguard.tscn" id="2_beyex"]
|
||||
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_vjqny"]
|
||||
[ext_resource type="PackedScene" uid="uid://bcv81ku26xo" path="res://interfaces/hud/hud.tscn" id="3_ccety"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8co0qa2omjmh" path="res://entities/weapons/space_gun/space_gun.tscn" id="4_6jh57"]
|
||||
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://entities/components/health_component.tscn" id="4_jxn63"]
|
||||
[ext_resource type="Script" path="res://entities/components/match_participant_component.gd" id="6_lrose"]
|
||||
[ext_resource type="Script" path="res://entities/player/player_input.gd" id="6_ymcrr"]
|
||||
[ext_resource type="PackedScene" uid="uid://dsysi2rd3bu76" path="res://interfaces/hud/iffs/iff.tscn" id="7_8hc80"]
|
||||
[ext_resource type="PackedScene" uid="uid://2t8ql8pkxv6c" path="res://entities/components/flag_carry_component.tscn" id="8_ej011"]
|
||||
[ext_resource type="Script" path="res://entities/components/flag_carry_component.gd" id="8_pdfbn"]
|
||||
[ext_resource type="PackedScene" uid="uid://d3l7fvbdg6m5g" path="res://entities/flag/assets/flag.glb" id="9_fce2y"]
|
||||
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="11_k330l"]
|
||||
[ext_resource type="Texture2D" uid="uid://ct1v5iadtpadm" path="res://entities/player/assets/jetpackfx/smoke_01.png" id="12_ypuho"]
|
||||
[ext_resource type="Texture2D" uid="uid://doxo4vfn0bjlp" path="res://entities/player/assets/jetpackfx/smoke_02.png" id="13_wvbf0"]
|
||||
[ext_resource type="Script" path="res://entities/components/health_component.gd" id="14_ctgxn"]
|
||||
[ext_resource type="Texture2D" uid="uid://dmf12llra7aq5" path="res://entities/player/assets/jetpackfx/Particle01.png" id="14_vughy"]
|
||||
|
||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_clur0"]
|
||||
|
|
@ -65,21 +66,12 @@ properties/0/replication_mode = 1
|
|||
properties/1/path = NodePath(".:position")
|
||||
properties/1/spawn = true
|
||||
properties/1/replication_mode = 1
|
||||
properties/2/path = NodePath(".:player_id")
|
||||
properties/2/path = NodePath("HealthComponent:health")
|
||||
properties/2/spawn = true
|
||||
properties/2/replication_mode = 2
|
||||
properties/3/path = NodePath("HealthComponent:health")
|
||||
properties/3/path = NodePath(".:player_state")
|
||||
properties/3/spawn = true
|
||||
properties/3/replication_mode = 2
|
||||
properties/4/path = NodePath(".:player_state")
|
||||
properties/4/spawn = true
|
||||
properties/4/replication_mode = 2
|
||||
properties/5/path = NodePath(".:nickname")
|
||||
properties/5/spawn = true
|
||||
properties/5/replication_mode = 2
|
||||
properties/6/path = NodePath(".:team_id")
|
||||
properties/6/spawn = true
|
||||
properties/6/replication_mode = 2
|
||||
|
||||
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_5j4ew"]
|
||||
properties/0/path = NodePath(".:direction")
|
||||
|
|
@ -238,14 +230,15 @@ monitorable = false
|
|||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Sensor"]
|
||||
shape = ExtResource("2_vjqny")
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
|
||||
|
||||
[node name="HealthComponent" parent="." node_paths=PackedStringArray("_player") instance=ExtResource("4_jxn63")]
|
||||
_player = NodePath("..")
|
||||
[node name="HealthComponent" type="Area3D" parent="." node_paths=PackedStringArray("match_participant_component")]
|
||||
script = ExtResource("14_ctgxn")
|
||||
match_participant_component = NodePath("../MatchParticipantComponent")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="HealthComponent"]
|
||||
shape = ExtResource("2_vjqny")
|
||||
|
||||
[node name="HUD" parent="." instance=ExtResource("3_ccety")]
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
"": SubResource("AnimationLibrary_hg307")
|
||||
|
|
@ -261,6 +254,9 @@ root_path = NodePath(".")
|
|||
replication_config = SubResource("SceneReplicationConfig_5j4ew")
|
||||
script = ExtResource("6_ymcrr")
|
||||
|
||||
[node name="MatchParticipantComponent" type="MultiplayerSynchronizer" parent="."]
|
||||
script = ExtResource("6_lrose")
|
||||
|
||||
[node name="Smoothing" type="Node3D" parent="."]
|
||||
script = ExtResource("11_k330l")
|
||||
target = NodePath("..")
|
||||
|
|
@ -280,19 +276,20 @@ unique_name_in_owner = true
|
|||
|
||||
[node name="SpaceGun" parent="Smoothing/SpringArm3D/Inventory" node_paths=PackedStringArray("holder") instance=ExtResource("4_6jh57")]
|
||||
transform = Transform3D(-1, 0, 2.53518e-06, 0, 1, 0, -2.53518e-06, 0, -1, 0.15, -0.3, -0.55)
|
||||
holder = NodePath("../../../..")
|
||||
holder = NodePath("../../../../MatchParticipantComponent")
|
||||
|
||||
[node name="SpineIKTarget" type="Node3D" parent="Smoothing/SpringArm3D"]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
|
||||
[node name="FlagCarryComponent" parent="Smoothing/SpringArm3D" node_paths=PackedStringArray("sensor", "carrier") instance=ExtResource("8_ej011")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0.150603)
|
||||
[node name="FlagCarryComponent" type="Node3D" parent="Smoothing/SpringArm3D" node_paths=PackedStringArray("sensor", "carrier")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0)
|
||||
visible = false
|
||||
script = ExtResource("8_pdfbn")
|
||||
sensor = NodePath("../../../Sensor")
|
||||
carrier = NodePath("../../..")
|
||||
|
||||
[node name="FlagMesh" parent="Smoothing/SpringArm3D/FlagCarryComponent" instance=ExtResource("9_fce2y")]
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, -0.602515, 0)
|
||||
transform = Transform3D(0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 1.559e-08, -0.462981, -0.178329)
|
||||
|
||||
[node name="ThirdPerson" type="Node3D" parent="Smoothing"]
|
||||
|
||||
|
|
@ -330,6 +327,7 @@ draw_pass_1 = SubResource("QuadMesh_uc7ts")
|
|||
[node name="IFFAttachment" type="Marker3D" parent="Smoothing/ThirdPerson"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.27457, 0)
|
||||
|
||||
[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "attach_point") instance=ExtResource("7_8hc80")]
|
||||
[node name="IFF" parent="Smoothing/ThirdPerson" node_paths=PackedStringArray("player", "match_participant_component", "attach_point") instance=ExtResource("7_8hc80")]
|
||||
player = NodePath("../../..")
|
||||
match_participant_component = NodePath("../../../MatchParticipantComponent")
|
||||
attach_point = NodePath("../IFFAttachment")
|
||||
|
|
|
|||
|
|
@ -26,6 +26,10 @@ signal fired_primary
|
|||
signal throwed_flag
|
||||
|
||||
func _ready() -> void:
|
||||
update_multiplayer_authority(0)
|
||||
|
||||
func update_multiplayer_authority(player_id : int) -> void:
|
||||
set_multiplayer_authority(player_id)
|
||||
var has_authority : bool = is_multiplayer_authority()
|
||||
set_process(has_authority)
|
||||
set_process_unhandled_input(has_authority)
|
||||
|
|
|
|||
|
|
@ -16,13 +16,11 @@ class_name DummyTarget extends RigidBody3D
|
|||
|
||||
@export var respawn_time := 0.0 # seconds
|
||||
|
||||
@onready var health_component: HealthComponent = $HealthComponent
|
||||
@onready var collision_shape_3d: CollisionShape3D = $CollisionShape3D
|
||||
|
||||
var start_pos : Vector3
|
||||
|
||||
func _ready() -> void:
|
||||
health_component.health_zeroed.connect(spawn)
|
||||
start_pos = global_position
|
||||
$TargetMesh/AnimationPlayer.play("gunTwoHanded")
|
||||
|
||||
|
|
@ -30,7 +28,6 @@ func spawn(_killer_id : int) -> void:
|
|||
hide()
|
||||
collision_shape_3d.disabled = true
|
||||
await get_tree().create_timer(respawn_time).timeout
|
||||
health_component.heal_full()
|
||||
global_position = start_pos
|
||||
show()
|
||||
collision_shape_3d.disabled = false
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://dpnu1lvfncx6q"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dpnu1lvfncx6q"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/target_dummy/target_dummy.gd" id="1_iup5v"]
|
||||
[ext_resource type="Shape3D" uid="uid://cb8esdlnottdn" path="res://entities/player/collision_shape.tres" id="2_i5k5j"]
|
||||
[ext_resource type="PackedScene" uid="uid://chuein4frnvwt" path="res://entities/target_dummy/assets/player_mesh.glb" id="4_fuync"]
|
||||
[ext_resource type="PackedScene" uid="uid://bof3mg7wgxrmn" path="res://entities/components/health_component.tscn" id="4_l1exy"]
|
||||
|
||||
[node name="DummyTarget" type="RigidBody3D"]
|
||||
collision_layer = 2147483649
|
||||
|
|
@ -19,7 +18,5 @@ script = ExtResource("1_iup5v")
|
|||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = ExtResource("2_i5k5j")
|
||||
|
||||
[node name="HealthComponent" parent="." instance=ExtResource("4_l1exy")]
|
||||
|
||||
[node name="TargetMesh" parent="." instance=ExtResource("4_fuync")]
|
||||
transform = Transform3D(0.75, 0, 0, 0, 0.75, 0, 0, 0, 0.75, 0, 0, 0)
|
||||
|
|
|
|||
|
|
@ -25,9 +25,10 @@ class_name Projectile extends Node3D
|
|||
@onready var projectile_trail : Trail3D = $Smoothing/ProjectileTrail
|
||||
|
||||
var velocity : Vector3 = Vector3.ZERO
|
||||
var shooter : Player
|
||||
var shooter : MatchParticipantComponent
|
||||
|
||||
func _ready() -> void:
|
||||
assert(shooter)
|
||||
var lifespan_timer : Timer = Timer.new()
|
||||
lifespan_timer.wait_time = lifespan
|
||||
lifespan_timer.one_shot = true
|
||||
|
|
|
|||
|
|
@ -14,13 +14,14 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends Node3D
|
||||
|
||||
var shooter : Player
|
||||
var shooter : MatchParticipantComponent
|
||||
|
||||
@onready var fire : GPUParticles3D = $Fire
|
||||
@onready var explosive_damage : ExplosiveDamageComponent = $ExplosiveDamageComponent
|
||||
var explosion_effect_pending : bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
assert(shooter)
|
||||
explosive_damage.damage_dealer = shooter
|
||||
fire.emitting = true
|
||||
fire.finished.connect(func() -> void: queue_free())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://8atq41j7wd55"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile_explosion.gd" id="1_fp5td"]
|
||||
[ext_resource type="PackedScene" uid="uid://ds1hekx1dq1bg" path="res://entities/components/explosive_damage_component.tscn" id="2_d4sf4"]
|
||||
[ext_resource type="Script" path="res://entities/components/explosive_damage_component.gd" id="2_28ymv"]
|
||||
|
||||
[sub_resource type="Curve" id="Curve_rg204"]
|
||||
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
|
||||
|
|
@ -25,7 +25,8 @@ emission_energy_multiplier = 4.0
|
|||
[sub_resource type="SphereMesh" id="SphereMesh_k3pnh"]
|
||||
material = SubResource("StandardMaterial3D_wpu51")
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_mlo2k"]
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_nj68w"]
|
||||
margin = 0.05
|
||||
radius = 5.0
|
||||
|
||||
[node name="ProjectileExplosion" type="Node3D"]
|
||||
|
|
@ -41,8 +42,8 @@ fixed_fps = 60
|
|||
process_material = SubResource("ParticleProcessMaterial_3mf41")
|
||||
draw_pass_1 = SubResource("SphereMesh_k3pnh")
|
||||
|
||||
[node name="ExplosiveDamageComponent" parent="." instance=ExtResource("2_d4sf4")]
|
||||
damage = 35
|
||||
[node name="ExplosiveDamageComponent" type="Area3D" parent="."]
|
||||
script = ExtResource("2_28ymv")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="ExplosiveDamageComponent"]
|
||||
shape = SubResource("SphereShape3D_mlo2k")
|
||||
shape = SubResource("SphereShape3D_nj68w")
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ extends Node3D
|
|||
class_name SpaceGun
|
||||
|
||||
@export var PROJECTILE : PackedScene
|
||||
@export var holder : Player
|
||||
@export var holder : MatchParticipantComponent
|
||||
|
||||
@onready var nozzle : Node3D = $Nozzle
|
||||
@onready var inventory : Node3D = get_parent()
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
extends Control
|
||||
|
||||
@export var player : Player
|
||||
@export var match_participant_component : MatchParticipantComponent
|
||||
@export var attach_point : Marker3D
|
||||
@export var healthbar_low_health_color : Color = Color(1 ,0 ,0, 0.78)
|
||||
@export var healthbar_mid_health_color : Color = Color(1, 1, 0, 0.78)
|
||||
|
|
@ -28,8 +29,8 @@ extends Control
|
|||
@onready var is_within_los : bool = false
|
||||
@onready var healthbar_fill_stylebox : StyleBoxFlat = _health_bar.get_theme_stylebox("fill")
|
||||
|
||||
func _ready() -> void:
|
||||
_player_name_label.text = player.nickname
|
||||
func set_nickname(new_nickname : String) -> void:
|
||||
_player_name_label.text = new_nickname
|
||||
|
||||
func _process(_delta : float) -> void:
|
||||
# retrieve camera for current viewport
|
||||
|
|
@ -44,7 +45,7 @@ func _process(_delta : float) -> void:
|
|||
# Show the correct IFF based on whether the player we're looking at belongs is a friend or a foe
|
||||
# in other words if their team_ids are the same as the "pawn" player
|
||||
if player.pawn_player != null:
|
||||
if player.pawn_player.team_id == player.team_id:
|
||||
if player.pawn_player.match_participant_component.team_id == player.match_participant_component.team_id:
|
||||
%FoeChevron.hide()
|
||||
%FriendChevron.show()
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -30,17 +30,17 @@ func _unhandled_input(event : InputEvent) -> void:
|
|||
elif event.is_action_released("scoreboard"):
|
||||
hide()
|
||||
|
||||
func add_player(player : Player) -> void:
|
||||
_add_scoreboard_entry.rpc(player.player_id, player.nickname)
|
||||
func add_participant(participant : MatchParticipantComponent) -> void:
|
||||
_add_scoreboard_entry.rpc(participant.player_id, participant.nickname)
|
||||
|
||||
func remove_player(player : Player) -> void:
|
||||
_remove_scoreboard_entry.rpc(player.player_id)
|
||||
func remove_participant(participant : MatchParticipantComponent) -> void:
|
||||
_remove_scoreboard_entry.rpc(participant.player_id)
|
||||
|
||||
func increment_kill_count(player : Player) -> void:
|
||||
_entries[player.player_id].kills += 1
|
||||
func increment_kill_count(participant : MatchParticipantComponent) -> void:
|
||||
_entries[participant.player_id].kills += 1
|
||||
|
||||
func add_score_to_player(player : Player, amount : int) -> void:
|
||||
var player_id : int = player.player_id
|
||||
func add_score_to_player(participant : MatchParticipantComponent, amount : int) -> void:
|
||||
var player_id : int = participant.player_id
|
||||
var entry : ScoreboardEntry = _entries[player_id]
|
||||
_update_scoreboard_entry.rpc(player_id, entry.nickname, entry.kills, entry.score + amount)
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ func unsubscribe_player(player : Player) -> void:
|
|||
player.died.disconnect(_on_player_died)
|
||||
|
||||
func _on_player_died(player : Player, killer_id : int) -> void:
|
||||
if player.player_id != killer_id:
|
||||
if player.match_participant_component.player_id != killer_id:
|
||||
var node_name : String = str(killer_id)
|
||||
if _players.has_node(node_name):
|
||||
var killer : Player = _players.get_node(node_name)
|
||||
_scoreboard.increment_kill_count(killer)
|
||||
_scoreboard.add_score_to_player(killer, 10)
|
||||
_scoreboard.increment_kill_count(killer.match_participant_component)
|
||||
_scoreboard.add_score_to_player(killer.match_participant_component, 10)
|
||||
|
|
|
|||
|
|
@ -38,16 +38,16 @@ func setup(flag : Flag) -> void:
|
|||
flag.dropped.connect(_on_flag_dropped)
|
||||
|
||||
func _on_flag_grabbed(grabber : Player) -> void:
|
||||
grabber.team_id = _team_rabbit.team_id
|
||||
_scoreboard.add_score_to_player(grabber, ON_GRAB_SCORE)
|
||||
grabber.match_participant_component.team_id = _team_rabbit.team_id
|
||||
_scoreboard.add_score_to_player(grabber.match_participant_component, ON_GRAB_SCORE)
|
||||
_flag_carrier_scoring_timer.start()
|
||||
|
||||
func _on_flag_regrabbed(grabber : Player) -> void:
|
||||
grabber.team_id = _team_rabbit.team_id
|
||||
grabber.match_participant_component.team_id = _team_rabbit.team_id
|
||||
|
||||
func _on_flag_dropped(dropper : Player) -> void:
|
||||
dropper.team_id = _team_chasers.team_id
|
||||
dropper.match_participant_component.team_id = _team_chasers.team_id
|
||||
_flag_carrier_scoring_timer.stop()
|
||||
|
||||
func _on_flag_carrier_scoring_timer_timeout(flag : Flag) -> void:
|
||||
_scoreboard.add_score_to_player(flag.last_carrier, ON_HOLD_SCORE)
|
||||
_scoreboard.add_score_to_player(flag.last_carrier.match_participant_component, ON_HOLD_SCORE)
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ script/source = "extends Node
|
|||
|
||||
func _ready() -> void:
|
||||
player_node.died.connect(respawn_player)
|
||||
player_node.match_participant_component.player_id = 1
|
||||
|
||||
func respawn_player(player : Player, _killer_id : int) -> void:
|
||||
player.respawn(player_respawn_location)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ func start_server(config : Dictionary) -> void:
|
|||
# server setup
|
||||
var peer : ENetMultiplayerPeer = ENetMultiplayerPeer.new()
|
||||
peer.create_server(config["port"], MAX_CLIENTS)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
multiplayer.peer_disconnected.connect(remove_player)
|
||||
multiplayer.multiplayer_peer = peer
|
||||
|
||||
_load_map.call_deferred(config["map"], config["nickname"])
|
||||
|
||||
|
|
@ -69,23 +69,24 @@ func respawn_player(player : Player) -> void:
|
|||
player.respawn.rpc(spawn_location)
|
||||
|
||||
func add_player(peer_id : int, nickname : String) -> void:
|
||||
var match_participant_component : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
var player : Player = PLAYER.instantiate()
|
||||
player.died.connect(_on_player_died)
|
||||
player.name = str(peer_id)
|
||||
player.player_id = peer_id
|
||||
player.team_id = ($RabbitScoringComponent as RabbitScoringComponent)._team_chasers.team_id
|
||||
player.nickname = nickname
|
||||
players.add_child(player)
|
||||
player.global_position = _map_manager.get_player_spawn().position
|
||||
player.died.connect(_on_player_died)
|
||||
player.match_participant_component.player_id = peer_id
|
||||
player.match_participant_component.team_id = ($RabbitScoringComponent as RabbitScoringComponent)._team_chasers.team_id
|
||||
player.match_participant_component.nickname = nickname
|
||||
$DeathmatchScoringComponent.subscribe_player(player)
|
||||
scoreboard.add_player(player)
|
||||
scoreboard.add_participant(player.match_participant_component)
|
||||
print("Peer `%s` connected" % player.name)
|
||||
|
||||
func remove_player(peer_id : int) -> void:
|
||||
var node_name : String = str(peer_id)
|
||||
if players.has_node(node_name):
|
||||
var player : Player = players.get_node(node_name)
|
||||
scoreboard.remove_player(player)
|
||||
scoreboard.remove_participant(player.match_participant_component)
|
||||
player.died.disconnect(_on_player_died)
|
||||
$DeathmatchScoringComponent.unsubscribe_player(player)
|
||||
player.queue_free()
|
||||
|
|
|
|||
|
|
@ -16,11 +16,17 @@ extends GutTest
|
|||
|
||||
var _subject : HealthComponent
|
||||
const TEST_MAX_HEALTH : float = 100.0
|
||||
const TEST_PLAYER_ID : int = 1
|
||||
const TEST_TEAM_ID : int = 1
|
||||
|
||||
func before_each() -> void:
|
||||
_subject = HealthComponent.new()
|
||||
watch_signals(_subject)
|
||||
_subject.max_health = TEST_MAX_HEALTH
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
participant.player_id = TEST_PLAYER_ID
|
||||
participant.team_id = TEST_TEAM_ID
|
||||
_subject.match_participant_component = participant
|
||||
add_child(_subject)
|
||||
|
||||
func after_each() -> void:
|
||||
|
|
@ -29,17 +35,27 @@ func after_each() -> void:
|
|||
func test_that_it_has_max_health_when_ready() -> void:
|
||||
assert_eq(_subject.health, _subject.max_health)
|
||||
|
||||
func test_that_it_takes_damage() -> void:
|
||||
var damage_amount : float = 10
|
||||
_subject.damage(damage_amount, -1, 0)
|
||||
func test_that_it_takes_damage_from_opponent_team() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, -1, -1)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
|
||||
|
||||
func test_that_it_takes_no_damage_from_same_team() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, -1, TEST_TEAM_ID)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH)
|
||||
|
||||
func test_that_it_can_self_damage() -> void:
|
||||
var damage_amount : float = 10.0
|
||||
_subject.damage(damage_amount, TEST_PLAYER_ID, TEST_TEAM_ID)
|
||||
assert_eq(_subject.health, TEST_MAX_HEALTH - damage_amount)
|
||||
|
||||
func test_that_it_emits_health_changed_after_damage() -> void:
|
||||
_subject.damage(1, -1, 0)
|
||||
_subject.damage(1, -1, -1)
|
||||
assert_signal_emitted(_subject, 'health_changed')
|
||||
|
||||
func test_that_it_emits_health_zeroed() -> void:
|
||||
_subject.damage(TEST_MAX_HEALTH, -1, 0)
|
||||
_subject.damage(TEST_MAX_HEALTH, -1, -1)
|
||||
assert_signal_emitted_with_parameters(_subject, 'health_zeroed', [-1])
|
||||
|
||||
func test_that_it_heals_fully() -> void:
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@
|
|||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
extends GutTest
|
||||
|
||||
var PLAYER : PackedScene = preload("res://entities/player/player.tscn")
|
||||
var SCOREBOARD : PackedScene = preload("res://interfaces/scoreboard/scoreboard.tscn")
|
||||
|
||||
var _subject : Scoreboard
|
||||
|
|
@ -30,29 +29,29 @@ func test_that_new_scoreboard_is_empty() -> void:
|
|||
assert_eq(_subject._entries, {})
|
||||
|
||||
func test_that_added_entry_is_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
player.nickname = "test_nickname"
|
||||
_subject.add_player(player)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
participant.nickname = "test_nickname"
|
||||
_subject.add_participant(participant)
|
||||
var entries : Array = _subject._entries.values()
|
||||
assert_eq(1, entries.size())
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = entries[0]
|
||||
assert_eq("test_nickname", tested_entry.nickname)
|
||||
assert_eq(0, tested_entry.kills)
|
||||
assert_eq(0, tested_entry.score)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
||||
func test_that_scores_are_added_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_player(player)
|
||||
_subject.add_score_to_player(player, 10)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
_subject.add_participant(participant)
|
||||
_subject.add_score_to_player(participant, 10)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]
|
||||
assert_eq(10, tested_entry.score)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
||||
func test_that_kill_counts_are_incremented_correctly() -> void:
|
||||
var player : Player = PLAYER.instantiate()
|
||||
_subject.add_player(player)
|
||||
_subject.increment_kill_count(player)
|
||||
var participant : MatchParticipantComponent = MatchParticipantComponent.new()
|
||||
_subject.add_participant(participant)
|
||||
_subject.increment_kill_count(participant)
|
||||
var tested_entry : Scoreboard.ScoreboardEntry = _subject._entries.values()[0]
|
||||
assert_eq(1, tested_entry.kills)
|
||||
player.free()
|
||||
participant.free()
|
||||
|
|
|
|||
Loading…
Reference in a new issue