add 飞行状态、上马状态、跟随状态监控
This commit is contained in:
@@ -13,11 +13,11 @@ try:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 默认布局参数
|
||||
# 默认布局参数(与 LogicBeacon:锚点 + 9 个数据块 对齐,需盖住第 9、10 格)
|
||||
_DEFAULTS = {
|
||||
"pixel_size": 17,
|
||||
"block_start_x": 30,
|
||||
"scan_region_width": 155,
|
||||
"scan_region_width": 190,
|
||||
"scan_region_height": 15,
|
||||
"offset_left": 20,
|
||||
"offset_top": 45,
|
||||
@@ -62,6 +62,51 @@ def load_layout_config():
|
||||
return cfg
|
||||
|
||||
|
||||
def _tri_state_from_r(channel_byte):
|
||||
"""Lua SetColorTexture 的 R 通道 0 / 0.5 / 1.0 → 与最近档位对齐(抗截图量化误差)"""
|
||||
v = channel_byte / 255.0
|
||||
return min((0.0, 0.5, 1.0), key=lambda t: abs(t - v))
|
||||
|
||||
|
||||
def _tri_state_label(value, low_mid_high):
|
||||
"""将 0 / 0.5 / 1.0 三档转为对应中文说明(抗浮点误差)"""
|
||||
v = float(value) if value is not None else 0.0
|
||||
if v < 0.25:
|
||||
return low_mid_high[0]
|
||||
if v < 0.75:
|
||||
return low_mid_high[1]
|
||||
return low_mid_high[2]
|
||||
|
||||
|
||||
def format_game_state_line(state):
|
||||
"""单行状态文字(中文),供 CLI 与 GUI 共用。"""
|
||||
death_txt = ('存活', '尸体', '灵魂')[state.get('death_state', 0)]
|
||||
target_hp = state.get('target_hp')
|
||||
if target_hp is not None:
|
||||
hp_part = f"血:{state['hp']}% 目标血:{target_hp}% 法:{state['mp']}%"
|
||||
else:
|
||||
hp_part = f"血:{state['hp']}% 法:{state['mp']}%"
|
||||
combat_txt = '战斗中' if state['combat'] else '未战斗'
|
||||
target_txt = '有敌对目标' if state['target'] else '无有效目标'
|
||||
flight_txt = _tri_state_label(
|
||||
state.get('flight', 0),
|
||||
('地面', '待起飞', '飞行中'),
|
||||
)
|
||||
mounted_txt = '已上马' if state.get('mounted') else '未上马'
|
||||
flyable_txt = '区域可飞' if state.get('flyable') else '区域不可飞'
|
||||
follow_txt = _tri_state_label(
|
||||
state.get('follow', 0),
|
||||
('未跟随', '需补跟随', '跟随中'),
|
||||
)
|
||||
return (
|
||||
f"{hp_part} | "
|
||||
f"{combat_txt} {target_txt} | "
|
||||
f"空格:{state.get('free_slots', 0)} 耐久:{state.get('durability', 0):.0%} {death_txt} | "
|
||||
f"x:{state['x']} y:{state['y']} 朝向:{state['facing']:.1f}° | "
|
||||
f"{flight_txt} {mounted_txt} {flyable_txt} {follow_txt}"
|
||||
)
|
||||
|
||||
|
||||
def save_layout_config(cfg):
|
||||
"""保存布局配置到 game_state_config.json"""
|
||||
path = _get_config_path()
|
||||
@@ -101,8 +146,11 @@ def parse_game_state():
|
||||
os.makedirs(SCREENSHOT_DIR, exist_ok=True)
|
||||
screenshot.save(os.path.join(SCREENSHOT_DIR, 'game_state.png'))
|
||||
|
||||
# 按截图像素分段:每 pixel_size 一格 → hp, mp, combat, target, logistics_death, x, y
|
||||
CHANNEL_NAMES = ('hp', 'mp', 'combat', 'target', 'logistics_death', 'x', 'y')
|
||||
# 每 pixel_size 一格 → … x, y, 飞行块(pixels[9]), 跟随(pixels[10])
|
||||
CHANNEL_NAMES = (
|
||||
'hp', 'mp', 'combat', 'target', 'logistics_death', 'x', 'y',
|
||||
'flight_block', 'follow',
|
||||
)
|
||||
for idx, name in enumerate(CHANNEL_NAMES):
|
||||
left = block_start_x + idx * pixel_size
|
||||
box = (left, 0, left + pixel_size, pixel_size)
|
||||
@@ -146,6 +194,16 @@ def parse_game_state():
|
||||
p7 = get_val(6)
|
||||
state['y'] = round((p7[0] + p7[1]/100), 2)
|
||||
|
||||
# 第 9 像素(Lua pixels[9]):R=飞行信号,G=上马,B=可飞区域
|
||||
p9 = get_val(7)
|
||||
state['flight'] = _tri_state_from_r(p9[0])
|
||||
state['mounted'] = p9[1] > 127
|
||||
state['flyable'] = p9[2] > 127
|
||||
|
||||
# 第 10 像素(Lua pixels[10]):R=跟随信号
|
||||
p10 = get_val(8)
|
||||
state['follow'] = _tri_state_from_r(p10[0])
|
||||
|
||||
return state
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -154,14 +212,7 @@ if __name__ == "__main__":
|
||||
while True:
|
||||
state = parse_game_state()
|
||||
if state:
|
||||
death_txt = ('存活', '尸体', '灵魂')[state.get('death_state', 0)]
|
||||
print(
|
||||
f"\r[状态] 血:{state['hp']}% 法:{state['mp']}% 目标血:{state.get('target_hp', 0)}% | "
|
||||
f"战斗:{'Y' if state['combat'] else 'N'} 目标:{'Y' if state['target'] else 'N'} | "
|
||||
f"空格:{state.get('free_slots', 0)} 耐久:{state.get('durability', 0):.0%} {death_txt} | "
|
||||
f"x:{state['x']} y:{state['y']} 朝向:{state['facing']:.1f}°",
|
||||
end=""
|
||||
)
|
||||
print(f"\r[状态] {format_game_state_line(state)}", end="")
|
||||
time.sleep(0.5)
|
||||
except KeyboardInterrupt:
|
||||
print("\n已停止。")
|
||||
Reference in New Issue
Block a user