比大小游戏修改

This commit is contained in:
2025-10-30 17:27:15 +08:00
parent 12aac846cc
commit 5a8a4ac026
3 changed files with 93 additions and 12 deletions

View File

@@ -439,5 +439,27 @@ if game_type == 'casino':
- 阻碍因素:无
- 状态:成功
[2025-10-30_17:20:00](预估时间)
- 已修改games/casino.py
- 更改:修改结算逻辑,从庄家指定结果改为系统随机生成
- 移除庄家输入种子/结果的参数
- 使用random.random()生成随机结果50%大/50%小)
- 更新帮助信息settle命令不再需要参数
- 原因:用户反馈庄家不应该能够操控游戏结果,庄家也是玩家
- 阻碍因素:无
- 状态:成功
[2025-10-30_17:26:19]
- 已修改games/casino.py, games/base.py
- 更改:添加庄家放弃游戏功能
- 新增_cancel_bigsmall()方法处理放弃逻辑
- 放弃时返还所有玩家下注
- 关闭会话并标记下注为cancelled
- 添加cancel命令支持cancel/放弃/关闭)
- 更新帮助信息和base.py中的帮助
- 原因:用户要求庄家可以放弃本轮游戏
- 阻碍因素:无
- 状态:成功
# 最终审查
待完成

View File

@@ -117,7 +117,8 @@ def get_help_message() -> str:
- `.赌场 大小 open <最小> <最大> <赔率>` - 庄家开启大小游戏
- `.赌场 大小 bet <大/小> <金额>` - 下注
- `.赌场 大小 status` - 查看状态
- `.赌场 大小 settle <大/小>` - 庄家结算
- `.赌场 大小 settle` - 庄家结算(系统随机)
- `.赌场 大小 cancel` - 庄家放弃游戏(返还下注)
### 其他
- `.help` - 显示帮助

View File

@@ -1,5 +1,6 @@
"""赌场游戏模块"""
import logging
import random
from games.base import BaseGame
from utils.parser import CommandParser
from core.database import get_db
@@ -79,6 +80,8 @@ class CasinoGame(BaseGame):
return await self._status_bigsmall(chat_id)
elif action in ['settle', '结算', '开奖']:
return await self._settle_bigsmall(sub_args, chat_id, user_id)
elif action in ['cancel', '放弃', '关闭']:
return await self._cancel_bigsmall(chat_id, user_id)
elif action in ['help', '帮助']:
return self._get_bigsmall_help()
else:
@@ -258,15 +261,15 @@ class CasinoGame(BaseGame):
text += f"- 压小:{bet_small} 分({len([b for b in bets if b['bet_type'] == ''])}注)\n"
text += f"- 总下注:{len(bets)}\n\n"
text += "---\n\n"
text += "💡 庄家可以使用 `.赌场 大小 settle <大/小>` 结算"
text += "💡 庄家可以使用 `.赌场 大小 settle` 结算"
return text
async def _settle_bigsmall(self, args: str, chat_id: int, user_id: int) -> str:
"""庄家结算游戏
"""庄家结算游戏(系统随机生成结果)
Args:
args: 结果 "<大/小>"
args: 无参数
chat_id: 会话ID
user_id: 用户ID
@@ -274,19 +277,16 @@ class CasinoGame(BaseGame):
结算结果消息
"""
try:
if not args:
return "❌ 请指定结算结果!\n\n正确格式:`.赌场 大小 settle <大/小>`"
result = args.strip()
if result not in ['', '']:
return f"❌ 结果类型错误!只支持'''',您输入的是:{result}"
# 不需要参数,系统自动随机生成结果
# 使用系统随机数决定大小50%概率)
result = '' if random.random() > 0.5 else ''
# 结算
settlement = self.db.settle_casino_bets(chat_id, '大小', result, user_id)
# 构建结算报告
text = f"## 🎰 大小游戏结算\n\n"
text += f"**结算结果**{result}\n\n"
text += f"**结算结果**🎲 {result}\n\n"
text += "---\n\n"
text += f"**赢家**{len(settlement['winners'])}\n"
text += f"**输家**{len(settlement['losers'])}\n\n"
@@ -316,6 +316,62 @@ class CasinoGame(BaseGame):
logger.error(f"结算失败: {e}", exc_info=True)
return f"❌ 结算失败: {str(e)}"
async def _cancel_bigsmall(self, chat_id: int, user_id: int) -> str:
"""庄家放弃本轮游戏
Args:
chat_id: 会话ID
user_id: 用户ID
Returns:
放弃结果消息
"""
try:
# 检查是否有活跃的会话
session = self.db.get_active_casino_session(chat_id, '大小')
if not session:
return "❌ 当前没有进行中的游戏"
# 验证是否为庄家
if session['banker_id'] != user_id:
return "❌ 只有庄家可以放弃游戏"
# 获取所有待结算下注
bets = self.db.get_pending_bets(chat_id, '大小')
# 返还所有下注的积分
return_amount = 0
for bet in bets:
# 返还积分
self.db.add_points(bet['user_id'], bet['amount'], 'casino_cancel',
"庄家放弃游戏,返还下注")
return_amount += bet['amount']
# 关闭会话(不结算,返还积分)
self.db.close_casino_session(chat_id, '大小')
# 标记下注为已取消
cursor = self.db.conn.cursor()
cursor.execute("""
UPDATE casino_bets
SET status = 'cancelled'
WHERE chat_id = ? AND game_type = ? AND status = 'pending'
""", (chat_id, '大小'))
# 构建报告
text = f"## 🎰 游戏已放弃\n\n"
text += f"**庄家**:用户{user_id}\n\n"
text += f"**总返还积分**{return_amount}\n\n"
text += f"**返还人数**{len(bets)}\n\n"
text += "---\n\n"
text += "✅ 所有下注已返还,游戏已关闭"
return text
except Exception as e:
logger.error(f"放弃游戏失败: {e}", exc_info=True)
return f"❌ 放弃游戏失败: {str(e)}"
def _get_bigsmall_help(self) -> str:
"""获取大小游戏帮助信息"""
return """## 🎰 大小游戏帮助
@@ -323,6 +379,8 @@ class CasinoGame(BaseGame):
### 庄家命令
- `.赌场 大小 open <最小> <最大> <赔率>` - 开启游戏
- 示例:`.赌场 大小 open 10 100 2.0`
- `.赌场 大小 settle` - 结算游戏(系统随机生成结果)
- `.赌场 大小 cancel` - 放弃游戏(返还所有下注)
### 玩家命令
- `.赌场 大小 bet <大/小> <金额>` - 下注
@@ -331,11 +389,11 @@ class CasinoGame(BaseGame):
### 通用命令
- `.赌场 大小 status` - 查看当前状态
- `.赌场 大小 settle <大/小>` - 庄家结算(仅庄家)
### 游戏规则
- 玩家下注后积分立即扣除
- 结算后根据结果发放奖励
- 庄家放弃游戏时,所有下注全额返还
- 系统抽水5%
- 赔率由庄家设置
"""