mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-04-29 16:25:35 +00:00
45 lines
1.5 KiB
GDScript
45 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 Flag extends Node3D
|
|
|
|
enum FlagState { FLAG_STATE_ON_STAND, FLAG_STATE_DROPPED, FLAG_STATE_TAKEN }
|
|
|
|
@export var flag_state : FlagState = FlagState.FLAG_STATE_ON_STAND
|
|
|
|
signal grabbed(grabber : Player)
|
|
signal regrabbed(grabber : Player)
|
|
signal dropped(dropper : Player)
|
|
|
|
var last_carrier : Player = null
|
|
@onready var _mesh : Node = $Smoothing/Mesh
|
|
|
|
func can_be_grabbed() -> bool:
|
|
return flag_state != FlagState.FLAG_STATE_TAKEN
|
|
|
|
func grab(grabber : Player) -> void:
|
|
if flag_state != FlagState.FLAG_STATE_TAKEN:
|
|
_mesh.hide()
|
|
flag_state = FlagState.FLAG_STATE_TAKEN
|
|
if (last_carrier == null) or (grabber != last_carrier):
|
|
grabbed.emit(grabber)
|
|
last_carrier = grabber
|
|
else:
|
|
regrabbed.emit(grabber)
|
|
|
|
func drop(dropper : Player) -> void:
|
|
if flag_state == FlagState.FLAG_STATE_TAKEN:
|
|
_mesh.show()
|
|
flag_state = FlagState.FLAG_STATE_DROPPED
|
|
dropped.emit(dropper)
|