;This is an automation to keep the Online MMORPG game Damoria active
; while you walk away for a while.
; It just clicks on the "Buildings" button over and over every minute
; or so.
;To use it press F5 to start it.
;
; While this script is running you press the right bracket ] to end it.

;Exit key = "]"

;CODE: AutoIt
HotKeySet("]", "exit1")
Opt("MouseClickDownDelay", 60) ;60 milliseconds
Opt("WinWaitDelay", 100)
Opt("WinTitleMatchMode", 4)
Opt("WinDetectHiddenText", 1)
Opt("MouseCoordMode", 0)
;$Green = 0xCCFF99 ; Building being built color

While 1 = 1 ; Do this loop until you press the ] Key to exit
; Variable declarations, adjust as needed to match YOUR screen
$y = 0 ; This is calculated and set as the center of the small square at bottom of build arrow
$Row = 0 ; Declare $Row variable and set initial value
$Base = 258 ; This is the top row when NO Buildings are being built
$Base1 = 297 ; This is the top row when ONE Building is being built
$Base2 = 297 ; This is the top row when TWO Buildings are being built
$OffsetRows = 27 ; Normal Vertical between the rows
$Build = 830 ; Column to click in order to select BUILD on an item (Portrait)
$Skip = 433 ; Position to show the building was skipped (Portrait)
$GreenBuilt = 755 ; Horizontal position that is Green (0xCCFF99) if being built (Portrait)


WinWait("http://www.damoria.com/ - Microsoft Internet Explorer","")
If Not WinActive("http://www.damoria.com/ - Microsoft Internet Explorer","") Then
WinActivate("http://www.damoria.com/ - Microsoft Internet Explorer","")
WinWaitActive("http://www.damoria.com/ - Microsoft Internet Explorer","")


WinMove("http://www.damoria.com/ - Microsoft Internet Explorer","",0,0)
Sleep(500) ; Give time to close Script window and get into game before starting.
RefreshStats()

;********************************************************************
; You can only have Two Buildings under Construction
;
;********************************************************************
;               Check for Building under Construction
;
; If PixelGetColor ( 1117,377 ) = 0xCCFF99
;         Then at least one building is under construction.
; If PixelGetColor ( 1117,401 ) = 0xCCFF99
;         Then Two buildings are under construction
;************************************************************************
; Row      Building                                                              *
; 1          Construction Office                                             *
; 2          Barracks                                                             *
; 3          Senate                                                                *
; 4          Stables                                                                *
; 5          Catapult Construction                                         *
; 6          Laboratory                                                          *
; 7          Military Training Area                                          *
; 8          Tournament Field                                               *
; 9          Marketplace                                                        *
; 10        Quarry                                                                 *
; 11        Sawmill                                                                 *
; 12        Mine                                                                     *
; 13        Dwelling                                                               *
; 14        Storage                                                               *
; 15        Hiding Place                                                        *
; 16        Wall                                                                     *
;************************************************************************
;   Arrange the following lines in order of importance for building
; You can copy/paste to add more buildings to the list but remember that
; only the top TWO buildings will ever get built while there are
; enough materials. If materials run out to build the top ones, then it will go down
; the line until it gets to one that can be built
;*********************************************************************


;#comments-start
; ************************************
$Row = 5 ;
SetY()
;SlideDown() <-- done in SetY() now
Sleep(500)
;MsgBox(0, $y, Hex(PixelGetColor($Build,$y),6))
MouseMove($Skip,$y) ; Show this section checked
Sleep(700) ; Pause a bit to show what Row is being checked.
If PixelGetColor ($GreenBuilt,$y) <> 0xCCFF99        And PixelGetColor ( $Build,$y ) = 0xFFFFFF then ;
Not being built AND Materials available
MouseMove($Build,$y) ; Build
MouseDown("left")
MouseUp("left")
Sleep(1000) ; Give screen time to change before next section
EndIf
Sleep(5000) ; Wait a while before refreshing screen
;#comments-end


;#comments-start
; ************************************
$Row = 2 ;
SetY()
;SlideDown() <-- done in SetY() now
Sleep(500)
;MsgBox(0, $y, Hex(PixelGetColor($Build,$y),6))
MouseMove($Skip,$y) ; Show this section checked
Sleep(700) ; Pause a bit to show what Row is being checked.
If PixelGetColor ($GreenBuilt,$y) <> 0xCCFF99        And PixelGetColor ( $Build,$y ) = 0xFFFFFF then ;
Not being built AND Materials available
MouseMove($Build,$y) ; Build
MouseDown("left")
MouseUp("left")
Sleep(1000) ; Give screen time to change before next section
EndIf
;#comments-end


WEnd

;********************************************************************
;********************************************************************

Func SetY() ; Used to set the Y-coordinate
SlideDown()
$y = $Base         ;Start at top Building's Row
   ;Vertical position when no buildings being built.
;#comments-start
MouseMove(830,215)
Sleep(500) ; Give time for mouse to move
If PixelGetColor ( 830,215 ) = 0xCCFF99 then ; At least one Building Slot is used (Portrait)
$y = $Base1 ; Move down
EndIf
MouseMove(830,191)
Sleep(500) ; Give time for mouse to move
If PixelGetColor ( 830,191 ) = 0xCCFF99 then ; See if the second building is under construction (Port)
$y = $Base2 ; Move down one more row for second item under construction (no slots open)
EndIf
$y += ($Row -1)* $OffsetRows
;#comments-end
EndFunc

Func SlideDown() ; Used to slide the slider down to see bottom of screen
MouseMove(885,466)
Sleep(500) ;Give Mouse time to get there
MouseDown("left")
MouseMove(885,683)
Sleep(500) ;Give Mouse time to get there
MouseUp("left")
EndFunc


Func SlideUp() ; Used to slide the slider up to see top of screen
MouseMove(885,466)
Sleep(500) ;Give Mouse time to get there
MouseDown("left")
MouseMove(885,241)
Sleep(500) ;Give Mouse time to get there
MouseUp("left")
EndFunc

Func RefreshStats()
SlideUp()
sleep(500) ; Give screen a chance to change
MouseMove(Random(214,277, 1),Random(141, 199, 1))
sleep(500) ; let screen change
MouseDown("left")
MouseUp("left")
sleep(2000) ; Give screen a chance to update
sleep (Random(1000, 4500, 1)) ; Make the time more random
Sleep(5000) ;


EndFunc

Func MouseInfo() ; used for debugging/information
$pos = MouseGetPos()
MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1])
$var = PixelGetColor(286, 571)
Sleep(700)
MsgBox(0, "The decmial color is", $var)
Sleep(700)
MsgBox(0, "The hex color is", Hex($var, 6))
Sleep(700)
EndFunc   ;==>MouseInfo


Func exit1()
Exit (0)
EndFunc   ;==>exit1
AutoIt Solution
Below is a listing of "Damoria Build.au3" my AutoIt script for building in Damoria. I use the
building two buildings. The first one takes priority if materials are available but it is possible
The script is written for Internet Explorer browser use and while I am playing Damoria, the
browser slider on the right side is right up next to the main game display so it is in a known
position for the script (it is covering the banner to the right.) Since your screen resolution
is probably different from mine, you will need to use the Au3Info tool in AutoIt to find the
exact coordinates for the buttons and rows, and, you may need it to find the values for the
colors.