M2.6: server rules (PvP, raiding, locks and friends, death penalty, difficulty, wolf grace), chat, admin commands, server console

This commit is contained in:
Paul Bailey
2026-11-04 22:54:40 +00:00
parent 47fc116839
commit 2ab79b68c6
26 changed files with 1195 additions and 57 deletions

View File

@@ -204,9 +204,14 @@ func _on_player_died() -> void:
const RESPAWN_DELAY := 3.0 ## seconds on the death screen before you can respawn
var dead_waiting := false ## dead, on the death screen
static func _death_note(has_items: bool, to_bed: bool) -> String:
return "%s\nYou'll wake %s." % ["Your belongings are in a grave where you fell." if has_items else "You had nothing on you.",
"at your bed" if to_bed else "at the island start"]
static func _death_note(has_items: bool, to_bed: bool, penalty: String = "grave") -> String:
var things := "You had nothing on you."
if penalty == "keep":
things = "You keep everything you were carrying."
elif has_items:
things = "Everything you carried is scattered where you fell: anyone can pick it up." if penalty == "drop_all" \
else "Your belongings are in a grave where you fell."
return "%s\nYou'll wake %s." % [things, "at your bed" if to_bed else "at the island start"]
## Respawn (the death screen's button): at your bed, or the island start.
func respawn_after_death() -> void:
@@ -225,13 +230,13 @@ func respawn_after_death() -> void:
player.survival.reset_after_death()
## Online: the server says we died. Same screen; Respawn asks the server.
func died_online(text: String, has_items: bool, to_bed: bool) -> void:
func died_online(text: String, has_items: bool, to_bed: bool, penalty: String = "grave") -> void:
dead_waiting = true
player.velocity = Vector3.ZERO
player.set_physics_process(false)
if hud != null:
hud.close_screens()
hud.show_death(text, _death_note(has_items, to_bed), RESPAWN_DELAY, func(): PlayerNet.ask("respawn"))
hud.show_death(text, _death_note(has_items, to_bed, penalty), RESPAWN_DELAY, func(): PlayerNet.ask("respawn"))
else:
get_tree().create_timer(RESPAWN_DELAY + 0.1).timeout.connect(func(): PlayerNet.ask("respawn"))
@@ -349,6 +354,7 @@ func _on_terrain_ready() -> void:
wolves.name = "Wolves"
add_child(wolves)
wolves.setup(self, den)
apply_rules()
return
_respawn()
if Saves.has_world():
@@ -373,6 +379,16 @@ func _on_terrain_ready() -> void:
wolves.setup(self, den)
_maybe_capture()
## A server's rules for the island (at start-up, and after an admin's /set).
func apply_rules() -> void:
var R = preload("res://scripts/net/rules.gd")
if wolves != null:
wolves.den_day = R.grace_days()
wolves.hunt_day = R.grace_days() + 1
wolves.pack_bonus = int(R.difficulty("pack"))
for p in PlayerNet.proxies.values():
p.survival.drain_mult = R.difficulty("drain")
func _process(delta: float) -> void:
if menu_mode:
# Slow orbit over the valley, looking toward the lake.
@@ -514,6 +530,9 @@ func piece_entry(piece: Node3D) -> Dictionary:
entry["extra"] = piece.save_extra()
if piece.has_meta("nid"):
entry["nid"] = int(piece.get_meta("nid"))
if piece.has_meta("owner"):
entry["owner"] = String(piece.get_meta("owner"))
entry["owner_name"] = String(piece.get_meta("owner_name", ""))
return entry
func dropped_entry(d: Node3D) -> Dictionary:
@@ -543,6 +562,9 @@ func add_piece_entry(e: Dictionary) -> Node3D:
piece.load_extra(e.extra)
if e.has("nid"):
piece.set_meta("nid", int(e.nid))
if e.has("owner"):
piece.set_meta("owner", String(e.owner))
piece.set_meta("owner_name", String(e.get("owner_name", "")))
return piece
func add_dropped_entry(e: Dictionary) -> Node3D:
@@ -730,7 +752,7 @@ func _go_online() -> void:
PlayerNet.join_world(self) # and our inventory and stats
CreatureNet.join_world(self) # the server's animals, wolves, arrows and floats
if hud != null:
var bar := UITheme.label("Online: %s" % Net.server_info.get("server_name", "server"), 14, UITheme.TEXT_DIM)
var bar := UITheme.label("Online: %s · T to chat (/help)" % Net.server_info.get("server_name", "server"), 14, UITheme.TEXT_DIM)
bar.position = Vector2(16, 40)
$HUD.add_child(bar)
Actions.notify.emit("Connected to %s" % Net.server_info.get("server_name", "the server"))
@@ -799,6 +821,10 @@ var bobbers: Dictionary = {} ## player -> their float
# --- who's here ------------------------------------------------------------
## A server's difficulty for one thing (rules.gd); 1 in single-player.
func difficulty_mult(k: String) -> float:
return preload("res://scripts/net/rules.gd").difficulty(k) if server_mode else 1.0
## Everyone animals react to: the local player in single-player; on a
## server, every player's character that's alive (player_net.gd).
func players() -> Array: