mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
37 lines
1.5 KiB
GDScript
37 lines
1.5 KiB
GDScript
# This file is part of open-fpsz.
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
class_name DeathmatchScoringComponent extends Node
|
|
|
|
@export var ON_KILL_SCORE : int = 10
|
|
|
|
# this is the node that contains all players, typically the one populated via MultiplayerSpawner
|
|
@export var _players : Node
|
|
@export var _scoreboard : Scoreboard
|
|
|
|
# only subscribe once per player, per match
|
|
func subscribe_player(player : Player) -> void:
|
|
player.died.connect(_on_player_died)
|
|
|
|
func unsubscribe_player(player : Player) -> void:
|
|
player.died.disconnect(_on_player_died)
|
|
|
|
func _on_player_died(player : Player, killer_id : int) -> void:
|
|
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.match_participant_component)
|
|
_scoreboard.add_score_to_player(killer.match_participant_component, 10)
|