mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-14 07:56:32 +00:00
Extract MatchParticipantComponent from Player entity and fix HealthComponent tests
This commit is contained in:
parent
d238c29f76
commit
b339bf34f0
23 changed files with 149 additions and 124 deletions
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue