1
0
Fork 0
forked from zovos/bot_tg
bot_tg/games/casino.py

128 lines
4.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import random
import sqlite3
import logging
import config
from .economy import economy
logger = logging.getLogger(__name__)
# Символы слотов и их веса (чем выше вес — тем чаще выпадает)
SLOT_SYMBOLS = ["🍒", "🍋", "🔔", "💎", "7", "🍀"]
SLOT_WEIGHTS = [30, 25, 20, 12, 8, 5] # 🍒 чаще всего, 🍀 реже всего
# Множители для выигрышей: {кол-во совпадений: (мин, макс)}
MULTIPLIERS = {
2: (1.2, 1.8), # две одинаковых
3: (2.0, 3.0), # три одинаковых (джекпот, редко)
}
CASINO_WIN_CHANCE = 0.35
def spin_slots() -> tuple[list[str], int]:
reels = random.choices(SLOT_SYMBOLS, weights=SLOT_WEIGHTS, k=3)
if random.random() > CASINO_WIN_CHANCE:
while len(set(reels)) < 3:
reels = random.choices(SLOT_SYMBOLS, weights=SLOT_WEIGHTS, k=3)
return reels, 0
counts = {}
for s in reels:
counts[s] = counts.get(s, 0) + 1
max_match = max(counts.values())
return reels, max_match
def get_user_length(user_id: int) -> float | None:
try:
with sqlite3.connect(config.PENIS_DB_PATH) as conn:
row = conn.execute(
"SELECT length FROM penis_stats WHERE user_id = ?",
(user_id,),
).fetchone()
return float(row[0]) if row else None
except sqlite3.Error:
logger.exception("casino: failed to get length")
return None
def update_user_length(user_id: int, delta: float) -> float | None:
try:
with sqlite3.connect(config.PENIS_DB_PATH) as conn:
row = conn.execute(
"SELECT length FROM penis_stats WHERE user_id = ?",
(user_id,),
).fetchone()
if row is None:
return None
new_length = round(float(row[0]) + delta, 1)
# Не даём уйти ниже 0 при проигрыше
if delta < 0 and new_length < 0:
new_length = 0.0
conn.execute(
"UPDATE penis_stats SET length = ? WHERE user_id = ?",
(new_length, user_id),
)
conn.commit()
return new_length
except sqlite3.Error:
logger.exception("casino: failed to update length")
return None
def play_casino(user_id: int, bet: float) -> str:
current = economy.get_user_balance(user_id)
# Проверяем максимум ставки
if bet > config.CASINO_MAX_BET:
return f"Максимальная ставка — {config.CASINO_MAX_BET} см, не жадничай."
if bet <= 0:
return "Ставка должна быть больше нуля, фраер."
# Проверяем хватает ли
if bet > current:
return f"У тебя {current:.1f} см, а ставишь {bet:.1f}. Столько нет, фраер."
# Крутим
reels, matches = spin_slots()
slots_display = " | ".join(reels)
if matches >= 2:
min_mult, max_mult = MULTIPLIERS[matches]
multiplier = round(random.uniform(min_mult, max_mult), 1)
winnings = round(bet * multiplier, 1)
# Обновляем баланс в экономической системе
economy.update_balance(user_id, winnings, 'casino_win', f'Выигрыш в казино x{multiplier}')
new_balance = economy.get_user_balance(user_id)
if matches == 3:
return (
f"🎰 {slots_display}\n\n"
f"🎉 ДЖЕКПОТ!!! Три одинаковых!\n"
f"Множитель: x{multiplier}\n"
f"Выигрыш: +{winnings:.1f} см\n"
f"<EFBFBD> Баланс: {new_balance:.1f} см"
)
return (
f"🎰 {slots_display}\n\n"
f"✅ Выигрыш! Две совпали.\n"
f"Множитель: x{multiplier}\n"
f"Выигрыш: +{winnings:.1f} см\n"
f"<EFBFBD> Баланс: {new_balance:.1f} см"
)
else:
# Обновляем баланс в экономической системе
economy.update_balance(user_id, -bet, 'casino_loss', f'Проигрыш в казино -{bet} см')
new_balance = economy.get_user_balance(user_id)
return (
f"🎰 {slots_display}\n\n"
f"❌ Мимо, братуха.\n"
f"Проигрыш: -{bet:.1f} см\n"
f"<EFBFBD> Баланс: {new_balance:.1f} см"
)