feat(赛马插件): 调整参与奖励并优化赛马显示对齐

- 将参与奖励从50点降低到20点以平衡经济系统
- 为所有马主添加参与奖励计算和发放逻辑
- 优化赛况显示中的马名对齐,支持中文字符宽度计算
This commit is contained in:
2026-04-06 23:21:21 +08:00
parent aca33820fc
commit 498d39b676
3 changed files with 21 additions and 2 deletions

View File

@@ -58,10 +58,21 @@ class RaceEngine:
lines = [f"【第{room.tick_count}回合】"]
sorted_horses = sorted(room.horses.values(), key=lambda h: h.index)
# Calculate max display width for name alignment
# Each CJK/fullwidth char counts as 2, others as 1
def _display_width(s: str) -> int:
w = 0
for ch in s:
w += 2 if '\u4e00' <= ch <= '\u9fff' or '\u3000' <= ch <= '\u303f' or '\uff00' <= ch <= '\uffef' else 1
return w
max_name_width = max(_display_width(h.name) for h in sorted_horses)
for horse in sorted_horses:
progress = min(horse.position / distance, 1.0)
filled = int(progress * bar_width)
bar = "" * filled + "" * (bar_width - filled)
lines.append(f" {horse.index:02d}{horse.name} |{bar}| {horse.position:.1f}m")
pad = " " * (max_name_width - _display_width(horse.name))
lines.append(f" {horse.index:02d}{horse.name}{pad} |{bar}| {horse.position:.1f}m")
return "\n".join(lines)