Repository navigation
Expand file tree
/
Copy pathgo2.py
More file actions
94 lines (79 loc) · 3.49 KB
/
Copy pathgo2.py
File metadata and controls
94 lines (79 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Pathfind and walk anywhere the community map knows: ;go2 <target>
Targets: a room id (;go2 1234), a tag (;go2 bank), a title substring
(;go2 herald street), `home` (the profile's `home` room) or `safe`
(the training plan's first safe room, 2026-09-22). Routes take the
fastest way the map knows (its
timeto travel times) and detour around the rooms your avoid list names
(settings "avoid_rooms" — cougar grounds by default) whenever a clean
way around exists; ;go2 direct <target> skips the detour for one trip.
The Faldesu ferry between the Crossing's North Road and Riverhaven is
ridden on the way (the map's bescort edge; the walker boards, waits for
a ferry that is out, and steps off at the far dock, #205).
;go2 alone reports where the map thinks you are; ;go2 update refreshes
the database. First use downloads it (~13MB) into ~/.revenant/mapdb/,
and a copy a week old is fetched again.
The location and walking engine lives in client/game/walker.py, shared with
other traveling scripts.
"""
from client.game.walker import DIRECTIONS, avoided_rooms, locate, walk # noqa: F401
NAMED = ("home", "safe")
def named_room(s, query):
"""The room `home` or `safe` stands for — the profile's `home`, the
plan's first safe room — as a map query; None (said) when the file
names none, and None, silently, for any other query."""
word = query.strip().lower()
if word not in NAMED:
return None
name = getattr(s.state, "name", None) or ""
if word == "home":
from client.game.profile import load_profile
room = str(load_profile(name).get("home") or "").strip()
if not room:
s.echo("go2: the profile names no home (Character Profile, `home`)")
return room or None
from client.game.training import load_plan
rooms = [str(room).strip() for room in (load_plan(name).get("safe_rooms") or [])]
rooms = [room for room in rooms if room]
if not rooms:
s.echo("go2: the training plan lists no safe rooms (File -> Training Plan...)")
return rooms[0] if rooms else None
def main(s):
from client.game.mapdb import MapDB, download, ensure_fresh
from client.settings import setting
if s.args and s.args[0] == "update":
s.echo("downloading map database ...")
s.echo(f"updated {download()}")
return
ensure_fresh(s.echo)
db = MapDB.load()
avoid = avoided_rooms(db, setting("avoid_rooms"))
if s.args and s.args[0] == "direct":
avoid = set()
s.args = s.args[1:]
here = locate(db, s.state)
if here is None:
title = getattr(s.state, "room_title", None) if s.state else None
if title and not db.rooms_titled(title):
s.echo(f"room {title!r} is not in the map database")
else:
s.echo("current room unknown yet — 'look' once and retry")
return
if not s.args:
titles = db.rooms[here].get("title") or ["?"]
s.echo(f"you are in room {here}: {titles[0]}")
s.echo("usage: ;go2 <room id | tag | title substring>")
return
query = " ".join(s.args)
named = named_room(s, query)
if named is None and query.lower() in NAMED:
return
if named:
s.echo(f"{query}: room {named}")
query = named
goals = db.resolve(query)
if not goals:
s.echo(f"nothing in the map matches {query!r}")
return
if walk(s, db, goals, describe=repr(query), avoid=avoid):
final = locate(db, s.state)
s.echo(f"arrived: {s.state.room_title} (room {final})")