# 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 . class_name RabbitScoringComponent extends Node @export var ON_GRAB_SCORE : int = 10 @export var ON_HOLD_SCORE : int = 10 @export var HOLD_SCORING_TIMER : float = 10.0 # seconds @export var _scoreboard : Scoreboard var _flag_carrier_scoring_timer : Timer = Timer.new() var _team_chasers : Team var _team_rabbit : Team func _ready() -> void: _flag_carrier_scoring_timer.wait_time = HOLD_SCORING_TIMER add_child(_flag_carrier_scoring_timer) _team_chasers = Team.new(0) _team_rabbit = Team.new(1) # setup only once per match, per flag (tested only with one flag so far) func setup(flag : Flag) -> void: _flag_carrier_scoring_timer.timeout.connect(_on_flag_carrier_scoring_timer_timeout.bind(flag)) flag.grabbed.connect(_on_flag_grabbed) flag.regrabbed.connect(_on_flag_regrabbed) flag.dropped.connect(_on_flag_dropped) func _on_flag_grabbed(grabber : Player) -> void: 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.match_participant_component.team_id = _team_rabbit.team_id func _on_flag_dropped(dropper : Player) -> void: 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.match_participant_component, ON_HOLD_SCORE)