Files
cultivation-world-simulator/src/classes/alignment.py
2025-10-04 17:13:35 +08:00

44 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from enum import Enum
class Alignment(Enum):
"""
阵营:正/邪。
值使用英文,便于与代码/保存兼容__str__ 返回中文。
"""
RIGHTEOUS = "righteous" # 正
EVIL = "evil" # 邪
def __str__(self) -> str:
return alignment_strs.get(self, self.value)
def get_info(self) -> str:
return alignment_strs[self] + ": " + alignment_infos[self]
def __hash__(self) -> int:
return hash(self.value)
def __eq__(self, other) -> bool:
"""
允许与同类或字符串比较:
- Alignment: 恒等比较
- str: 同时支持英文值value与中文显示__str__
"""
if isinstance(other, Alignment):
return self is other
if isinstance(other, str):
return other == self.value or other == str(self)
return False
alignment_strs = {
Alignment.RIGHTEOUS: "",
Alignment.EVIL: "",
}
alignment_infos = {
Alignment.RIGHTEOUS: "正义阵营的理念是:扶助弱小,维护秩序,除魔卫道。",
Alignment.EVIL: "邪恶阵营的理念是:弱肉强食,以自身利益为先,蔑视规则,推崇权力与恐惧。",
}