johanntang
1/17/2018 - 10:21 PM

idlechampions.ahk

#SingleInstance force
#NoEnv
global uiDelay := 200
global transitionDelay := 1000

global middleScreenX := 620
global middleScreenY := 400
global resetAutoProgressX := 1246
global resetAutoProgressY := 145

CoordMode, Mouse, Relative
CoordMode, Pixel, Relative

`::         ; Press ` to Exit the script program
Send {Shift Up}
Send {Alt Up}
exitapp
+!`::       ; So that above can be used during the loops while holding down Shift and Alt
Send {Shift Up}
Send {Alt Up}

^!p::Pause      ; Press Ctrl+Alt+P to pause. Press it again to resume
+^!p::Pause     ; So that above can be used during the loops while holding down Shift and Alt

#IfWinActive ahk_exe IdleDragons.exe
^j::            ; Toggle the script on/off
    toggle := !toggle   ; Turns toggle on if it is off, and off if it is on
    if (toggle) {
        SetTimer, Timer_Spam, 1000
    } else {
        SetTimer, Timer_Spam, Off
    }
return


F12::
ClickDamageUpgrade()
Return

Timer_Spam:
IfWinActive ahk_exe IdleDragons.exe
{
    CheckWindow()
    IfEqual,toggle,0,return                     ; The following lines are a safety net

    SelectTown()
    SelectAdventure()
    Sleep, 6000
    CheckWindow()
    IfEqual,toggle,0,return                     ; The following lines are a safety net

    ResetAutoProgress()
    Loop ; Endless loop with just Click, damage
    {
        Loop, 50 {
            Click, 170, 500
            Sleep, 10
        }

        CheckWindow()
        IfEqual,toggle,0,return                     ; The following lines are a safety net

        ClickDamageUpgrade()
        Sleep, %uiDelay%
        CheckWindow()
        IfEqual,toggle,0,return                     ; The following lines are a safety net

        PixelGetColor, color, %resetAutoProgressX%, %resetAutoProgressY%
        IfEqual, color, 0xFFFFFF
        {
            Break ; Reset adventure when autoprogress was turned off
        }
    }

    ResetMission()
}

Return

ResetAutoProgress()
{
  autoProgressColor := 0xFFFFFF
  Click, %resetAutoProgressX%, %resetAutoProgressY%, 0
  Sleep, %uiDelay%
  PixelGetColor, color, %resetAutoProgressX%, %resetAutoProgressY%
  If(color = autoProgressColor)
  {
      Click, %resetAutoProgressX%, %resetAutoProgressY%
      Sleep, %transitionDelay%
  }
}

SelectTown()
{
  campaignX := 100
  grandTourY := 140
  tombOfAnnihilationY := 200

  Loop 10 ;Zoom map out FULLY
  {
      MouseClick, WheelDown, %middleScreenX%, %middleScreenY%
      Sleep, 20
  }
  Sleep, %uiDelay%
  Click, %campaignX%,  %tombOfAnnihilationY%     ; Select Tomb of Annihilation
  Sleep, %uiDelay%
  Click, %campaignX%, %grandTourY%      ; Select A Grang Tour of the Sword Coast
  Sleep, %uiDelay%
}

SelectAdventure()
{
  adventuresMenuButtonX := 745
  adventuresMenuButtonY := 400
  adventureListX := 400
  adventureListY := 385
  cursedFarmerFreePlayY := 435
  startObjectiveX := 800
  startObjectiveY := 600

  Click, %adventuresMenuButtonX%, %adventuresMenuButtonY%      ; Opens the Adventures Menu
  Sleep, %uiDelay%
  Loop, 20            ; Reset Adventure Menu Scroll to top
  {
      Click, %adventureListX%, %adventureListY%, 0
      MouseClick, WheelUp
      Sleep, 20
  }

  Sleep, %uiDelay%
  Click, %adventureListX%, %cursedFarmerFreePlayY%  ; Select Cursed Farmer Free Play
  Sleep, %uiDelay%

  Click, %startObjectiveX%, %startObjectiveY%  ; Start Game
}

LevelUpClickDamage()
{
  clickDamageX := 180
  clickDamageY := 745
  disabledColor := 0x7A7A7A

  Click, %clickDamageX%, %clickDamageY%, 0
  Loop,
  {
    PixelGetColor, color, %clickDamageX%, %clickDamageY%
    if (color = disabledColor)
      return
    Click, %clickDamageX%, %clickDamageY%
    Sleep, 20
  }
}

ClickDamageUpgrade()
{
  x1 = 137
  y1 = 739
  x2 = 145
  y2 = 742
  clickDamageX := 180
  clickDamageY := 745
  upgradeColor := 0x26AD4C
  color = 0x7A7A7A

  PixelSearch, x, y, x1, y1, x2, y2, %color%, 2, Fast
  if ErrorLevel
  {
    Click, %clickDamageX%, %clickDamageY%, 0
    LevelUpClickDamage()
  }
  return
}

ResetMission()
{
  completeAdventureX := 275
  completeAdventureY := 125
  completeConfirmX := 570
  completeConfirmY := 530
  continueColor := 0x26AD4C
  continueButtonX := 645
  continueButtonY := 650

  Sleep, %transitionDelay%
  Click, %completeAdventureX%, %completeAdventureY%
  Sleep, %transitionDelay%
  Click, %completeConfirmX%, %completeConfirmY%
  Sleep, %uiDelay%

  Loop,
  {
    Click, %continueButtonX%, %continueButtonY%, 0
    PixelGetColor, color, %continueButtonX%, %continueButtonY%
    If(color = continueColor)
    {
      Click, %continueButtonX%, %continueButtonY%
      return
    }
    Sleep, %uiDelayY%
  }
}

CheckWindow()
{
  IfWinNotActive ahk_exe IdleDragons.exe  ; if the current window stops being IdleChampions
  {                                       ; then the script with turn itself off as if you had
      toggle := 0                         ; pressed the toggle manually to turn it off.
      SetTimer, Timer_Spam, Off           ; This prevents the script from beginning to click
      return                              ; on any other windows by accident, which can be caused
  }
}