52 lines
1.6 KiB
GDScript
52 lines
1.6 KiB
GDScript
extends "res://scripts/building/piece.gd"
|
|
## Grave: left where you died, holding everything you carried. Open it with E
|
|
## to take your things back; it crumbles once empty.
|
|
##
|
|
## On a server it has an owner (whoever died), and only they can open it
|
|
## (player_net.gd asks use_block_reason). Server rules for friends come in M2.6.
|
|
|
|
var inventory := Inventory.new(40)
|
|
var owner_id := ""
|
|
var owner_name := ""
|
|
|
|
func _build() -> void:
|
|
inventory.changed.connect(_on_changed)
|
|
|
|
func _mine() -> bool:
|
|
return owner_id.is_empty() or Net.state != "connected" or owner_id == Net.get_identity().player_id
|
|
|
|
func display_name() -> String:
|
|
return "Your grave" if _mine() else "%s's grave" % owner_name
|
|
|
|
func interact_prompt(_player: Node) -> String:
|
|
if not _mine():
|
|
return "%s's grave" % owner_name
|
|
return "Your grave [E] Recover belongings"
|
|
|
|
func interact(player: Node) -> void:
|
|
if _mine():
|
|
player.open_inventory(self)
|
|
else:
|
|
Actions.notify.emit("That's %s's grave" % owner_name)
|
|
|
|
## Server: why player `id` can't take from it ("" = they can).
|
|
func use_block_reason(id: String) -> String:
|
|
if owner_id.is_empty() or owner_id == id:
|
|
return ""
|
|
return "That's %s's grave" % owner_name
|
|
|
|
func save_extra() -> Dictionary:
|
|
return {"owner_id": owner_id, "owner_name": owner_name} if not owner_id.is_empty() else {}
|
|
|
|
func load_extra(d: Dictionary) -> void:
|
|
owner_id = String(d.get("owner_id", ""))
|
|
owner_name = String(d.get("owner_name", ""))
|
|
|
|
func _on_changed() -> void:
|
|
if WorldNet.world != null:
|
|
return # online, the server crumbles it (world_net.gd)
|
|
for s in inventory.slots:
|
|
if s != null:
|
|
return
|
|
queue_free.call_deferred()
|