forked from johnny603/lux
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathachievements.py
More file actions
106 lines (92 loc) · 3.83 KB
/
Copy pathachievements.py
File metadata and controls
106 lines (92 loc) · 3.83 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
95
96
97
98
99
100
101
102
103
104
105
106
from datetime import datetime, timezone
from typing import Dict, List, Optional
ACHIEVEMENTS = [
{"id": "first_solve", "title": "First Solve", "description": "Solve your first puzzle."},
{"id": "solve_5", "title": "Solver: 5", "description": "Solve 5 puzzles."},
{"id": "solve_10", "title": "Solver: 10", "description": "Solve 10 puzzles."},
{"id": "solve_25", "title": "Solver: 25", "description": "Solve 25 puzzles."},
{
"id": "master_secrets",
"title": "Master of Secrets",
"description": "Discover all secret chambers hidden throughout the escape facility.",
},
{
"id": "checkpoint_guardian_slayer",
"title": "Guardian of the Core",
"description": "Conquer a Checkpoint Boss Battle Showdown and claim a Boss Token.",
},
]
def _now_iso():
return datetime.now(timezone.utc).isoformat()
def _ach_by_id(aid: str):
for a in ACHIEVEMENTS:
if a["id"] == aid:
return a
return None
def evaluate_achievements(state: Dict, levels: Optional[List[Dict]] = None) -> List[Dict]:
"""Evaluate achievements based on current state and optional levels metadata.
Returns a list of newly unlocked achievement dicts.
"""
import storage
unlocked = state.setdefault("achievements", {})
normalized = storage.normalize_state(state)
solved = set(normalized.get("solved", {}).keys())
newly = []
# simple count-based achievements
n = len(solved)
thresholds = [
("first_solve", n >= 1),
("solve_5", n >= 5),
("solve_10", n >= 10),
("solve_25", n >= 25),
]
for aid, cond in thresholds:
if cond and aid not in unlocked:
meta = _ach_by_id(aid) or {"id": aid}
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": meta.get("title"),
"description": meta.get("description"),
}
newly.append({"id": aid, **unlocked[aid]})
# secret rooms discovery achievement
discovered_secrets = set(storage.get_discovered_secret_rooms(state))
import rooms
all_secret_ids = set(rooms.get_all_secret_room_ids())
if all_secret_ids and all_secret_ids.issubset(discovered_secrets) and "master_secrets" not in unlocked:
aid = "master_secrets"
meta = _ach_by_id(aid) or {"id": aid}
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": meta.get("title", "Master of Secrets"),
"description": meta.get("description", "Discover all secret chambers."),
}
newly.append({"id": aid, **unlocked[aid]})
# Checkpoint boss battle conquest achievement
boss_tokens = set(storage.get_boss_tokens(state))
if boss_tokens and "checkpoint_guardian_slayer" not in unlocked:
aid = "checkpoint_guardian_slayer"
meta = _ach_by_id(aid) or {"id": aid}
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": meta.get("title", "Guardian of the Core"),
"description": meta.get("description", "Conquer a Checkpoint Boss Battle Showdown."),
}
newly.append({"id": aid, **unlocked[aid]})
# category completion achievements if levels provided
if levels:
# build category -> set(ids)
cats = {}
for level in levels:
cid = level.get("category") or "uncategorized"
cats.setdefault(cid, set()).add(level.get("id"))
for cat, ids in cats.items():
if ids and ids.issubset(solved) and f"category_{cat}" not in unlocked:
aid = f"category_{cat}"
unlocked[aid] = {
"unlocked_at": _now_iso(),
"title": f"Master: {cat}",
"description": f"Solve all puzzles in {cat}.",
}
newly.append({"id": aid, **unlocked[aid]})
return newly