More achievements

This commit is contained in:
2026-10-22 12:25:21 -04:00
parent 3b81cae024
commit 84b363b863
4 changed files with 115 additions and 16 deletions
+47 -7
View File
@@ -681,7 +681,7 @@ class PersistenceTests(unittest.TestCase):
def test_eight_milestones_match_achievement_count_and_start_unreached(self):
self.game.state = self.game.load_state()
goals = self.game.milestone_status(self.game.state, self.game.now_ms())
self.assertEqual(len(goals), 8)
self.assertEqual(len(goals), 12)
self.assertEqual(len(goals), len(self.game.player_achievements("nobody")))
self.assertTrue(all(goal["progress"] < goal["target"] for goal in goals))
self.assertEqual(self.game.chat_messages(), [])
@@ -689,7 +689,7 @@ class PersistenceTests(unittest.TestCase):
def test_milestone_thresholds_for_counts_and_precision(self):
game = self.game.new_game()
press = {"player_id": "p", "at": game["started_at"], "remaining_ms": 10000, "zone": "green", "points": 0}
for count in (9, 10, 49, 50):
for count in (9, 10, 49, 50, 51):
game["players"] = {str(i): {} for i in range(count)}
goals = {g["id"]: g for g in self.game.milestone_status(game, game["started_at"])}
self.assertEqual(goals["ten_players"]["progress"] == goals["ten_players"]["target"], count >= 10)
@@ -701,7 +701,7 @@ class PersistenceTests(unittest.TestCase):
self.assertEqual(goals["thousand_presses"]["progress"] == 1000, count >= 1000)
for remaining, qualifies in ((10000, False), (9999, True), (0, False), (-1, False)):
game["presses"] = [dict(press, remaining_ms=remaining)]
self.assertEqual(self.game.milestone_status(game, game["started_at"])[-1]["progress"], int(qualifies))
self.assertEqual(next(g for g in self.game.milestone_status(game, game["started_at"]) if g["id"] == "first_photo_finish")["progress"], int(qualifies))
def test_survival_milestones_boundaries_and_game_end_cap(self):
game = self.game.new_game()
@@ -728,7 +728,7 @@ class PersistenceTests(unittest.TestCase):
self.game.state = self.game.load_state()
self.assertEqual(self.game.chat_messages(), [])
with self.game.database() as connection:
self.assertEqual(connection.execute("SELECT COUNT(*) FROM community_milestones WHERE reached_at IS NOT NULL").fetchone()[0], 8)
self.assertEqual(connection.execute("SELECT COUNT(*) FROM community_milestones WHERE reached_at IS NOT NULL").fetchone()[0], 10)
self.game.load_state()
self.assertEqual(self.game.chat_messages(), [])
# Existing SQLite database without the new table follows the same baseline.
@@ -792,6 +792,46 @@ class PersistenceTests(unittest.TestCase):
).fetchone()
self.assertEqual(latest_player["at"], at - 896)
def test_archived_season_awards_and_shared_ranks(self):
self.game.state = self.game.load_state()
scores = {"a": 32, "b": 32, "c": 16, "d": 8}
for number in (1, 2):
presses = [{"player_id": pid, "points": points} for pid, points in scores.items()]
with self.game.database() as connection:
connection.execute("""INSERT INTO season_results (id,name,starts_at,ends_at,played_from,finished_at,reason,leaderboard,presses)
VALUES (?,?,?,?,?,?,?,?,?)""", (str(number), "Same name", number*1000, number*1000+100, number*1000, number*1000+50, "countdown", "[]", json.dumps(presses)))
badges = {a["id"]: a for a in self.game.seasonal_achievements("a")}
self.assertTrue(badges["season_champion"]["unlocked"])
self.assertEqual(badges["season_veteran"]["progress"], number)
self.assertEqual(badges["season_veteran"]["unlocked"], number == 2)
self.assertTrue(self.game.seasonal_achievements("b")[-1]["unlocked"])
self.assertTrue(self.game.seasonal_achievements("c")[-2]["unlocked"])
self.assertFalse(self.game.seasonal_achievements("d")[-2]["unlocked"])
self.assertFalse(any(a["unlocked"] for a in self.game.seasonal_achievements("idle")))
self.game.load_state()
self.assertEqual(self.game.seasonal_achievements("a")[0]["unlocked_at"], 1050)
def test_new_events_upgrade_silently_and_announce_future_threshold_once(self):
self.game.state = self.game.load_state()
at = self.game.now_ms()
presses = [{"player_id": str(i), "points": 100, "zone": self.game.ZONES[i % 6]["name"], "remaining_ms": 60000, "at": at} for i in range(10)]
self.game.state["presses"] = presses
goals = {g["id"]: g for g in self.game.milestone_status(self.game.state, at)}
self.assertEqual(goals["ten_contenders"]["progress"], 10)
self.assertEqual(goals["shared_spectrum"]["progress"], 6)
self.assertEqual(goals["thousand_points"]["progress"], 1000)
with self.game.database() as connection:
connection.executemany("DELETE FROM community_milestones WHERE id = ?", [(key,) for key in ("shared_spectrum", "ten_contenders", "thousand_points", "ten_thousand_points")])
self.game.sync_milestones(connection, self.game.state, at)
self.assertEqual(self.game.chat_messages(), [])
self.game.state["presses"] = presses * 10
with self.game.database() as connection:
self.game.sync_milestones(connection, self.game.state, at+1)
self.game.sync_milestones(connection, self.game.state, at+2)
messages = [m for m in self.game.chat_messages() if m["id"] == "milestone:ten_thousand_points"]
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0]["at"], at+1)
def achievement_game(self):
self.game.state = self.sample_state()
self.game.state.update(duration_ms=120000, started_at=1000, presses=[])
@@ -802,7 +842,7 @@ class PersistenceTests(unittest.TestCase):
def test_achievements_start_locked_without_presses(self):
self.achievement_game()
achievements = self.achievement_map()
self.assertEqual(set(achievements), {"close_call", "full_spectrum", "keeping_us_alive", "red_alert", "into_the_dark", "white_knuckle", "photo_finish", "last_second"})
self.assertEqual(len(achievements), 12)
for achievement in achievements.values():
self.assertFalse(achievement["unlocked"])
self.assertIsNone(achievement["unlocked_at"])
@@ -869,7 +909,7 @@ class PersistenceTests(unittest.TestCase):
for index, zone in enumerate(self.game.ZONES):
self.game.state["presses"].append({"player_id": "alice", "at": 61000 + index * 1000, "remaining_ms": 999, "zone": zone["name"], "points": zone["points"]})
expected = self.game.player_achievements("alice")
self.assertTrue(all(a["unlocked"] for a in expected))
self.assertTrue(all(a["unlocked"] for a in expected if a.get("scope") != "lifetime"))
self.write_legacy(self.game.state)
self.game.state = self.game.load_state()
self.assertEqual(self.game.player_achievements("alice"), expected)
@@ -884,7 +924,7 @@ class PersistenceTests(unittest.TestCase):
before = copy.deepcopy(self.game.state)
status, summary = request(token="alice-token", path="/api/me")
self.assertEqual(status, 200)
self.assertEqual(len(summary["achievements"]), 8)
self.assertEqual(len(summary["achievements"]), 12)
self.assertEqual(summary["total_points"], 40)
self.assertEqual(self.game.state, before)
self.assertNotIn("achievements", self.game.load_state())