Files

26 lines
930 B
GDScript

extends "res://scripts/building/piece.gd"
## Bed: E sets your spawn point here. Once it's yours, E at night sleeps until
## morning, if the bed is under a roof with walls around it.
func _build() -> void:
add_to_group("bed") # (a bed or a bedroll: either is a spawn point)
func display_name() -> String:
return String(def.get("name", "Bed"))
## A bedroll: you can sleep in the open (world.sleep_block_reason).
func open_air() -> bool:
return bool(def.get("place", {}).get("open_air", false))
func is_spawn() -> bool:
var w := get_parent().get_parent()
return w.get("bed_spawn") != null and w.has_bed_spawn and (w.bed_spawn as Vector3).distance_to(global_position) < 0.3
func interact_prompt(_player: Node) -> String:
if not is_spawn():
return "%s [E] Set spawn point" % display_name()
return "%s (your spawn point) [E] Sleep" % display_name()
func interact(player: Node) -> void:
Actions.use_bed(player, self)