1.status现在列出玩家列表2.修复狼人投票bug

This commit is contained in:
2025-11-10 10:28:08 +08:00
parent c7a4d3d047
commit 97692b120a
2 changed files with 48 additions and 4 deletions

View File

@@ -341,6 +341,38 @@ if game_type == 'werewolf':
- 状态:成功 - 状态:成功
[2025-11-10_10:20:38]
- 已修改:
1. games/werewolf.py - 调整status指令的房间名单展示
- 更改:
1. 房间开放阶段现在显示已加入玩家的房内ID与用户名
2. 游戏进行阶段的玩家状态显示同时包含房内ID和用户名
- 原因:
提升`.werewolf status`指令提供的信息量,方便玩家识别房间成员
- 阻碍因素:
- 状态:未确认
[2025-11-10_10:27:07]
- 已修改:
1. games/werewolf.py - 统一狼人投票记录的键类型
- 更改:
1. `_wolf_kill()` 读取和保存 `wolf_votes` 时转换为字符串键
2. 统计投票进度时将键重新转换为整数,确保与 `alive_wolves` 对齐
- 原因:
修复狼人全部投票后仍提示有人未投票的问题
- 阻碍因素:
- 状态:未确认
# 最终审查 # 最终审查
待审查阶段完成... 待审查阶段完成...

View File

@@ -744,7 +744,8 @@ class WerewolfGame(BaseGame):
# 记录投票(允许改票) # 记录投票(允许改票)
wolf_votes = state_data.get('wolf_votes', {}) wolf_votes = state_data.get('wolf_votes', {})
wolf_votes[player['user_id']] = target_id wolf_votes = {str(k): v for k, v in wolf_votes.items()}
wolf_votes[str(player['user_id'])] = target_id
state_data['wolf_votes'] = wolf_votes state_data['wolf_votes'] = wolf_votes
self._save_game_state(chat_id, state_data) self._save_game_state(chat_id, state_data)
@@ -755,7 +756,7 @@ class WerewolfGame(BaseGame):
alive_wolves.append(p['user_id']) alive_wolves.append(p['user_id'])
# 检查是否所有狼人都已投票 # 检查是否所有狼人都已投票
voted_wolves = set(wolf_votes.keys()) voted_wolves = {int(k) for k in wolf_votes.keys()}
all_wolves = set(alive_wolves) all_wolves = set(alive_wolves)
if not all_wolves.issubset(voted_wolves): if not all_wolves.issubset(voted_wolves):
@@ -1035,7 +1036,17 @@ class WerewolfGame(BaseGame):
status = state_data['status'] status = state_data['status']
if status == 'open': if status == 'open':
return f"## 🐺 狼人杀房间\n\n状态:等待玩家加入\n人数:{len(state_data['players'])}/{self.max_players}\n\n输入 `.werewolf join` 加入游戏" players = state_data.get('players', [])
msg = f"## 🐺 狼人杀房间\n\n状态:等待玩家加入\n人数:{len(players)}/{self.max_players}\n"
if players:
msg += "\n当前玩家:\n"
for player in players:
player_name = player.get('name') or "未知玩家"
msg += f"{player['id']}{player_name}\n"
else:
msg += "\n当前房间暂无玩家\n"
msg += "\n输入 `.werewolf join` 加入游戏"
return msg
if status != 'playing': if status != 'playing':
return "❌ 游戏未开始或已结束!" return "❌ 游戏未开始或已结束!"
@@ -1056,8 +1067,9 @@ class WerewolfGame(BaseGame):
alive_count = 0 alive_count = 0
dead_count = 0 dead_count = 0
for player in state_data['players']: for player in state_data['players']:
player_name = player.get('name') or "未知玩家"
status_icon = "❤️" if player['alive'] else "💀" status_icon = "❤️" if player['alive'] else "💀"
msg += f"{status_icon} {player['id_label']}\n" msg += f"{status_icon} {player['id']}{player_name}\n"
if player['alive']: if player['alive']:
alive_count += 1 alive_count += 1
else: else: