This commit is contained in:
{ИМЯ}
2025-07-13 22:43:34 +03:00
parent e4dc7cd52a
commit fea53fdd8f

View File

@ -8,18 +8,23 @@ global targetWindow := "DirtyLeague"
global isRunning := false global isRunning := false
global actionQueue := [] global actionQueue := []
global timerStates := Map() global timerStates := Map()
global timerFunctions := [] global timerFunctions := [] ; PROPERLY INITIALIZED ARRAY
global startupDelay := 5000 ; 5-second global delay (ms) global startupDelay := 5000 ; 5-second global delay (ms)
; Timer configurations ; Timer configurations
timers := [ timers := [
[25, "Common", [1850, 1150]], [25, "Common", [1850, 1150]],
[50, "Rare", [1300, 450]], [50, "Rare", [1300, 450]],
[90, "Epic", [2520, 450]] [90, "Epic", [2520, 450]]
]
; Common click sequence
CommonSequence := [{ action: "Start Battle", pos: [1945, 1780], delay: 30000 }, { action: "Close Results", pos: [980,
1630], delay: 4000 }, { action: "Close Shop", pos: [3700, 120], delay: 4000 }
] ]
; === INITIALIZATION === ; === INITIALIZATION ===
Sleep startupDelay ; GLOBAL STARTUP DELAY HERE Sleep startupDelay ; GLOBAL STARTUP DELAY
SetupTimers() SetupTimers()
SetTimer ProcessQueue, 1000 SetTimer ProcessQueue, 1000
SetTimer UpdateStatusTooltip, 1000 SetTimer UpdateStatusTooltip, 1000
@ -40,33 +45,32 @@ SetTimer UpdateStatusTooltip, 1000
; === TIMER SETUP === ; === TIMER SETUP ===
SetupTimers() { SetupTimers() {
global timers, timerStates, timerFunctions, startupDelay global timers, timerStates, timerFunctions, startupDelay
For i, timer in timers { for i, timer in timers {
timerName := "Timer" i timerName := "Timer" i
ms := timer[1] * 60000 ms := timer[1] * 60000
timerStates[timerName] := { timerStates[timerName] := {
interval: ms, interval: ms,
nextRun: A_TickCount + startupDelay + (1000 * i), ; Includes global delay nextRun: A_TickCount + startupDelay + (1000 * i),
opponent: timer[2], opponent: timer[2],
position: timer[3] position: timer[3]
} }
fn := ObjBindMethod(MyTimer, "Trigger", timerName) fn := ObjBindMethod(MyTimer, "Trigger", timerName)
timerFunctions.Push(fn) timerFunctions.Push(fn)
SetTimer fn, ms SetTimer fn, ms
SetTimer fn, -(startupDelay + (1000 * i)) ; Respects global delay SetTimer fn, -(startupDelay + (1000 * i))
} }
} }
class MyTimer { class MyTimer {
static Trigger(name) { static Trigger(name) {
global actionQueue, timerStates global actionQueue, timerStates
; Update next run time for this timer ; Update next run time
timerStates[name].nextRun := A_TickCount + timerStates[name].interval timerStates[name].nextRun := A_TickCount + timerStates[name].interval
; Add to queue ; Add to queue
actionQueue.Push({ actionQueue.Push({
name: name, name: name,
@ -78,24 +82,24 @@ class MyTimer {
} }
ProcessQueue() { ProcessQueue() {
global isRunning, actionQueue, CommonSequence global isRunning, actionQueue, CommonSequence, targetWindow
if (!isRunning && actionQueue.Length > 0) { if (!isRunning && actionQueue.Length > 0) {
isRunning := true isRunning := true
current := actionQueue.RemoveAt(1) current := actionQueue.RemoveAt(1)
if WinExist(targetWindow) { if WinExist(targetWindow) {
WinActivate WinActivate
WinWaitActive WinWaitActive
; Opponent-specific step ; Opponent-specific step
ToolTip "Attacking: " current.opponent, 10, 10 ToolTip "Attacking: " current.opponent, 10, 10
MouseMove current.opponentPos[1], current.opponentPos[2] MouseMove current.opponentPos[1], current.opponentPos[2]
Click Click
Sleep 4000 Sleep 4000
; Common sequence ; Common sequence
For step in CommonSequence { for step in CommonSequence {
ToolTip step.action "...", 10, 10 ToolTip step.action "...", 10, 10
MouseMove step.pos[1], step.pos[2] MouseMove step.pos[1], step.pos[2]
Click Click
@ -105,24 +109,22 @@ ProcessQueue() {
ToolTip "ERROR: Window not found", 10, 10 ToolTip "ERROR: Window not found", 10, 10
Sleep 2000 Sleep 2000
} }
ToolTip ; Clear action tooltip ToolTip
isRunning := false isRunning := false
} }
} }
UpdateStatusTooltip() { UpdateStatusTooltip() {
global isRunning, timerStates global isRunning, timerStates, actionQueue
if (isRunning) { if (isRunning) {
; Don't update status during battles
return return
} }
statusText := "Next Battles:`n`n" statusText := "Next Battles:`n`n"
totalWidth := 300 ; Tooltip width in pixels totalWidth := 300
; Calculate time until next run for each timer
for name, timer in timerStates { for name, timer in timerStates {
remaining := timer.nextRun - A_TickCount remaining := timer.nextRun - A_TickCount
if (remaining < 0) { if (remaining < 0) {
@ -131,24 +133,22 @@ UpdateStatusTooltip() {
mins := Floor(remaining / 60000) mins := Floor(remaining / 60000)
secs := Mod(Floor(remaining / 1000), 60) secs := Mod(Floor(remaining / 1000), 60)
progress := 100 - (remaining * 100 / timer.interval) progress := 100 - (remaining * 100 / timer.interval)
progress := Min(Max(progress, 0), 100) ; Clamp 0-100 progress := Min(Max(progress, 0), 100)
; Create progress bar barWidth := Floor(totalWidth * (progress / 100))
barWidth := Floor(totalWidth * (progress/100)) progressBar := "[" . Format("{:-" barWidth "}", "")
progressBar := "[" . Format("{:-" barWidth "}", "") . Format("{:" (totalWidth - barWidth) "}", "") . "]"
. Format("{:" (totalWidth-barWidth) "}", "") . "]"
statusText .= name ": " Format("{1:02}:{2:02}", mins, secs)
statusText .= name ": " Format("{1:02}:{2:02}", mins, secs) . " (" progress "%)`n" progressBar "`n"
. " (" progress "%)`n" progressBar "`n"
} }
} }
; Add queue status if any
if (actionQueue.Length > 0) { if (actionQueue.Length > 0) {
statusText .= "`nQueued: " actionQueue.Length " battles" statusText .= "`nQueued: " actionQueue.Length " battles"
} }
ToolTip statusText, 10, 10, 1 ; Tooltip with ID 1 ToolTip statusText, 10, 10, 1
} }
; Clear tooltips when script exits ; Clear tooltips when script exits