Merge pull request '[Eva] Ева, патч 21 применён — теперь ты можешь' (#40) from eva/chat-b7c183-backend into main
Reviewed-on: #40
This commit was merged in pull request #40.
This commit is contained in:
+21
-13
@@ -195,9 +195,11 @@ async def complete_bubble_level(request: Request):
|
|||||||
if not user_exists:
|
if not user_exists:
|
||||||
raise HTTPException(401, "User not registered")
|
raise HTTPException(401, "User not registered")
|
||||||
|
|
||||||
current_level = await conn.fetchval(
|
user = await conn.fetchrow(
|
||||||
"SELECT current_level FROM users WHERE telegram_id = $1", telegram_id
|
"SELECT current_level, difficulty FROM users WHERE telegram_id = $1", telegram_id
|
||||||
) or "A1"
|
)
|
||||||
|
current_level = user["current_level"] or "A1"
|
||||||
|
difficulty = user["difficulty"] or "medium"
|
||||||
|
|
||||||
# Читаем серверный hints_used
|
# Читаем серверный hints_used
|
||||||
hints_used = await conn.fetchval(
|
hints_used = await conn.fetchval(
|
||||||
@@ -206,17 +208,24 @@ async def complete_bubble_level(request: Request):
|
|||||||
) or 0
|
) or 0
|
||||||
hints_used = min(max(0, hints_used), 3)
|
hints_used = min(max(0, hints_used), 3)
|
||||||
|
|
||||||
# 🆕 Расчёт звёзд
|
# 🔧 НОВОЕ (14.10.2026): очки по формуле филворда.
|
||||||
# Старт 5. Штрафы: hints(1) + wrong_words(до 3) + time(1)
|
# Hard — фикс 110. Easy/Medium — 100 − 20×hints − 20×list + bonus.
|
||||||
time_penalty = 1 if (completion_time and completion_time > 60) else 0
|
if difficulty == "hard":
|
||||||
wrong_penalty = min(max(0, wrong_words), 3)
|
if hints_used > 0 or list_opened:
|
||||||
hint_penalty = 1 if hints_used > 0 else 0
|
raise HTTPException(
|
||||||
list_penalty = 1 if list_opened else 0
|
status_code=400,
|
||||||
stars = max(1, 5 - time_penalty - wrong_penalty - hint_penalty - list_penalty)
|
detail="Hints and word list are disabled on Hard difficulty"
|
||||||
|
)
|
||||||
|
points = 110
|
||||||
|
else:
|
||||||
|
bonus = 10 if hints_used == 0 else 0
|
||||||
|
penalty_hints = 20 * hints_used
|
||||||
|
penalty_list = 0 if difficulty == "easy" else 20 * (1 if list_opened else 0)
|
||||||
|
points = max(20, min(110, 100 - penalty_hints - penalty_list + bonus))
|
||||||
|
|
||||||
# Начисляем XP
|
# Начисляем XP
|
||||||
from services.xp import award_xp
|
from services.xp import award_xp
|
||||||
xp_result = await award_xp(conn, telegram_id, "bubbles", stars)
|
xp_result = await award_xp(conn, telegram_id, "bubbles", points)
|
||||||
score = xp_result["points"]
|
score = xp_result["points"]
|
||||||
|
|
||||||
await conn.execute("""
|
await conn.execute("""
|
||||||
@@ -241,7 +250,7 @@ async def complete_bubble_level(request: Request):
|
|||||||
]
|
]
|
||||||
if hints_used == 0:
|
if hints_used == 0:
|
||||||
achievements_to_check.append(("bubble_no_hints", 1))
|
achievements_to_check.append(("bubble_no_hints", 1))
|
||||||
if stars == 5:
|
if hints_used == 0 and not list_opened and wrong_words == 0:
|
||||||
achievements_to_check.append(("bubble_perfect", 1))
|
achievements_to_check.append(("bubble_perfect", 1))
|
||||||
if completion_time is not None and 0 < completion_time <= 45:
|
if completion_time is not None and 0 < completion_time <= 45:
|
||||||
achievements_to_check.append(("bubble_speed", 45))
|
achievements_to_check.append(("bubble_speed", 45))
|
||||||
@@ -261,7 +270,6 @@ async def complete_bubble_level(request: Request):
|
|||||||
"completion_time": completion_time,
|
"completion_time": completion_time,
|
||||||
"new_achievements": new_achievements,
|
"new_achievements": new_achievements,
|
||||||
# 🆕 XP-поля
|
# 🆕 XP-поля
|
||||||
"stars": xp_result["stars"],
|
|
||||||
"base_points": xp_result["base_points"],
|
"base_points": xp_result["base_points"],
|
||||||
"multiplier": xp_result["multiplier"],
|
"multiplier": xp_result["multiplier"],
|
||||||
"points": xp_result["points"],
|
"points": xp_result["points"],
|
||||||
|
|||||||
Reference in New Issue
Block a user