BAAS Docs
Reference

Auto Fight and Recognition Development

Auto-fight workflows, state machines, screenshot data, template matching, OCR, screenshot methods, and image resources.

This page is migrated from the legacy develop_doc/script/auto_fight.md, game_feature.md, screenshot.md, and ocr.md. It explains how the backend extracts state from screenshots and executes combat workflows.

Development reference

Normal users only need to configure tasks in the Tauri client. This page is for backend auto-fight workflows, recognition assets, and source maintenance.

Auto Fight Model

BAAS auto fight is not the game's built-in Auto blindly casting skills. Instead, it:

  1. Captures screenshots continuously.
  2. Extracts cost, skills, HP, timers, positions, and other data.
  3. Evaluates conditions from a user-defined workflow.
  4. Releases skills or performs restart/end actions in the right state.

The legacy docs describe this as a finite-state machine:

Rendering diagram...

Workflow files are JSON and contain three core object types:

ObjectPurpose
stateCurrent flow node; executes an action and transitions by conditions
actionCast skill, restart, wait, toggle Auto, or another operation
conditionHP, cost, skill name, timeout, and composed predicates
Legacy auto-fight state-flow example

Observable Combat Data

Auto fight maintains screenshot-derived data that actions and conditions can read:

DataUsage
Boss current/max HPHP workflows, kill checks, restart checks
Skill-slot student namesDetect whether a target skill appears
Skill costDecide whether a skill can be cast
Current costTiming control
Speed / Auto stateConfirm combat state
Fight remaining timeTimeout and phase checks
Room remaining timeTotal Assault and timed modes
Student/enemy positionsTargeting, area skills, YOLO detection
Combat screen regions used by auto-fight data extraction Auto-fight screenshot data update cycle

Screenshot and Control Performance

Legacy screenshot-method guidance:

MethodNotes
nemuFast and lossless for MuMu 12; usually worth testing first
scrcpyFast, but not lossless
adbStable but slower
uiautomator2Stable but slower
mss / pyautoguiPC-client window capture

Performance varies by device and emulator. Auto fight, remote display, and daily tasks have different latency needs; do not blindly reuse one task's best setting for every scenario.

Template Matching

Template matching fits static images: buttons, icons, fixed UI elements, shop entries. It is CPU-friendly and can run in milliseconds. Its weakness is sensitivity to scale, rotation, color, and screenshot ratio.

Common function roles:

FunctionPurpose
compare_imageMatch a fixed screenshot region against a template
search_in_areaSearch a template inside a region and return best position/confidence
search_image_in_areaSearch with a runtime-provided template image
get_image_all_appear_positionReturn all positions above threshold
swipe_search_target_strSwipe until a target string or image appears
Template-matching example for fixed shop UI elements Swipe-search example in the normal shop

OCR

OCR recognizes text, numbers, HP, cost, event names, and other dynamic information that cannot be handled reliably by static templates. The legacy OCR service supported:

  • Multiple language models.
  • Single-line OCR.
  • General OCR.
  • Text-box detection.
  • Local image, remote image, or shared-memory transfer.

OCR costs more than template matching. Prefer templates for stable static UI; use OCR for text, numbers, and dynamic content.

OCR local-image pass method example

Recognition Asset Maintenance

When adding or updating recognition assets, confirm:

ItemRequirement
ResolutionPrefer standard 16:9 screenshots, ideally 1280x720
FormatUse lossless PNG
Language and serverMatch the target server resource directory
OcclusionAvoid cursor, popups, and notifications
NamingUse semantic names, not temporary screenshot names
ValidationTest on the target server and a clean profile

If recognition fails only on the PC client, check HDR, window ratio, screenshot method, and control method before recapturing templates.

On this page