From b57f1e08efb0157ecf479df4caa324071f3bebf0 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Wed, 29 Oct 2025 15:07:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=A7=AF=E5=88=86?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E4=B8=AD=E6=8C=87=E4=BB=A4=E5=88=86=E6=9E=90?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- games/alchemy.py | 122 ++++++++++++----------------------------------- games/points.py | 14 ++---- 2 files changed, 36 insertions(+), 100 deletions(-) diff --git a/games/alchemy.py b/games/alchemy.py index 8fffbcd..4f4c55d 100644 --- a/games/alchemy.py +++ b/games/alchemy.py @@ -5,6 +5,7 @@ from datetime import datetime from games.base import BaseGame from utils.parser import CommandParser from core.database import get_db +from typing import * logger = logging.getLogger(__name__) @@ -18,61 +19,22 @@ class AlchemyGame(BaseGame): self.db = get_db() # 奖品池配置 - 确保数学期望等于消耗积分 - # 消耗10积分时的奖品池 - 数学期望约10.5 - self.prize_pool_10 = [ - # 负面奖励 (概率, 类型, 数值, 描述) - (0.05, "penalty", -5, "炼金失败,损失积分"), # 5% 概率损失5积分 - (0.02, "penalty", -10, "炼金爆炸,损失积分"), # 2% 概率损失10积分 - - # 普通奖励 (概率, 类型, 数值, 描述) - (0.30, "points", 5, "少量积分"), # 30% 概率获得5积分 - (0.25, "points", 8, "少量积分"), # 25% 概率获得8积分 - (0.20, "points", 10, "等值积分"), # 20% 概率获得10积分 - (0.10, "points", 15, "丰厚积分"), # 10% 概率获得15积分 - (0.05, "points", 20, "丰厚积分"), # 5% 概率获得20积分 - - # 大奖 (概率, 类型, 数值, 描述) - (0.02, "points", 50, "🌟 巨额积分"), # 2% 概率获得50积分 - (0.01, "points", 100, "💎 传说积分"), # 1% 概率获得100积分 - ] - - # 消耗20积分时的奖品池 - 数学期望约21 - self.prize_pool_20 = [ - # 负面奖励 - (0.03, "penalty", -10, "炼金失败,损失积分"), # 3% 概率损失10积分 - (0.02, "penalty", -20, "炼金爆炸,损失积分"), # 2% 概率损失20积分 - - # 普通奖励 - (0.25, "points", 8, "少量积分"), # 25% 概率获得8积分 - (0.20, "points", 12, "少量积分"), # 20% 概率获得12积分 - (0.20, "points", 20, "等值积分"), # 20% 概率获得20积分 - (0.15, "points", 25, "丰厚积分"), # 15% 概率获得25积分 - (0.10, "points", 30, "丰厚积分"), # 10% 概率获得30积分 - (0.05, "points", 40, "丰厚积分"), # 5% 概率获得40积分 - - # 大奖 - (0.03, "points", 80, "🌟 巨额积分"), # 3% 概率获得80积分 - (0.02, "points", 150, "💎 传说积分"), # 2% 概率获得150积分 - ] - - # 消耗50积分时的奖品池 - 数学期望约52 - self.prize_pool_50 = [ - # 负面奖励 - (0.02, "penalty", -25, "炼金失败,损失积分"), # 2% 概率损失25积分 - (0.01, "penalty", -50, "炼金爆炸,损失积分"), # 1% 概率损失50积分 - - # 普通奖励 - (0.20, "points", 20, "少量积分"), # 20% 概率获得20积分 - (0.20, "points", 30, "少量积分"), # 20% 概率获得30积分 - (0.20, "points", 50, "等值积分"), # 20% 概率获得50积分 - (0.15, "points", 60, "丰厚积分"), # 15% 概率获得60积分 - (0.12, "points", 75, "丰厚积分"), # 12% 概率获得75积分 - (0.08, "points", 100, "丰厚积分"), # 8% 概率获得100积分 - - # 大奖 - (0.02, "points", 150, "🌟 巨额积分"), # 2% 概率获得150积分 - (0.00, "points", 300, "💎 传说积分"), # 0% 概率获得300积分(预留) + self.prize_pool: List[Tuple[int, str, float, str]] = [ + # (权重, 类型, 倍率, 描述) + (9, "penalty", 0, "炼金失败"), + (1, "penalty", -1, "炼金爆炸"), + (200, "points", 0.1, "少量积分"), + (490, "points", 0.5, "少量积分"), + (600, "points", 1, "等值积分"), + (490, "points", 2, "丰厚积分"), + (200, "points", 5, "丰厚积分"), + (9, "points", 10, "🌟 巨额积分"), + (1, "points", 100, "💎 传说积分"), ] + + self.total_weight: int = 0 + for weight,_,_,_ in self.prize_pool: + self.total_weight += weight async def handle(self, command: str, chat_id: int, user_id: int) -> str: """处理炼金相关指令 @@ -101,8 +63,6 @@ class AlchemyGame(BaseGame): cost_points = 10 # 默认消耗10积分 if args.isdigit(): cost_points = int(args) - if cost_points not in [10, 20, 50]: - return "❌ 炼金消耗积分只能是 10、20 或 50" return self._perform_alchemy(user_id, cost_points) @@ -126,17 +86,11 @@ class AlchemyGame(BaseGame): return f"❌ 积分不足!需要 {cost_points} 积分,当前可用 {user_points['points']} 积分" # 选择奖品池 - if cost_points == 10: - prize_pool = self.prize_pool_10 - elif cost_points == 20: - prize_pool = self.prize_pool_20 - elif cost_points == 50: - prize_pool = self.prize_pool_50 - else: - return "❌ 不支持的炼金消耗积分" + prize_pool = self.prize_pool # 执行抽奖 reward = self._draw_prize(prize_pool) + reward_points = reward['value']*cost_points # 消费积分 if not self.db.consume_points(user_id, cost_points, "alchemy", f"炼金抽奖消耗"): @@ -145,10 +99,10 @@ class AlchemyGame(BaseGame): # 处理奖励 if reward['type'] == 'points' and reward['value'] > 0: # 获得积分奖励 - self.db.add_points(user_id, reward['value'], "alchemy", f"炼金奖励") + self.db.add_points(user_id, reward_points, "alchemy", f"炼金奖励") elif reward['type'] == 'penalty' and reward['value'] < 0: # 负面奖励(扣分) - penalty_points = abs(reward['value']) + penalty_points = abs(reward_points) self.db.consume_points(user_id, penalty_points, "alchemy", f"炼金失败") # 炼金系统已简化,不再记录历史 @@ -160,24 +114,10 @@ class AlchemyGame(BaseGame): text = f"## ⚗️ 炼金结果\n\n" text += f"**消耗积分**:{cost_points} 分\n\n" - if reward['type'] == 'points' and reward['value'] > 0: - # 根据奖励大小选择不同的表情符号 - if reward['value'] >= 100: - emoji = "👑" - text += f"**{emoji} 传说奖励**:{reward['value']} 积分\n\n" - elif reward['value'] >= 50: - emoji = "💎" - text += f"**{emoji} 巨额奖励**:{reward['value']} 积分\n\n" - else: - emoji = "🎁" - text += f"**{emoji} 获得奖励**:{reward['value']} 积分\n\n" - text += f"**奖励描述**:{reward['description']}\n\n" - elif reward['type'] == 'penalty' and reward['value'] < 0: - penalty_points = abs(reward['value']) - text += f"**💥 炼金失败**:损失 {penalty_points} 积分\n\n" - text += f"**失败原因**:{reward['description']}\n\n" - else: - text += f"**获得奖励**:{reward['description']}\n\n" + if reward['type'] == 'points': + text += f"**{reward['description']}**: 获得{reward_points} 积分\n\n" + elif reward['type'] == 'penalty': + text += f"**{reward['description']}**: 损失 {abs(reward_points)} 积分\n\n" text += f"**当前积分**:{updated_points['points']} 分\n\n" text += "---\n\n" @@ -195,11 +135,11 @@ class AlchemyGame(BaseGame): 奖品信息 """ # 生成随机数 - rand = random.random() + rand = random.random()*self.total_weight cumulative_prob = 0.0 - for prob, reward_type, reward_value, description in prize_pool: - cumulative_prob += prob + for weight, reward_type, reward_value, description in prize_pool: + cumulative_prob += weight if rand <= cumulative_prob: return { 'type': reward_type, @@ -207,11 +147,11 @@ class AlchemyGame(BaseGame): 'description': description } - # 兜底返回最后一个奖品 + # 兜底返回第一个奖品 return { - 'type': prize_pool[-1][1], - 'value': prize_pool[-1][2], - 'description': prize_pool[-1][3] + 'type': prize_pool[0][1], + 'value': prize_pool[0][2], + 'description': prize_pool[0][3] } def _get_alchemy_stats(self, user_id: int) -> str: diff --git a/games/points.py b/games/points.py index 8cc2d9d..d90a125 100644 --- a/games/points.py +++ b/games/points.py @@ -33,18 +33,14 @@ class PointsGame(BaseGame): _, args = CommandParser.extract_command_args(command) args = args.strip().lower() - # 每日签到 - if args in ['checkin', '签到', '打卡']: - return self._daily_checkin(user_id) - # 积分排行榜 - elif args in ['leaderboard', '排行榜', '排行']: + if args in ['leaderboard', '排行榜', '排行']: return self._get_leaderboard() - # 默认:查看个人积分 + # 默认:每日签到 else: - return self._get_user_points(user_id) + return self._daily_checkin(user_id) except Exception as e: logger.error(f"处理积分指令错误: {e}", exc_info=True) @@ -65,7 +61,7 @@ class PointsGame(BaseGame): # 检查是否已签到 today = datetime.now().strftime('%Y-%m-%d') if self.db.check_daily_checkin(user_id, today): - return f"❌ 今日已签到,明天再来吧!\n\n📅 签到日期:{today}" + return self._get_user_points(user_id) # 执行签到 try: @@ -102,7 +98,7 @@ class PointsGame(BaseGame): text += f"**当前积分**:{points_info['points']} 分\n\n" text += "---\n\n" text += "💡 提示:\n" - text += "• 每日签到可获得 10 积分\n" + text += "• 每日签到可获得 100 积分\n" text += "• 查看运势可获得随机积分\n" text += "• 使用 `.points leaderboard` 查看排行榜"