ba-auto-daily/ba_dailies.sh

122 lines
2.2 KiB
Bash

#!/bin/bash
export DISPLAY=:0
export XAUTHORITY=/run/user/1000/gdm/Xauthority
WIN_NAME="BlueArchive"
MAILBOX_ICON="1726 60"
CLAIM_ALL="1691 1128"
CAFE_ICON="165 1100"
CAFE_ROOM_SWITCH="190 160"
CAFE_INCOME="1780 1105"
VENV_PYTHON="$HOME/.venvs/ba-auto-daily/bin/python3"
DETECT_SPARKLE="$HOME/ba_scripts/detect_and_click.py"
CAFE_MAX_CLICKS_PER_ROOM=15
get_window() {
xdotool search --name "$WIN_NAME" | head -1
}
click() {
local coords="$1"
xdotool mousemove $coords click 1
sleep 0.5
}
press_enter() {
xdotool key Return
sleep 0.5
}
press_esc() {
xdotool key Escape
sleep 0.5
}
focus_game() {
local win
win=$(get_window)
if [ -z "$win" ]; then
echo "ERROR: Blue Archive window not found. Is the game running?"
exit 1
fi
xdotool windowactivate "$win"
sleep 0.5
}
do_mailbox() {
echo "[mailbox] Opening mailbox..."
click "$MAILBOX_ICON"
sleep 1.5
echo "[mailbox] Claiming all..."
click "$CLAIM_ALL"
sleep 1
echo "[mailbox] Confirming claim..."
press_enter
sleep 1
echo "[mailbox] Closing mailbox..."
press_esc
sleep 1
echo "[mailbox] Done."
}
do_cafe_room() {
local i
for ((i = 0; i < CAFE_MAX_CLICKS_PER_ROOM; i++)); do
if ! "$VENV_PYTHON" "$DETECT_SPARKLE" | grep -q "^MATCH"; then
break
fi
sleep 1
press_enter
done
}
do_cafe() {
echo "[cafe] Opening cafe..."
click "$CAFE_ICON"
sleep 3
press_enter
echo "[cafe] Room 1: farming affection..."
do_cafe_room
echo "[cafe] Switching to room 2..."
click "$CAFE_ROOM_SWITCH"
sleep 3
press_enter
echo "[cafe] Room 2: farming affection..."
do_cafe_room
echo "[cafe] Claiming cafe income..."
click "$CAFE_INCOME"
sleep 2
press_enter
sleep 2
press_enter
sleep 2
echo "[cafe] Exiting cafe..."
press_esc
sleep 1.5
press_esc
sleep 1.5
echo "[cafe] Done."
}
case "$1" in
mailbox)
focus_game
do_mailbox
;;
cafe)
focus_game
do_cafe
;;
"")
focus_game
do_mailbox
do_cafe
echo "All done."
;;
*)
echo "Unknown phase: $1"
exit 1
;;
esac