property quitReason : ""
    property x : 0
    property y : 0
    property x1 : 0
    property y1 : 0
    property yCount : 0
    property xCount : 0
    property reps : 0
    property counter : 0
    property startTime : 0
    property curTime : 0
    property endTime : 999
    property lolIsRunning : false
    property button1 : {}
    property button2 : {}
    property button3 : {}
    property button4 : {}
    property timerOn : false
    property quitApp : false
    property xRatio : 0
    property yRatio : 0
    tell application "Extra Suites" to ES move mouse {0, 0}
    delay 1
    display dialog "remember to set your input.ini & persistedSettings"
    -- setting current time
    set startTime to do shell script "ruby -e 'print Time.now.to_f'"

    -- getting screen resolution

    tell application "Finder"
        set screenRes to bounds of window of desktop
        set screenResX to item 3 of screenRes
        set screenResY to item 4 of screenRes
    end tell

    -- set ratios that coordinates will be multiplied to

    set xRatio to screenResX / 1920
    set yRatio to screenResY / 1080

    -- use timer or not
    set timerOn to button returned of (display dialog "Use timer?" with title "Auto-League" buttons {"Yes", "No"})

    if timerOn = "Yes" then
        askTimer()

        if ((endTime ≥ 0) is false) then
            display dialog "Error in input, please input (a) valid integer(s)" with title "Auto-League"
            askTimer()
        end if
    end if

    set preferredChamp to text returned of (display dialog "Preferred champion? (leave blank if no preference)" default answer "" default button 2)



















    -- all coordinates
    property play : {960, 190}
    property PvP : {650, 270}
    property bots : {650, 330}
    property classic : {850, 300}
    property dominion : {850, 330}
    property summonersRift : {1040, 305}
    property twistedTreeline : {1040, 350}
    property summonersRiftBeginner : {1240, 330}
    property summonersRiftIntermediate : {1240, 355}
    property othersBeginner : {1240, 300}
    property othersIntermediate : {1240, 330}
    property blindPickSR : {1240, 355}
    property blindPickOthers : {1240, 310}
    property crystalScar : {1070, 310}
    property solo : {1070, 860}
    property profile : {1400, 200}
    property ranChamp : {645, 360}
    property lockIn : {1230, 675}
    property accept : {873, 594}
    property endGame : {958, 638}
    property playAgain : {1450, 885}
    property leaverBuster : {970, 605}
    property networkWarning : {960, 500}
    property reconnect : {960, 605}
    property report : {930, 640}
    property lvlQ : {750, 925}
    property lvlW : {825, 925}
    property lvlE : {890, 925}
    property lvlR : {960, 925}
    property closeShop : {1560, 35}
    property search : {1250, 285}
    property firstChamp : {715, 360}
    property changeShop : {540, 60}
    property secondShop : {430, 115}
    property firstShop : {430, 95}
    property home : {1230, 855}
    property callRole : {1000, 890}
    property sendMsg : {1275, 890}
    -- end of coordinates





















    set difficulty to button returned of (display dialog "Which difficulty?" with title "Auto-League" buttons {"PvP", "Beginner", "Intermediate"})

    set map to button returned of (display dialog "Which map?" with title "Auto-League" buttons {"Summoner's Rift", "Crystal Scar (less likely to be reported in PvP)", "Twisted Treeline"})

    -- SETTING BUTTONS
    -- if PvP is chosen click PvP, the rest are bots, so click co-op vs AI
    if difficulty = "PvP" then
        set button1 to PvP
    else
        set button1 to bots
    end if

    -- if crystal scar is chosen, click dominion, the rest of the maps are classic, so click classic
    if map = "Crystal Scar (less likely to be reported in PvP)" then
        set button2 to dominion
    else
        set button2 to classic
    end if

    -- if twisted treeline, click 2nd button from top, crystal scar and summoners rift are in the same spot, 1st form top, so click first button from top, but i wanted to keep the buttons seperate, so they use different variables
    if map = "Twisted Treeline" then
        set button3 to twistedTreeline
    else if map = "Summoner's Rift" then
        set button3 to summonersRift
    else if map = "Crystal Scar (less likely to be reported in PvP)" then
        set button3 to crystalScar
    end if

    -- pvp is only for blind pick, but buttons for SR and TT and CR are different
    if difficulty = "PvP" then
        if map = "Summoner's Rift" then
            set button4 to blindPickSR
        else
            set button4 to blindPickOthers
        end if
    end if

    if difficulty = "Beginner" then
        -- different spots for different maps 
        if map = "Summoner's Rift" then
            set button4 to summonersRiftBeginner
        else
            set button4 to othersBeginner
        end if
    end if

    if difficulty = "Intermediate" then
        -- different spots for different maps 
        if map = "Summoner's Rift" then
            set button4 to summonersRiftIntermediate
        else
            set button4 to othersIntermediate
        end if
    end if




    checkQuit()

    tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" to activate
    -- joining queue
    click(play)
    delay 0.1
    click(button1)
    delay 0.1
    click(button2)
    delay 0.1
    click(button3)
    delay 0.1
    click(button4)
    delay 0.1
    checkQuit()
    click(solo)

    checkQuit()
















    repeat


        set counter to 0
        checkQuit()
        -- repeat until client is not running, or game is running
        repeat until application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" is running or application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" is not running
            checkQuit()

            set counter to counter + 1

            if counter ≥ 250 then
                checkQuit()
                set counter to 0
                click(report)
                tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" to activate
                -- joining queue
                click(home)
                click(play)
                delay 0.1
                click(button1)
                delay 0.1
                click(button2)
                delay 0.1
                click(button3)
                delay 0.1
                click(button4)
                delay 0.1
                click(solo)
            end if
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" to activate

            click(reconnect)
            set curTime to do shell script "ruby -e 'print Time.now.to_f'"
            -- add exeption to curTime thingy so that it waits 3 mins to see if you were in champ select
            checkQuit()
            click(leaverBuster)
            click(playAgain)
            -- try to accept queue/select & lock in champion / reconnecting
            click(profile)
            click(accept)
            click(ranChamp)
            click(search)
            try
                delay 0.1
                tell application "Extra Suites"
                    activate
                    delay 0.1
                    click(search)
                    ES type string preferredChamp
                    quit
                    delay 0.2
                end tell
                delay 0.2
            end try
            -- click(firstChamp) this is commented out and replaced with ranChamp, as if you search for a champ, the ran champ location turns into the first champ location if the word "random" does not fit the search criteria
            click(ranChamp)
            delay 0.1
            click(lockIn)
            click(callRole)
            try
                if map = "Summoner's Rift" then
                    delay 0.1
                    tell application "Extra Suites"
                        activate
                        delay 0.1
                        ES type string "mid"
                        quit
                        delay 0.2
                    end tell
                    delay 0.2
                end if
            end try
            click(sendMsg)
            delay 2
            checkQuit()


        end repeat
        tell application "Safari" to quit
        -- repeat until game is closed 
        repeat until application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" is not running
            try
                if application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" is running then
                    tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
                end if
            end try

            randomMove()
            (*
            click(lvlQ)
            click(lvlW)
            click(lvlE)
            click(lvlR)
            *)
            clickGame(networkWarning)
            tell application "Extra Suites"
                delay 0.1
                activate
                delay 0.1
                try
                    tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
                end try
                -- use spells
                ES type key "r"
                ES type key "q"
                ES type key "w"
                ES type key "e"
                ES type key "1"
                ES type key "2"
                ES type key "3"
                ES type key "4"
                ES type key "5"
                ES type key "6"
                ES type key "c"
                ES type key "d"
                ES type key "f"
                quit
                delay 2
            end tell
            randomMove()
            tell application "Extra Suites" to ES type key "p"
            delay 1
            clickSingle(changeShop)
            delay 1
            clickGame(firstShop)
            --click(secondShop)
            delay 1
            randomItem(10)
            tell application "Extra Suites" to ES type key "p"
            clickGame(closeShop)
            delay 2

            clickGame(endGame)
            delay 3

        end repeat
    end repeat



















    -- SUBROUTINES
    on randomMove()
        if reps = 10 then
            set reps to 0
            tell application "Extra Suites"
                ES move mouse {xRatio * 638, 498 * yRatio}
                delay 0.1
                ES click mouse with double click
                delay 0.1
                ES click mouse with double click
                delay 0.1
                ES click mouse with double click
                delay 0.1
                ES click mouse with double click
            end tell
        else
            set reps to reps + 1
            repeat until x ≠ x1 or xCount = 10
                set x to (random number from 1725 to 1825)
                set xCount to xCount + 1
            end repeat
            if x ≠ x1 then set xCount to 0
            if xCount = 10 then
                set xCount to 0
                set x to 1149
            end if
            repeat until y ≠ y1 or yCount = 10
                set y to (random number from 900 to 970)
                set yCount to yCount + 1
            end repeat
            if x ≠ x1 then set yCount to 0
            if yCount = 10 then
                set yCount to 0
                set y to 669
            end if
            set x1 to x
            set y1 to y
        end if

        aMove({x, y})
        delay 5
    end randomMove

    on aMove(coordinate)
        set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
        set item 2 of coordinate to ((item 2 of coordinate) * yRatio)


        tell application "Extra Suites"
            delay 0.1
            activate
            ES move mouse coordinate
            try
                if application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" is running then
                    tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
                end if
            end try
            ES click mouse
            ES type key "a"
            quit
            delay 0.2
        end tell

    end aMove

    on click(coordinate)

        set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
        set item 2 of coordinate to ((item 2 of coordinate) * yRatio)
        try
            tell application "Extra Suites"
                set coordinate2 to {"", ""}
                set item 1 of coordinate2 to ((1000) * xRatio)
                set item 2 of coordinate2 to ((650) * yRatio)
                ES move mouse coordinate2
                ES click mouse with double click
                ES move mouse coordinate
                ES click mouse with double click
                quit
            end tell
        end try
        delay 0.1
        tell application "Extra Suites" to launch
        delay 0.2

        try
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" to activate
        end try

    end click

    on clickGame(coordinate)
        delay 0.3
        tell application "Extra Suites" to launch
        try
            delay 0.1
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
        end try
        set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
        set item 2 of coordinate to ((item 2 of coordinate) * yRatio)
        tell application "Extra Suites"
            delay 0.1
            set coordinate2 to {"", ""}
            set item 1 of coordinate2 to ((1000) * xRatio)
            set item 2 of coordinate2 to ((650) * yRatio)
            ES move mouse coordinate2
            ES click mouse with double click
            ES move mouse coordinate
            ES click mouse with double click
            quit
            delay 0.2
        end tell
        delay 0.1
        tell application "Extra Suites" to launch
        delay 0.1
    end clickGame

    on clickSingle(coordinate)
        try
            tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" to activate
        end try
        set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
        set item 2 of coordinate to ((item 2 of coordinate) * yRatio)
        tell application "Extra Suites"
            set coordinate2 to {"", ""}
            set item 1 of coordinate2 to ((1000) * xRatio)
            set item 2 of coordinate2 to ((650) * yRatio)
            ES move mouse coordinate2
            ES click mouse with double click
            ES move mouse coordinate
            ES click mouse
            quit
            delay 0.3
        end tell

        tell application "Extra Suites" to launch
    end clickSingle


    on askTimer()
        set endTime to 0
        -- ask for when they want the script to quit
        set endHours to text returned of (display dialog "How long to run in hours? (minutes will be asked in next dialogue)" default answer "" with title "Auto-League")
        set endTime to (endTime + (endHours * 3600))
        set endMins to text returned of (display dialog "How long to run? (minutes)" default answer "" with title "Auto-League")

        set endTime to endTime + (endMins * 60) -- total seconds to run
    end askTimer


    on checkQuit()
        (*	if application "Extra Suites" is not running then
            set quitApp to true
            set quitReason to "ES closed"
        end if
        *)
        -- if the "This copy of Extra Suites is unregistered" thingy is closed, then quit
        (*	tell application "System Events"
            if ((exists (window 1 of process "Extra Suites")) = (false)) then
                set quitApp to true
                set quitReason to quitReason & " ES window 1"
            end if
        end tell *)
        -- if the amount of time defined in the timer has passed, then quit
        if timerOn = "Yes" then
            if (curTime - startTime) ≥ endTime then
                set quitApp to true
                set quitReason to quitReason & " timer ended"
            end if
        end if
        if quitApp = true then quit
    end checkQuit



    on quit
        -- getting info for plist
        set ESrunning to (application "Extra Suites" is running)
        tell application "System Events"
            set ESWindow1 to (exists (window 1 of process "Extra Suites"))
        end tell
        set timerEnd to (curTime - startTime) ≥ endTime
        set lolClient to application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.250/deploy/bin/LolClient" is running
        set lolGame to application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.233/deploy/LeagueOfLegends.app/Contents/MacOS/LeagueofLegends" is running

        set arrayNumber to 0
        tell application "System Events"
            set plistFile to property list file "~/Library/Application Support/Auto League/QuitReason.plist"
            tell plistFile
                repeat -- repeat until a new array name is found, then create new array
                    set arrayNumber to arrayNumber + 1
                    set arrayName to "quitNumber" & arrayNumber as string
                    if property list item arrayName exists then
                    else
                        make new property list item at end with properties {kind:list, name:arrayName}
                        exit repeat
                    end if
                    --display dialog arrayNumber
                end repeat

                -- 1st item of array


                -- creating
                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:ESrunning}

                -- 2nd item, etc.

                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:ESWindow1}


                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:timerEnd}

                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:timerOn}

                -- value of quitApp already defined
                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:quitApp}


                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:lolClient}

                make new property list item at end of property list item arrayName with properties {kind:boolean, name:"ES is running", value:lolGame}

                make new property list item at end of property list item arrayName with properties {kind:string, name:"ES is running", value:quitReason}

            end tell
        end tell
        try
            do shell script "killall UserKernel"
        end try
        error number -128
    end quit


    on randomItem(repetitions)
        repeat repetitions times
            set thisY to random number from 150 to 710
            set thisX to random number from 330 to 700
            clickGame({thisX, thisY})
        end repeat
    end randomItem
    (*
    on makeReadable(array)
        set rStringLength to 1
        set rString to item 1 of array as string
        if item 2 of array = false and item 3 of array = false and item 4 of array = false then
            return rString
        else

            -- if any one of them is true, add with
            set rString to rString & " with"

            -- the string cant be more than 2 in length, so add control if it is in keybind
            if item 2 of array is true then
                set rString to rString & " control"
                set rStringLength to rStringLength + 1
            end if

            -- if control is part of the keybind, and something else too, then add :and shift", else add "shift"
            if item 3 of array is true then
                if length of rString = 2 then
                    set rString to rString & " and shift"
                else
                    set rString to rString & " shift"
                end if
                set rStringLength to rStringLength + 1
            end if

            -- if control is part of the keybind, and something else too, then add and command, else add command
            if item 4 of array is true then
                if length of rString ≥ 2 then
                    set rString to rString & " and command"
                else
                    set rString to rString & " command"
                end if
                set rStringLength to rStringLength + 1
            end if

            -- if control is part of the keybind, and something else too, then add and option, else add option
            if item 5 of array is true then
                if length of rString ≥ 2 then
                    set rString to rString & " and option"
                else
                    set rString to rString & " option"
                end if
                set rStringLength to rStringLength + 1
            end if

        end if

        return rString
    end makeReadable
        ⁃	*)
    
        
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
        <!-- enter your key bindings into the following arrays, they are currently set 	
          to be what the default is 						
         the key will tell you what the following things will be for		
         they go in the order :							
            button (excluding shift/control etc.)					
            control (in format <true/false> with a "/" after and <> e.g.: <true/>	
            shift									
            command									
            option (if you have alt, make option and shift both true)			
         they will look something like this:	

                <key>useQ</key>
                <array>
            /		start of use Q skill keybinding			\
                <string>q</string>						
                <true/>								
                <false/>							
                <false/>							
                <false/>	
             \              end of use Q skill keybinding 			/	
                </array>


        -->


            <key>attackMove</key>
            <array>




        <!-- NOTE: THIS IS THE NOT THE BUTTON YOU PRESS TO ATTACK MOVE THE NEXT TIME YOU CLICK, THIS IS THE BUTTON YOU PRESS TO AUTOATTACK-MOVE WITHOUT CLICKING IT IS UNBOUND BY DEFAULT YOU WILL HAVE TO BIND IT YOURSELF					-->
        <!--	 /              start of attack move click keybinding 		\	-->
                <string>UNBOUND BY DEFAULT</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	 \              end of attack move click keybinding 		/	-->




            </array>
            <key>useQ</key>
            <array>





        <!--	/		start of use Q skill keybinding			\	-->
                <string>q</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use Q skill keybinding			/	-->




            </array>
            <key>useW</key>
            <array>





        <!--	/		start of use W skill keybinding			\	-->
                <string>w</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use W skill keybinding			/	-->




            </array>
            <key>useE</key>
            <array>




        <!--	/		start of use E skill keybinding			\	-->
                <string>e</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use E skill keybinding			/	-->
            </array>
            <key>useR</key>
            <array>





        <!--	/		start of use R skill keybinding			\	-->
                <string>r</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use R skill keybinding			/	-->




            </array>
            <key>levelQ</key>
            <array>




        <!--	/		start of level up Q keybinding			\	-->
                <string>q</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up Q keybinding			/	-->




            </array>
            <key>levelW</key>
            <array>




        <!--	/		start of level up W keybinding			\	-->
                <string>w</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up W keybinding			/	-->




            </array>
            <key>levelE</key>
            <array>




        <!--	/		start of level up E keybinding			\	-->
                <string>e</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up E keybinding			/	-->




            </array>
            <key>levelR</key>
            <array>




        <!--	/		start of level up R keybinding			\	-->
                <string>r</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up R keybinding			/	-->




            </array>
            <key>shop</key>
            <array>




        <!--	/		start of open shop keybinding			\	-->
                <string>p</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of open shop keybinding			/	-->




        </array>
    </dict>
    </plist>
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
        <dict>
        <!-- enter your key bindings into the following arrays, they are currently set 	
          to be what the default is 						
         the key will tell you what the following things will be for		
         they go in the order :							
            button (excluding shift/control etc.)					
            control (in format <true/false> with a "/" after and <> e.g.: <true/>	
            shift									
            command									
            option (if you have alt, make option and shift both true)			
         they will look something like this:	

                <key>useQ</key>
                <array>
            /		start of use Q skill keybinding			\
                <string>q</string>						
                <true/>								
                <false/>							
                <false/>							
                <false/>	
             \              end of use Q skill keybinding 			/	
                </array>


        -->


            <key>attackMove</key>
            <array>




        <!-- NOTE: THIS IS THE NOT THE BUTTON YOU PRESS TO ATTACK MOVE THE NEXT TIME YOU CLICK, THIS IS THE BUTTON YOU PRESS TO AUTOATTACK-MOVE WITHOUT CLICKING IT IS UNBOUND BY DEFAULT YOU WILL HAVE TO BIND IT YOURSELF					-->
        <!--	 /              start of attack move click keybinding 		\	-->
                <string>UNBOUND BY DEFAULT</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	 \              end of attack move click keybinding 		/	-->




            </array>
            <key>useQ</key>
            <array>





        <!--	/		start of use Q skill keybinding			\	-->
                <string>q</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use Q skill keybinding			/	-->




            </array>
            <key>useW</key>
            <array>





        <!--	/		start of use W skill keybinding			\	-->
                <string>w</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use W skill keybinding			/	-->




            </array>
            <key>useE</key>
            <array>




        <!--	/		start of use E skill keybinding			\	-->
                <string>e</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use E skill keybinding			/	-->
            </array>
            <key>useR</key>
            <array>





        <!--	/		start of use R skill keybinding			\	-->
                <string>r</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of use R skill keybinding			/	-->




            </array>
            <key>levelQ</key>
            <array>




        <!--	/		start of level up Q keybinding			\	-->
                <string>q</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up Q keybinding			/	-->




            </array>
            <key>levelW</key>
            <array>




        <!--	/		start of level up W keybinding			\	-->
                <string>w</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up W keybinding			/	-->




            </array>
            <key>levelE</key>
            <array>




        <!--	/		start of level up E keybinding			\	-->
                <string>e</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up E keybinding			/	-->




            </array>
            <key>levelR</key>
            <array>




        <!--	/		start of level up R keybinding			\	-->
                <string>r</string>
                <true/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of level up R keybinding			/	-->




            </array>
            <key>shop</key>
            <array>




        <!--	/		start of open shop keybinding			\	-->
                <string>p</string>
                <false/>
                <false/>
                <false/>
                <false/>
        <!--	\		end of open shop keybinding			/	-->




        </array>
    </dict>
    </plist>

        
        
        
        	tell application "Extra Suites" to ES move mouse {0, 0}
	delay 5
	property x : 0
	property y : 0
	property x1 : 0
	property y1 : 0
	property yCount : 0
	property xCount : 0
	property reps : 0
	property counter : 0
	property startTime : 0
	property curTime : 0
	property endTime : 0
	property lolIsRunning : false
	property button1 : {}
	property button2 : {}
	property button3 : {}
	property button4 : {}
	property timerOn : false
	property quitApp : false
	property xRatio : 0
	property yRatio : 0
	-- setting current time
	set startTime to do shell script "ruby -e 'print Time.now.to_f'"
	
	-- getting screen resolution
	
	tell application "Finder"
		set screenRes to bounds of window of desktop
		set screenResX to item 3 of screenRes
		set screenResY to item 4 of screenRes
	end tell
	
	-- set ratios that coordinates will be multiplied to
	
	set xRatio to screenResX / 1920
	set yRatio to screenResY / 1080
	
	-- use timer or not
	set timerOn to button returned of (display dialog "Use timer?" with title "Auto-League" buttons {"Yes", "No"})
	
	checkQuit()
	
	if timerOn = "Yes" then
		askTimer()
		
		if ((endTime ≥ 0) is false) then
			display dialog "Error in input, please input a valid integer" with title "Auto-League"
			askTimer()
		end if
	end if
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	-- all coordinates
	property play : {960, 190}
	property PvP : {650, 270}
	property bots : {650, 330}
	property classic : {850, 300}
	property dominion : {850, 330}
	property summonersRift : {1040, 305}
	property twistedTreeline : {1040, 350}
	property summonersRiftBeginner : {1240, 330}
	property summonersRiftIntermediate : {1240, 355}
	property othersBeginner : {1240, 300}
	property othersIntermediate : {1240, 330}
	property blindPickSR : {1240, 355}
	property blindPickOthers : {1240, 310}
	property crystalScar : {1070, 310}
	property solo : {1070, 860}
	property profile : {1400, 200}
	property ranChamp : {645, 360}
	property lockIn : {1230, 675}
	property accept : {873, 594}
	property endGame : {958, 638}
	property playAgain : {1450, 885}
	
	-- end of coordinates
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	set difficulty to button returned of (display dialog "Which difficulty?" with title "Auto-League" buttons {"PvP", "Beginner", "Intermediate"})
	
	set map to button returned of (display dialog "Which map?" with title "Auto-League" buttons {"Summoner's Rift", "Crystal Scar (less likely to be reported in PvP)", "Twisted Treeline"})
	
	-- SETTING BUTTONS
	-- if PvP is chosen click PvP, the rest are bots, so click co-op vs AI
	if difficulty = "PvP" then
		set button1 to PvP
	else
		set button1 to bots
	end if
	
	-- if crystal scar is chosen, click dominion, the rest of the maps are classic, so click classic
	if map = "Crystal Scar (less likely to be reported in PvP)" then
		set button2 to dominion
	else
		set button2 to classic
	end if
	
	-- if twisted treeline, click 2nd button from top, crystal scar and summoners rift are in the same spot, 1st form top, so click first button from top, but i wanted to keep the buttons seperate, so they use different variables
	if map = "Twisted Treeline" then
		set button3 to twistedTreeline
	else if map = "Summoner's Rift" then
		set button3 to summonersRift
	else if map = "Crystal Scar (less likely to be reported in PvP)" then
		set button3 to crystalScar
	end if
	
	-- pvp is only for blind pick, but buttons for SR and TT and CR are different
	if difficulty = "PvP" then
		if map = "Summoner's Rift" then
			set button4 to blindPickSR
		else
			set button4 to blindPickOthers
		end if
	end if
	
	if difficulty = "Beginner" then
		-- different spots for different maps 
		if map = "Summoner's Rift" then
			set button4 to summonersRiftBeginner
		else
			set button4 to othersBeginner
		end if
	end if
	
	if difficulty = "Intermediate" then
		-- different spots for different maps 
		if map = "Summoner's Rift" then
			set button4 to summonersRiftIntermediate
		else
			set button4 to othersIntermediate
		end if
	end if
	
	
	
	
	
	checkQuit()
	
	tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.197/deploy/bin/LolClient" to activate
	-- joining queue
	click(play)
	delay 0.1
	click(button1)
	delay 0.1
	click(button2)
	delay 0.1
	click(button3)
	delay 0.1
	click(button4)
	delay 0.1
	checkQuit()
	click(solo)
	
	checkQuit()
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	repeat
		set counter to 0
		checkQuit()
		-- repeat until client is not running, or game is running
		repeat until application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.186/deploy/LeagueofLegends.app/Contents/MacOS/LeagueofLegends" is running or application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.197/deploy/bin/LolClient" is not running
			checkQuit()
			
			set counter to counter + 1
			
			if counter ≥ 500 then
				checkQuit()
				set counter to 0
				-- click report ok button
				tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.197/deploy/bin/LolClient" to activate
				-- joining queue
				click(play)
				delay 0.1
				click(button1)
				delay 0.1
				click(button2)
				delay 0.1
				click(button3)
				delay 0.1
				click(button4)
				delay 0.1
				click(solo)
			end if
			tell application "/Applications/League of Legends.app/Contents/LoL/RADS/projects/lol_air_client/releases/0.0.0.197/deploy/bin/LolClient" to activate
			
			delay 0.1
			-- click reconnect
			set curTime to do shell script "ruby -e 'print Time.now.to_f'"
			checkQuit()
			delay 0.1
			click(playAgain)
			-- try to accept queue/select & lock in champion / reconnecting
			delay 0.1
			click(profile)
			delay 0.1
			click(accept)
			delay 0.1
			click(ranChamp)
			delay 0.1
			click(lockIn)
			
			delay 5
			checkQuit()
			
		end repeat
		tell application "Safari" to quit
		
		-- repeat until game is closed 
		repeat until application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.186/deploy/LeagueofLegends.app/Contents/MacOS/LeagueofLegends" is not running
			try
				tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.186/deploy/LeagueofLegends.app/Contents/MacOS/LeagueofLegends" to activate
			end try
			
			randomMove()
			click(endGame)
			delay 10
		end repeat
		try
			tell application "/Applications/League of Legends.app/Contents/LoL/RADS/solutions/lol_game_client_sln/releases/0.0.0.186/deploy/LeagueofLegends.app/Contents/MacOS/LeagueofLegends" to quit
		end try
	end repeat
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	-- SUBROUTINES
	on randomMove()
		if reps = 10 then
			set reps to 0
			tell application "Extra Suites"
				ES move mouse {xRatio * 638, 498 * yRatio}
				delay 0.1
				ES click mouse with double click
				delay 0.1
				ES click mouse with double click
				delay 0.1
				ES click mouse with double click
				delay 0.1
				ES click mouse with double click
			end tell
		else
			set reps to reps + 1
			repeat until x ≠ x1 or xCount = 10
				set x to (random number from 1725 to 1825)
				set xCount to xCount + 1
			end repeat
			if x ≠ x1 then set xCount to 0
			if xCount = 10 then
				set xCount to 0
				set x to 1149
			end if
			repeat until y ≠ y1 or yCount = 10
				set y to (random number from 900 to 970)
				set yCount to yCount + 1
			end repeat
			if x ≠ x1 then set yCount to 0
			if yCount = 10 then
				set yCount to 0
				set y to 669
			end if
			set x1 to x
			set y1 to y
		end if
		
		aMove({x, y})
		delay 5
	end randomMove
	
	on aMove(coordinate)
		set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
		set item 2 of coordinate to ((item 2 of coordinate) * yRatio)
		tell application "Extra Suites"
			ES move mouse coordinate
			ES click mouse
			ES type key "a"
			quit
		end tell
	end aMove
	
	on click(coordinate)
		set item 1 of coordinate to ((item 1 of coordinate) * xRatio)
		set item 2 of coordinate to ((item 2 of coordinate) * yRatio)
		tell application "Extra Suites"
			ES move mouse coordinate
			ES click mouse with double click
			quit
		end tell
		delay 0.2
		tell application "Extra Suites" to activate
	end click
	
	on askTimer()
		set endTime to 0
		-- ask for when they want the script to quit
		set endHours to text returned of (display dialog "How long to run in hours? (minutes will be asked in next dialogue)" default answer "" with title "Auto-League")
		set endTime to (endTime + (endHours * 3600))
		set endMins to text returned of (display dialog "How long to run? (minutes)" default answer "" with title "Auto-League")
		
		set endTime to endTime + (endMins * 60) -- total seconds to run
	end askTimer
	
	
	on checkQuit()
		if application "Extra Suites" is not running then set quitApp to true
		-- if the "This copy of Extra Suties is unregistered" thingy is closed, then quit
		tell application "System Events"
			if ((exists (window 1 of process "Extra Suites")) = (false)) then set quitApp to true
		end tell
		
		-- if the amount of time defined in the timer has passed, then quit
		if timerOn = "Yes" then
			if (curTime - startTime) ≥ endTime then
				set quitApp to true
			end if
		end if
		
		if quitApp = true then quit
	end checkQuit
	
	
        
        
        
            tell application "Extra Suites" to quit