game_roles.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # -*- coding: utf-8 -*-
  2. """三国狼人杀角色定义"""
  3. from typing import Dict, List
  4. class GameRoles:
  5. """游戏角色管理类"""
  6. ROLES = {
  7. "狼人": {
  8. "description": "狼人",
  9. "ability": "夜晚可以击杀一名玩家",
  10. "win_condition": "消灭所有好人或与好人数量相等",
  11. "team": "狼人阵营"
  12. },
  13. "预言家": {
  14. "description": "预言家",
  15. "ability": "每晚可以查验一名玩家的身份",
  16. "win_condition": "消灭所有狼人",
  17. "team": "好人阵营"
  18. },
  19. "女巫": {
  20. "description": "女巫",
  21. "ability": "拥有解药和毒药各一瓶,可以救人或杀人",
  22. "win_condition": "消灭所有狼人",
  23. "team": "好人阵营"
  24. },
  25. "猎人": {
  26. "description": "猎人",
  27. "ability": "被投票出局时可以开枪带走一名玩家",
  28. "win_condition": "消灭所有狼人",
  29. "team": "好人阵营"
  30. },
  31. "村民": {
  32. "description": "村民",
  33. "ability": "无特殊技能,依靠推理和投票",
  34. "win_condition": "消灭所有狼人",
  35. "team": "好人阵营"
  36. },
  37. "守护者": {
  38. "description": "守护者",
  39. "ability": "每晚可以守护一名玩家免受狼人攻击",
  40. "win_condition": "消灭所有狼人",
  41. "team": "好人阵营"
  42. }
  43. }
  44. CHARACTER_TRAITS = {
  45. "刘备": "仁德宽厚,善于团结众人,说话温和有礼",
  46. "关羽": "忠义刚烈,言辞直接,重情重义",
  47. "张飞": "性格豪爽,说话大声直接,容易冲动",
  48. "诸葛亮": "智慧超群,分析透彻,言辞谨慎",
  49. "赵云": "忠勇双全,话语简洁有力",
  50. "曹操": "雄才大略,善于权谋,话语犀利",
  51. "司马懿": "深谋远虑,城府极深,言辞含蓄",
  52. "周瑜": "才华横溢,略显傲气,分析精准",
  53. "孙权": "年轻有为,善于决断,话语果决"
  54. }
  55. @classmethod
  56. def get_role_desc(cls, role: str) -> str:
  57. """获取角色描述"""
  58. return cls.ROLES.get(role, {}).get("description", "未知角色")
  59. @classmethod
  60. def get_role_ability(cls, role: str) -> str:
  61. """获取角色技能"""
  62. return cls.ROLES.get(role, {}).get("ability", "无特殊技能")
  63. @classmethod
  64. def get_character_trait(cls, character: str) -> str:
  65. """获取角色性格特点"""
  66. return cls.CHARACTER_TRAITS.get(character, "性格温和,说话得体")
  67. @classmethod
  68. def is_werewolf(cls, role: str) -> bool:
  69. """判断是否为狼人"""
  70. return role == "狼人"
  71. @classmethod
  72. def is_villager_team(cls, role: str) -> bool:
  73. """判断是否为好人阵营"""
  74. return cls.ROLES.get(role, {}).get("team") == "好人阵营"
  75. @classmethod
  76. def get_standard_setup(cls, player_count: int) -> List[str]:
  77. """获取标准角色配置"""
  78. if player_count == 6:
  79. return ["狼人", "狼人", "预言家", "女巫", "村民", "村民"]
  80. elif player_count == 8:
  81. return ["狼人", "狼人", "狼人", "预言家", "女巫", "猎人", "村民", "村民"]
  82. elif player_count == 9:
  83. return ["狼人", "狼人", "狼人", "预言家", "女巫", "猎人", "守护者", "村民", "村民"]
  84. else:
  85. # 默认配置:约1/3狼人
  86. werewolf_count = max(1, player_count // 3)
  87. roles = ["狼人"] * werewolf_count
  88. # 添加神职
  89. remaining = player_count - werewolf_count
  90. if remaining >= 1:
  91. roles.append("预言家")
  92. remaining -= 1
  93. if remaining >= 1:
  94. roles.append("女巫")
  95. remaining -= 1
  96. if remaining >= 1:
  97. roles.append("猎人")
  98. remaining -= 1
  99. # 剩余为村民
  100. roles.extend(["村民"] * remaining)
  101. return roles