M2.4: the server decides online (characters, inventory, stats, death, owned graves, per-player saves); death screen with Respawn after 3 s

This commit is contained in:
Paul Bailey
2026-11-04 19:18:31 +00:00
parent 8e8f10eb96
commit 35a656e996
16 changed files with 1124 additions and 477 deletions

View File

@@ -1,20 +1,46 @@
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"
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:
player.open_inventory(self)
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: