Files
AIGame/Tools/seed_chest_test.py
T

29 lines
1.4 KiB
Python

"""Prepare chest UI cases only in the isolated chest account/database."""
import json
from pathlib import Path
import sqlite3
import sys
root = Path(__file__).resolve().parents[1]
test_root = (root / 'Tools/output/g1-live').resolve()
database = Path((test_root / 'chest-db.path').read_text(encoding='utf-8-sig').strip()).resolve()
username = (test_root / 'chest-account.txt').read_text(encoding='utf-8-sig').strip()
mode = sys.argv[1] if len(sys.argv) == 2 else ''
if test_root not in database.parents or not username.startswith('g1live_chest_') or mode not in ('choice', 'lost', 'empty'):
raise RuntimeError('Refusing non-isolated chest fixture')
with sqlite3.connect(database) as conn:
row = conn.execute('SELECT u.pid,g.state FROM users u JOIN game_states g ON g.pid=u.pid WHERE u.username=?', (username,)).fetchone()
state = json.loads(row[1])
if state['schema'] != 8 or state.get('pendingShot') or state.get('pendingBattle'):
raise RuntimeError('Finish isolated pending activities first')
if mode == 'choice':
state['chests'] = [0, 1, 0]
elif mode == 'lost':
state['chests'] = [1, 0, 0]
else:
state['chests'] = [0, 0, 0]
state['chestDailyClaimed'] = 1
state['revision'] += 1
conn.execute('UPDATE game_states SET state=? WHERE pid=?', (json.dumps(state, ensure_ascii=False), row[0]))
print('Prepared isolated chest UI case:', mode)