пенис пенис елда
This commit is contained in:
+170
-41
@@ -17,10 +17,23 @@ from pathlib import Path
|
||||
from database import get_db, SessionLocal, User, InventoryItem, CaseOpening, Contract, Upgrade, UpgradeRPU
|
||||
from websocket_manager import manager, crash_game
|
||||
from achievements import (
|
||||
seed_achievements, check_achievement, check_open_cases_achievements, check_contracts_achievements,
|
||||
check_upgrade_achievements, check_rare_item_achievement, check_knife_achievement,
|
||||
check_spent_achievements, check_balance_achievement, check_slot_match_achievement,
|
||||
check_slot_plays_achievements, check_inventory_achievement, get_user_achievements
|
||||
seed_achievements, check_achievement,
|
||||
check_open_cases_achievements, check_contracts_achievements,
|
||||
check_upgrade_achievements, check_upgrade_risk_achievements, check_upgrade_result_achievements,
|
||||
check_rare_item_achievement, check_knife_achievement,
|
||||
check_spent_achievements,
|
||||
check_balance_achievements,
|
||||
check_slot_match_achievements, check_slot_plays_achievements,
|
||||
check_slot_match_count_achievements,
|
||||
check_inventory_achievements,
|
||||
check_dildo_achievements, check_dildo_contract_achievement,
|
||||
check_crash_achievements, check_crash_cashout_achievements,
|
||||
check_items_unboxed_achievements, check_total_profit_achievements,
|
||||
check_achievements_count_achievements,
|
||||
check_rare_item_count_achievements, check_knife_count_achievements,
|
||||
check_midnight_case_achievement, check_exact_cases_achievement,
|
||||
check_collection_achievements,
|
||||
get_user_achievements
|
||||
)
|
||||
from auth import (
|
||||
create_user, authenticate_user, create_access_token,
|
||||
@@ -307,8 +320,7 @@ async def index(request: Request, user: Optional[User] = Depends(get_current_use
|
||||
if user:
|
||||
return RedirectResponse(url="/cases")
|
||||
|
||||
return templates.TemplateResponse("index.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "index.html", {
|
||||
"user": None,
|
||||
"active_page": "home"
|
||||
})
|
||||
@@ -319,8 +331,7 @@ async def login_page(request: Request, user: Optional[User] = Depends(get_curren
|
||||
if user:
|
||||
return RedirectResponse(url="/profile")
|
||||
|
||||
return templates.TemplateResponse("login.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "login.html", {
|
||||
"user": None,
|
||||
"active_page": "login"
|
||||
})
|
||||
@@ -331,8 +342,7 @@ async def register_page(request: Request, user: Optional[User] = Depends(get_cur
|
||||
if user:
|
||||
return RedirectResponse(url="/profile")
|
||||
|
||||
return templates.TemplateResponse("register.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "register.html", {
|
||||
"user": None,
|
||||
"active_page": "register"
|
||||
})
|
||||
@@ -399,8 +409,7 @@ async def profile_page(
|
||||
if item.type:
|
||||
types.add(item.type)
|
||||
|
||||
return templates.TemplateResponse("profile.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "profile.html", {
|
||||
"user": user,
|
||||
"total_items": total_items,
|
||||
"cases_opened": cases_opened,
|
||||
@@ -490,8 +499,7 @@ async def public_profile_page(
|
||||
reverse=True
|
||||
)[:12]
|
||||
|
||||
return templates.TemplateResponse("profile.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "profile.html", {
|
||||
"user": current_user,
|
||||
"profile_user": profile_user,
|
||||
"is_public": True,
|
||||
@@ -586,8 +594,7 @@ async def cases_page(
|
||||
|
||||
#print(f"Всего секций для отображения: {len(sections)}")
|
||||
|
||||
return templates.TemplateResponse("cases.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "cases.html", {
|
||||
"user": user,
|
||||
"sections": sections,
|
||||
"active_page": "cases"
|
||||
@@ -644,8 +651,7 @@ async def contracts_page(
|
||||
has_contract = any(c >= 10 for c in group_counts.values())
|
||||
has_knife_contract = len(knife_items) >= 10
|
||||
|
||||
return templates.TemplateResponse("contracts.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "contracts.html", {
|
||||
"user": user,
|
||||
"inventory_items": all_items + knife_items,
|
||||
"has_contract": has_contract or has_knife_contract,
|
||||
@@ -887,8 +893,9 @@ async def api_open_case(
|
||||
|
||||
# Проверка достижений
|
||||
unlocked_ach = []
|
||||
open_count = db.query(CaseOpening).filter(CaseOpening.user_id == user.id).count()
|
||||
unlocked_ach += check_open_cases_achievements(db, user.id)
|
||||
total_spent = db.query(CaseOpening).filter(CaseOpening.user_id == user.id).count() * price_per_case
|
||||
total_spent = open_count * price_per_case
|
||||
unlocked_ach += check_spent_achievements(db, user.id, total_spent)
|
||||
|
||||
# Проверка на редкий предмет
|
||||
@@ -898,7 +905,18 @@ async def api_open_case(
|
||||
if item_data:
|
||||
unlocked_ach += check_knife_achievement(db, user.id, item_data)
|
||||
|
||||
unlocked_ach += check_inventory_achievement(db, user.id)
|
||||
unlocked_ach += check_inventory_achievements(db, user.id)
|
||||
unlocked_ach += check_dildo_achievements(db, user.id)
|
||||
unlocked_ach += check_items_unboxed_achievements(db, user.id)
|
||||
unlocked_ach += check_rare_item_count_achievements(db, user.id)
|
||||
unlocked_ach += check_knife_count_achievements(db, user.id)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
unlocked_ach += check_midnight_case_achievement(db, user.id)
|
||||
unlocked_ach += check_exact_cases_achievement(db, user.id, open_count)
|
||||
unlocked_ach += check_collection_achievements(db, user.id)
|
||||
profit = user.balance + total_spent
|
||||
unlocked_ach += check_total_profit_achievements(db, user.id, profit)
|
||||
|
||||
# Запись активности — каждый предмет отдельно
|
||||
for r in results:
|
||||
@@ -1067,7 +1085,12 @@ async def api_submit_contract(
|
||||
db.commit()
|
||||
|
||||
unlocked_ach = check_contracts_achievements(db, user.id)
|
||||
unlocked_ach += check_inventory_achievement(db, user.id)
|
||||
unlocked_ach += check_inventory_achievements(db, user.id)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_dildo_achievements(db, user.id)
|
||||
unlocked_ach += check_dildo_contract_achievement(db, user.id)
|
||||
unlocked_ach += check_collection_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
|
||||
act = record_activity_own_session(user.id, user.username, "contract",
|
||||
f"🔄 выполнил(а) контракт и получил(а) {result.received_item.market_hash_name}",
|
||||
@@ -1148,6 +1171,111 @@ async def get_item_image(
|
||||
}
|
||||
|
||||
|
||||
@app.get("/web/api/inventory/item-detail/{inventory_id}")
|
||||
async def api_item_detail(
|
||||
inventory_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Детальная информация о предмете с коллекцией"""
|
||||
inv_item = db.query(InventoryItem).filter(
|
||||
InventoryItem.id == inventory_id,
|
||||
InventoryItem.user_id == user.id
|
||||
).first()
|
||||
if not inv_item:
|
||||
# Also allow viewing if item exists (public profiles)
|
||||
inv_item = db.query(InventoryItem).filter(
|
||||
InventoryItem.id == inventory_id
|
||||
).first()
|
||||
if not inv_item:
|
||||
return JSONResponse(status_code=404, content={"error": "Предмет не найден"})
|
||||
|
||||
item_data = get_item(inv_item.item_id)
|
||||
if not item_data:
|
||||
return JSONResponse(status_code=404, content={"error": "Данные предмета не найдены"})
|
||||
|
||||
collection = item_data.get("collection", "").strip()
|
||||
# fallback to case name
|
||||
if not collection or collection == "Без коллекции":
|
||||
crates = item_data.get("crates_names", [])
|
||||
if crates:
|
||||
collection = f"Case: {crates[0]}"
|
||||
|
||||
item_resp = {
|
||||
"id": inv_item.id,
|
||||
"item_id": inv_item.item_id,
|
||||
"name": inv_item.market_hash_name,
|
||||
"rarity": inv_item.rarity,
|
||||
"wear": inv_item.wear,
|
||||
"float": inv_item.float_value,
|
||||
"type": inv_item.type,
|
||||
"price_rub": item_data.get("price_rub", 100),
|
||||
"image_url": item_data.get("image_url", ""),
|
||||
"collection": collection,
|
||||
"weapon": item_data.get("weapon", ""),
|
||||
"pattern": item_data.get("pattern", ""),
|
||||
}
|
||||
|
||||
# Собираем все предметы коллекции
|
||||
coll_items = []
|
||||
all_owned = True
|
||||
owned_names = set()
|
||||
|
||||
# Получаем все item_id из коллекции
|
||||
from backend import COLLECTIONS_INDEX, extract_base_name, RARITY_ORDER
|
||||
collection_ids = COLLECTIONS_INDEX.get(collection, [])
|
||||
|
||||
# Группируем по базовому имени (без учёта вариантов)
|
||||
seen_base = {}
|
||||
for cid in collection_ids:
|
||||
citem = get_item(cid)
|
||||
if not citem:
|
||||
continue
|
||||
base = extract_base_name(citem.get("market_hash_name", ""))
|
||||
if base and base not in seen_base:
|
||||
seen_base[base] = citem
|
||||
|
||||
# Все предметы пользователя — для проверки владения
|
||||
user_items = db.query(InventoryItem.item_id).filter(
|
||||
InventoryItem.user_id == user.id
|
||||
).all()
|
||||
user_item_ids = {iid for (iid,) in user_items}
|
||||
|
||||
# Сортируем по редкости (низшая → высшая)
|
||||
sorted_bases = sorted(seen_base.values(), key=lambda x: RARITY_ORDER.get(x.get("rarity", "Unknown"), -1))
|
||||
|
||||
for citem in sorted_bases:
|
||||
base = extract_base_name(citem.get("market_hash_name", ""))
|
||||
owned = False
|
||||
for u_id in user_item_ids:
|
||||
u_item = get_item(u_id)
|
||||
if u_item and extract_base_name(u_item.get("market_hash_name", "")) == base:
|
||||
owned = True
|
||||
owned_names.add(base)
|
||||
break
|
||||
|
||||
if not owned:
|
||||
all_owned = False
|
||||
|
||||
coll_items.append({
|
||||
"base_name": base,
|
||||
"market_hash_name": citem.get("market_hash_name", ""),
|
||||
"weapon": citem.get("weapon", ""),
|
||||
"pattern": citem.get("pattern", ""),
|
||||
"rarity": citem.get("rarity", ""),
|
||||
"rarity_level": RARITY_ORDER.get(citem.get("rarity", "Unknown"), -1),
|
||||
"owned": owned,
|
||||
"image_url": citem.get("image_url", ""),
|
||||
})
|
||||
|
||||
return {
|
||||
"item": item_resp,
|
||||
"collection_name": collection if collection else "",
|
||||
"items": coll_items,
|
||||
"all_owned": all_owned,
|
||||
}
|
||||
|
||||
|
||||
def get_case_items(case_name: str) -> List[dict]:
|
||||
"""Получает предметы кейса по его имени"""
|
||||
items = []
|
||||
@@ -1472,8 +1600,7 @@ async def case_detail_page(
|
||||
"image_url": item["image_url"]
|
||||
})
|
||||
|
||||
return templates.TemplateResponse("case_detail.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "case_detail.html", {
|
||||
"user": user,
|
||||
"case_name": case_name,
|
||||
"case_display_name": case_config.get('display_name', case_name),
|
||||
@@ -1885,8 +2012,11 @@ async def api_open_slot_case(
|
||||
# Проверка достижений для слота
|
||||
unlocked_ach = []
|
||||
if match:
|
||||
unlocked_ach += check_slot_match_achievement(db, user.id)
|
||||
unlocked_ach += check_slot_match_achievements(db, user.id)
|
||||
unlocked_ach += check_slot_plays_achievements(db, user.id)
|
||||
unlocked_ach += check_slot_match_count_achievements(db, user.id)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
|
||||
db.commit()
|
||||
|
||||
@@ -2234,8 +2364,7 @@ async def upgrade_page(
|
||||
"probability": round(u.rpu_adjusted_probability or u.probability or 0, 1)
|
||||
})
|
||||
|
||||
return templates.TemplateResponse("upgrade.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "upgrade.html", {
|
||||
"user": user,
|
||||
"inventory_items": enriched_items,
|
||||
"upgrade_rpu": upgrade_rpu,
|
||||
@@ -2450,6 +2579,12 @@ async def api_execute_upgrade(
|
||||
db.commit()
|
||||
|
||||
unlocked_ach = check_upgrade_achievements(db, user.id)
|
||||
unlocked_ach += check_upgrade_risk_achievements(db, user.id, input_price)
|
||||
unlocked_ach += check_upgrade_result_achievements(db, user.id, success, base_probability, input_price)
|
||||
unlocked_ach += check_dildo_achievements(db, user.id)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_collection_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
|
||||
if success:
|
||||
act = record_activity_own_session(user.id, user.username, "upgrade",
|
||||
@@ -2501,8 +2636,7 @@ async def achievements_page(
|
||||
total = len(achievements)
|
||||
unlocked = sum(1 for a in achievements if a["unlocked"])
|
||||
|
||||
return templates.TemplateResponse("achievements.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "achievements.html", {
|
||||
"user": user,
|
||||
"achievements": achievements,
|
||||
"total": total,
|
||||
@@ -2534,8 +2668,7 @@ async def activity_page(
|
||||
):
|
||||
activities = db.query(ActivityFeed).order_by(desc(ActivityFeed.created_at)).limit(50).all()
|
||||
|
||||
return templates.TemplateResponse("activity.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "activity.html", {
|
||||
"user": user,
|
||||
"activities": [
|
||||
{
|
||||
@@ -2681,8 +2814,7 @@ async def crash_page(
|
||||
request: Request,
|
||||
user: User = Depends(get_current_user)
|
||||
):
|
||||
return templates.TemplateResponse("crash.html", {
|
||||
"request": request,
|
||||
return templates.TemplateResponse(request, "crash.html", {
|
||||
"user": user,
|
||||
"active_page": "crash"
|
||||
})
|
||||
@@ -2711,11 +2843,9 @@ async def api_crash_bet(
|
||||
CrActivity.user_id == user.id,
|
||||
CrActivity.activity_type == "crash"
|
||||
).count() + 1
|
||||
unlocked_ach = []
|
||||
r1 = check_achievement(db, user.id, "crash_first", 1)
|
||||
if r1: unlocked_ach.append(r1)
|
||||
r2 = check_achievement(db, user.id, "crash_pro", crash_count)
|
||||
if r2: unlocked_ach.append(r2)
|
||||
unlocked_ach = check_crash_achievements(db, user.id, crash_count)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
db.commit()
|
||||
|
||||
asyncio.ensure_future(manager.send_personal(user.id, {"type": "balance_update", "balance": user.balance}))
|
||||
@@ -2748,10 +2878,9 @@ async def api_crash_cashout(
|
||||
user.balance += payout
|
||||
|
||||
# Проверка достижений
|
||||
unlocked_ach = []
|
||||
if g.current_multiplier >= 5.0:
|
||||
r = check_achievement(db, user.id, "crash_5x", 1)
|
||||
if r: unlocked_ach.append(r)
|
||||
unlocked_ach = check_crash_cashout_achievements(db, user.id, g.current_multiplier)
|
||||
unlocked_ach += check_balance_achievements(db, user.id)
|
||||
unlocked_ach += check_achievements_count_achievements(db, user.id)
|
||||
|
||||
db.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user