1.解决狼人的杀技能立即生效且消耗的bug2.狼人杀人后不应该播报全局消息
This commit is contained in:
@@ -324,6 +324,7 @@ class WerewolfGame(BaseGame):
|
||||
'round': 0,
|
||||
'wolves': [],
|
||||
'kill_target': None,
|
||||
'wolf_votes': {}, # 狼人投票记录 {user_id: target_id}
|
||||
'seer_result': {},
|
||||
'witch_save': False,
|
||||
'witch_poison': None,
|
||||
@@ -723,18 +724,74 @@ class WerewolfGame(BaseGame):
|
||||
if current_phase != 'night_kill':
|
||||
return f"❌ 当前不是狼人行动阶段!当前阶段:{self._get_phase_description(current_phase)['name']}"
|
||||
|
||||
# 记录投票
|
||||
# 简化:只要有一个狼人投票就算成功
|
||||
if state_data.get('kill_target') is None:
|
||||
state_data['kill_target'] = target_id
|
||||
# 记录投票(允许改票)
|
||||
wolf_votes = state_data.get('wolf_votes', {})
|
||||
wolf_votes[player['user_id']] = target_id
|
||||
state_data['wolf_votes'] = wolf_votes
|
||||
self._save_game_state(chat_id, state_data)
|
||||
|
||||
# 获取所有存活的狼人
|
||||
alive_wolves = []
|
||||
for p in state_data['players']:
|
||||
if p['role'] == 'wolf' and p['alive']:
|
||||
alive_wolves.append(p['user_id'])
|
||||
|
||||
# 检查是否所有狼人都已投票
|
||||
voted_wolves = set(wolf_votes.keys())
|
||||
all_wolves = set(alive_wolves)
|
||||
|
||||
if not all_wolves.issubset(voted_wolves):
|
||||
# 还有狼人未投票,私聊通知投票者
|
||||
not_voted_count = len(all_wolves - voted_wolves)
|
||||
vote_confirm_msg = f"## 🐺 投票确认\n\n✅ 你投票给 **{target_id}号玩家**\n\n⏳ 等待其他狼人投票(还有{not_voted_count}个狼人未投票)"
|
||||
await self._send_to_player(player['user_id'], vote_confirm_msg, sender="系统")
|
||||
|
||||
# 群消息不透露目标
|
||||
return f"✅ 投票已记录,等待其他狼人(还有{not_voted_count}个未投票)"
|
||||
|
||||
# 所有狼人都已投票,统计票数
|
||||
vote_count = {}
|
||||
for wolf_id, target in wolf_votes.items():
|
||||
if wolf_id in alive_wolves: # 只统计存活狼人的投票
|
||||
vote_count[target] = vote_count.get(target, 0) + 1
|
||||
|
||||
# 找出票数最多的目标
|
||||
max_votes = max(vote_count.values())
|
||||
top_targets = [tid for tid, count in vote_count.items() if count == max_votes]
|
||||
|
||||
# 判断是否平票
|
||||
if len(top_targets) > 1:
|
||||
# 平票,清除投票记录,要求重新投票
|
||||
state_data['wolf_votes'] = {}
|
||||
self._save_game_state(chat_id, state_data)
|
||||
|
||||
# 自动推进到下一阶段
|
||||
next_phase_msg = self._advance_phase(chat_id, state_data)
|
||||
# 私聊通知所有狼人平票结果
|
||||
targets_str = '、'.join([f"{tid}号" for tid in top_targets])
|
||||
for p in state_data['players']:
|
||||
if p['role'] == 'wolf' and p['alive']:
|
||||
tie_msg = f"## 🐺 狼人投票结果\n\n⚠️ 投票结果平票!\n\n票数最多的玩家:{targets_str}(各{max_votes}票)\n\n请重新投票"
|
||||
await self._send_to_player(p['user_id'], tie_msg, sender="系统")
|
||||
|
||||
return f"✅ 投票成功:刀{target_id}号玩家{next_phase_msg}"
|
||||
else:
|
||||
return f"⚠️ 今晚已经有了投票目标:{state_data['kill_target']}号"
|
||||
# 群消息不透露具体目标
|
||||
return f"⚠️ 狼人投票结果平票,请重新投票"
|
||||
|
||||
# 票数唯一,确定击杀目标
|
||||
kill_target = top_targets[0]
|
||||
state_data['kill_target'] = kill_target
|
||||
state_data['wolf_votes'] = {} # 清空投票记录
|
||||
self._save_game_state(chat_id, state_data)
|
||||
|
||||
# 私聊通知所有狼人投票结果
|
||||
for p in state_data['players']:
|
||||
if p['role'] == 'wolf' and p['alive']:
|
||||
vote_msg = f"## 🐺 狼人投票结果\n\n✅ 投票完成:决定刀 **{kill_target}号玩家**({max_votes}票)"
|
||||
await self._send_to_player(p['user_id'], vote_msg, sender="系统")
|
||||
|
||||
# 自动推进到下一阶段
|
||||
next_phase_msg = self._advance_phase(chat_id, state_data)
|
||||
|
||||
# 群消息不透露击杀目标
|
||||
return f"✅ 狼人投票完成{next_phase_msg}"
|
||||
|
||||
async def _seer_check(self, chat_id: int, state_data: Dict, player: Dict, target_id: int) -> str:
|
||||
"""预言家验人
|
||||
|
||||
Reference in New Issue
Block a user