M2.5: wildlife, wolves, hunting, fishing and sleeping on the server

This commit is contained in:
Paul Bailey
2026-11-04 21:25:10 +00:00
parent 26be17b05f
commit a211fe4c63
20 changed files with 1258 additions and 88 deletions

View File

@@ -109,8 +109,43 @@ func _do(cmd: Dictionary) -> Dictionary:
net.leave()
await create_timer(0.3).timeout
return {"left": true}
# M2.5 (tests/test_net_life.gd).
"tp":
root.get_node("PlayerNet").ask("debug_tp", [_p(cmd.to)])
await create_timer(0.6).timeout
player.set_physics_process(false)
return {"pos": _v(player.global_position)}
"ask":
var args: Array = []
for x in cmd.get("args", []):
args.append(_p(x.v) if x is Dictionary and x.has("v") else x)
root.get_node("PlayerNet").ask(String(cmd.what), args)
await create_timer(0.4).timeout
return {"inv": player.inventory.to_data()}
"bed":
var b: Node3D = WN.pieces.get(int(cmd.nid))
if b == null:
return {"error": "no bed %d" % int(cmd.nid)}
root.get_node("Actions").use_bed(player, b)
await create_timer(0.5).timeout
return {"asked": true}
"life":
return life(world, root.get_node("CreatureNet"), root.get_node("PlayerNet"))
return {"error": "unknown command"}
## What this player's game shows of the server's wildlife.
static func life(w: Node3D, CN: Node, PN: Node) -> Dictionary:
var out := {"puppets": {}, "floats": [], "projectiles": CN.projectiles_seen, "howls": CN.howls_heard,
"hurts": PN.hurts, "health": w.player.survival.health, "day": w.day_night.day,
"hours": w.day_night.hours(), "statuses": w.player.survival.statuses.duplicate()}
for cid in CN.puppets:
var c: Node3D = CN.puppets[cid]
if is_instance_valid(c):
out.puppets[str(cid)] = {"kind": c.kind, "pos": _v(c.global_position), "state": c.state, "hp": c.hp}
for peer in CN.floats:
out.floats.append(peer)
return out
# Shared with test_net_shared.gd (it loads this script for these).
## Walks (by setting positions, like the game sending its moves) at 5 m/s.