47 lines
1.7 KiB
GDScript
47 lines
1.7 KiB
GDScript
class_name WorkZoneBuildingArea
|
|
extends Area2D
|
|
|
|
# ============================================================================
|
|
# WorkZoneBuildingArea.gd - 打工区建筑交互入口
|
|
# ============================================================================
|
|
# 为打工区建筑提供统一交互数据,玩家面对入口按交互键时由 PlayerController 调用。
|
|
# ============================================================================
|
|
|
|
const INTERACTION_COLLISION_LAYER: int = 2
|
|
const InteractionAnchorUtil = preload("res://_Core/utils/InteractionAnchor.gd")
|
|
|
|
@export var buildingId: String = ""
|
|
@export var buildingTitle: String = ""
|
|
@export var buildingRole: String = ""
|
|
@export var interactionDistance: float = 150.0
|
|
|
|
func _ready() -> void:
|
|
collision_layer = INTERACTION_COLLISION_LAYER
|
|
collision_mask = 0
|
|
add_to_group("whaletown_interactable")
|
|
|
|
func get_interaction_actions(player: Node2D) -> Array[Dictionary]:
|
|
var anchor_position: Vector2 = InteractionAnchorUtil.get_position(self)
|
|
var distance: float = anchor_position.distance_to(player.global_position)
|
|
if distance > interactionDistance:
|
|
return []
|
|
return [{
|
|
"id": "building:%s" % buildingId,
|
|
"title": "使用 %s" % (buildingTitle if not buildingTitle.is_empty() else "设施"),
|
|
"distance": distance,
|
|
"priority": 30,
|
|
"callback": Callable(self, "interact"),
|
|
}]
|
|
|
|
func interact() -> void:
|
|
var payload := {
|
|
"buildingId": buildingId,
|
|
"title": buildingTitle,
|
|
"role": buildingRole,
|
|
"nodePath": get_path(),
|
|
}
|
|
var eventSystem := get_node_or_null("/root/EventSystem")
|
|
if eventSystem != null:
|
|
eventSystem.call("emit_event", EventNames.OBJECT_INTERACTED, payload)
|
|
print("WorkZone building interacted: %s - %s" % [buildingTitle, buildingRole])
|