Expert guide for developing and maintaining Python-based game automation bots using computer vision (OpenCV, YOLO) and PyAutoGUI for the Lineage game
Expert assistant for developing and maintaining Python-based game automation bots for Lineage. Specializes in computer vision (OpenCV, YOLO), PyAutoGUI automation, threaded architecture, and state machine implementations.
This skill provides expert guidance for working with the Lineage bot codebase, which uses:
When working with this codebase:
- `WindowCapture`: Continuously captures game window screenshots using Win32 API
- `YoloDetection`: Processes frames for object detection in real-time
- `Bot`: Runs state machine logic and controls PyAutoGUI actions
- Screenshot coordinates (relative to captured image)
- Screen coordinates (absolute positions for PyAutoGUI)
- Use `get_screen_position()` for translation with 8px border and 30px titlebar offsets
When adding a new bot variant:
1. **Create bot directory structure**:
```
src/bots/new_area/
├── bot.py # Bot class with state machine
├── runner.py # Main entry point
└── variants/ # Optional variants (mage, warrior, etc.)
```
2. **Copy and customize bot class** from existing area (e.g., `chi2/bot.py`):
- Adjust tunable constants for area-specific behavior
- Configure detection radius (`INNER_IGNORE_RADIUS`, `OUTER_IGNORE_RADIUS`)
- Set skill cooldowns (`SKILL_F7_DELAY`, `SKILL_F9_DELAY`)
- Tune movement timers (`SKILL_MOVE_DELAY`, `DETECTION_WAITING_THRESHOLD`)
3. **Implement state machine logic** with states:
- `INITIALIZING`: Setup phase
- `SEARCHING`: Looking for targets
- `MOVING`: Character movement
- `MINING`: Combat/interaction
- `BACKTRACKING`: Recovery state
4. **Create runner script** in `scripts/run_new_area.py`:
- Initialize WindowCapture with game window title
- Initialize YoloDetection with model path (`models/yolo/area_name.pt`)
- Initialize Vision and Bot instances
- Coordinate threaded execution with proper Lock synchronization
5. **Add batch script** in `bin/new_area.bat` for Windows execution
When working with detection models:
1. **Collect training data** using `tools/capture.py`
2. **Train YOLO model** using external tools (Ultralytics, Roboflow)
3. **Place trained model** in `models/yolo/area_name.pt`
4. **Test model** using `tools/train/test_yolo_img.py`
5. **Adjust confidence threshold** in runner script (typically 0.5-0.7)
When implementing threaded components:
When implementing target detection and selection:
1. **Filter targets by distance** using `targets_ordered_by_distance()`:
- Apply inner/outer radius constraints
- Calculate pythagorean distance from screen center
2. **Deduplicate targets** using ignore list:
- Store summed coordinates `(x + y + distance)` in `ignore_positions`
- Check with `is_duplicated_target()` before attacking
- Clear on F5 press (movement action)
3. **Prioritize targets** by distance (closest first)
When debugging bot behavior:
- `q`: Quit bot
- `p`: Pause execution
- `c`: Continue execution
When organizing code:
When configuring bot behavior:
```python
INNER_IGNORE_RADIUS = 0 # Minimum detection distance
OUTER_IGNORE_RADIUS = 500 # Maximum detection distance
SKILL_F7_DELAY = 10.0 # F7 skill cooldown
SKILL_F9_DELAY = 15.0 # F9 skill cooldown
SKILL_MOVE_DELAY = 25.0 # Time before triggering movement
DETECTION_WAITING_THRESHOLD = 6.0 # Timeout before moving (no targets)
ATTACK_INTERVAL = 1.2 # Duration of attack action
ENABLE_F7 = True
ENABLE_F9 = True
ENABLE_MOVING = True
```
When setting up development environment:
1. **Create virtual environment**: `python -m venv .venv`
2. **Activate environment**:
- Windows: `.\.venv\Scripts\activate`
- macOS/Linux: `source .venv/bin/activate`
3. **Install dependencies**: `pip install -r requirements.txt`
4. **Note**: Requires Windows for Win32 API (pywin32 dependency)
When implementing bot features:
```python
from src.core.bot_base import BotBase
class Forest3Bot(BotBase):
INNER_IGNORE_RADIUS = 50
OUTER_IGNORE_RADIUS = 450
SKILL_F7_DELAY = 12.0
SKILL_F9_DELAY = 18.0
SKILL_MOVE_DELAY = 30.0
# ... implement state machine logic
from src.core.window_capture import WindowCapture
from src.core.detection.yolo import YoloDetection
from src.bots.forest3.bot import Forest3Bot
def main():
wincap = WindowCapture('Lineage')
detector = YoloDetection('models/yolo/forest3.pt', conf=0.6)
bot = Forest3Bot(wincap, detector)
# Start threads and run...
from src.bots.forest3.runner import main
if __name__ == '__main__':
main()
```
```python
from src.core.utils.bot_utils import targets_ordered_by_distance, find_next_target
click_points = self.vision.get_click_points()
ordered_targets = targets_ordered_by_distance(
click_points,
self.wincap.w // 2,
self.wincap.h // 2,
self.INNER_IGNORE_RADIUS,
self.OUTER_IGNORE_RADIUS
)
target = find_next_target(ordered_targets, self.ignore_positions)
if target:
x, y, distance = target
screen_x, screen_y = self.wincap.get_screen_position((x, y))
pyautogui.click(screen_x, screen_y)
self.ignore_positions.append(x + y + distance)
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/lineage-bot-development-assistant/raw