feat: XP foundation + waves + featured game + profile + leaderboard by total_xp
- services/xp.py: award_xp, level_for, RANKS (48), featured_game - services/waves.py: wave_plan, grid_size_for, wave_medal - routers/featured.py: GET /featured (игра дня ×1.5) - routers/users.py: POST /set-nickname, POST /set-avatar - routers/app_auth.py: /auth/me с XP-полями (level, rank_key, rank_name, xp) - routers/game.py: award_xp + 3 штрафа + POST /game/next (волны) - routers/wordquiz.py: award_xp + серии в choose_progress - routers/bubblewords.py: award_xp + 4 штрафа - routers/sentences.py: award_xp по длине предложения - routers/leaderboard.py: сортировка по total_xp, XP-поля в ответе - database.py: миграции user_profile, xp_log, choose_progress, user_seen_levels, user_game_progress, wave_results, bubble_levels, user_word_stats - main.py: подключение routers/featured Проверено: - /auth/me отдаёт level=1, rank_00, xp_in_level - /featured отдаёт wordsearch + seconds_left - /game/complete-level начисляет XP через award_xp - xp_log, user_profile заполняются - /game/next выдаёт уровень по волнам - /leaderboard сортирует по total_xp
This commit is contained in:
+34
-4
@@ -160,6 +160,8 @@ async def check_sentence(request: Request):
|
||||
raise HTTPException(400, "Too many words")
|
||||
|
||||
pool = await get_pool()
|
||||
# 🔧 НОВОЕ (08.10.2026): XP-система — результат award_xp.
|
||||
xp_result = None
|
||||
async with pool.acquire() as conn:
|
||||
user_exists = await conn.fetchval(
|
||||
"SELECT 1 FROM users WHERE telegram_id = $1", telegram_id
|
||||
@@ -207,12 +209,28 @@ async def check_sentence(request: Request):
|
||||
|
||||
if is_correct:
|
||||
word_count = len(correct_words_original)
|
||||
|
||||
# 🆕 Расчёт звёзд для "Составь предложение"
|
||||
# Старт 5. Штрафы:
|
||||
# -1 за каждую неверную проверку (клиент шлёт wrong_checks)
|
||||
# -1 если time > лимита (по длине: 3-4 → 30с, 5-6 → 45с, 7-8 → 60с)
|
||||
wrong_checks = int(body.get("wrong_checks", 0) or 0)
|
||||
|
||||
if word_count <= 4:
|
||||
score = 50
|
||||
time_limit = 30
|
||||
elif word_count <= 6:
|
||||
score = 75
|
||||
time_limit = 45
|
||||
else:
|
||||
score = 100
|
||||
time_limit = 60
|
||||
|
||||
time_penalty = 1 if (completion_time and completion_time > time_limit) else 0
|
||||
wrong_penalty = min(max(0, wrong_checks), 3)
|
||||
stars = max(1, 5 - wrong_penalty - time_penalty)
|
||||
|
||||
# Начисляем XP
|
||||
from services.xp import award_xp
|
||||
xp_result = await award_xp(conn, telegram_id, "sentence", stars)
|
||||
score = xp_result["points"]
|
||||
|
||||
await conn.execute(
|
||||
"""INSERT INTO sentence_progress (user_id, sentence_id, completed_at, score, level)
|
||||
@@ -267,7 +285,19 @@ async def check_sentence(request: Request):
|
||||
"correct_words": [normalize_word_for_display(w) for w in correct_words_original],
|
||||
"already_completed": False,
|
||||
"score": score,
|
||||
"new_achievements": new_achievements
|
||||
"new_achievements": new_achievements,
|
||||
# 🆕 XP
|
||||
"stars": xp_result["stars"],
|
||||
"base_points": xp_result["base_points"],
|
||||
"multiplier": xp_result["multiplier"],
|
||||
"points": xp_result["points"],
|
||||
"featured": xp_result["featured"],
|
||||
"level_up": xp_result["level_up"],
|
||||
"total_xp": xp_result["total_xp"],
|
||||
"level": xp_result["level"],
|
||||
"rank_key": xp_result["rank_key"],
|
||||
"xp_in_level": xp_result["xp_in_level"],
|
||||
"xp_needed": xp_result["xp_needed"],
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user