|
|
@@ -1,36 +1,46 @@
|
|
|
+#include <Date.au3>
|
|
|
;;Klanhaboru fun
|
|
|
;; https://git.petyuspolisz.com/chestercs/klanhaboru/src/master/klanhaboru_main.au3
|
|
|
-AutoItSetOption("SendKeyDelay", 1)
|
|
|
+AutoItSetOption("SendKeyDelay", 0)
|
|
|
AutoItSetOption("SendKeyDownDelay", 0)
|
|
|
AutoItSetOption("WinTitleMatchMode", 2)
|
|
|
-Global $gameTitle = "Klánháború"
|
|
|
-Global $pageLoadTime = 1500 ;inMs
|
|
|
-Global $gyujtogetesWaitTime = 1200000 ;20m default fallback value
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
;; User Config
|
|
|
+Global $trainUnitRepeatTimer = 3600 ;in seconds
|
|
|
+Global $trainLovassagRepeatTimer = 3600 ;in seconds
|
|
|
+Global $epitesRepeatTimer = 300 ;in seconds
|
|
|
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
Global $server = IniRead(@ScriptDir & "/config.ini", "Options", "server", "hu83")
|
|
|
Global $villageId = IniRead(@ScriptDir & "/config.ini", "Options", "villageId", "4446")
|
|
|
;Mode 0-3 (0-Lusta gyûjtögetõk, 1-Szerény gyûjtögetõk, 2-Okos gyûjtögetõk, 3-Kiváló gyûjtögetõk)
|
|
|
Global $scavengeMode = IniRead(@ScriptDir & "/config.ini", "Options", "scavengeMode", "2")
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
+Global $gameTitle = "Klánháború"
|
|
|
+Global $gyujtogetesEventTimer
|
|
|
+Global $trainUnitsEventTimer = eventStart($trainUnitRepeatTimer)
|
|
|
+Global $trainLovassagEventTimer = eventStart($trainLovassagRepeatTimer)
|
|
|
+Global $epitesEventTimer = eventStart($epitesRepeatTimer)
|
|
|
+Global $pageLoadTime = 1500 ;inMs
|
|
|
+
|
|
|
|
|
|
WinWaitActive($gameTitle)
|
|
|
Sleep(1000)
|
|
|
While 1
|
|
|
gyujtogetes(true, 2, 0, 0, 0, 0, 0, 0, 0, 0) ;$mode, $landzsas, $kardforgato, $bardos, $ijasz, $konnyulovas, $lovasijasz, $nehezlovas, $lovag
|
|
|
- Sleep($gyujtogetesWaitTime)
|
|
|
trainUnits(0, 0, 0, 0) ;$landzsas, $kardforgato, $bardos, $ijasz
|
|
|
trainLovassag(0, 0, 0, 0) ;$kem, $konnyulovas, $lovasijasz, $nehezlovas
|
|
|
- ;epites("wall") ;Options: main, barracks, stable, watchtower, smith, place, statue, market, wood, stone, iron, farm, storage, hide, wall
|
|
|
+ epites("wall") ;Options: main, barracks, stable, watchtower, smith, place, statue, market, wood, stone, iron, farm, storage, hide, wall
|
|
|
+ Sleep(1000)
|
|
|
WEnd
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
;; Functions
|
|
|
func gyujtogetes($sendAll, $mode, $landzsas, $kardforgato, $bardos, $ijasz, $konnyulovas, $lovasijasz, $nehezlovas, $lovag) ;Mode 0-3 (0-Lusta gyûjtögetõk, 1-Szerény gyûjtögetõk, 2-Okos gyûjtögetõk, 3-Kiváló gyûjtögetõk)
|
|
|
+ if (Not eventTriggered($gyujtogetesEventTimer)) Then Return false
|
|
|
ConsoleWrite("Gyüjtögetés started!" & @CRLF)
|
|
|
- if ($landzsas = 0 and $kardforgato = 0 and $bardos = 0 and $ijasz = 0 and $konnyulovas = 0 and $lovasijasz = 0 and $nehezlovas = 0 and $lovag = 0) Then
|
|
|
+ if ($sendAll = false and $landzsas = 0 and $kardforgato = 0 and $bardos = 0 and $ijasz = 0 and $konnyulovas = 0 and $lovasijasz = 0 and $nehezlovas = 0 and $lovag = 0) Then
|
|
|
ConsoleWrite("Gyüjtögetés Skip!" & @CRLF)
|
|
|
Return False
|
|
|
EndIf
|
|
|
@@ -61,18 +71,16 @@ func gyujtogetes($sendAll, $mode, $landzsas, $kardforgato, $bardos, $ijasz, $kon
|
|
|
Sleep(300)
|
|
|
jsExecutor("document.getElementsByClassName('scavenge-option')[" & $mode & "].getElementsByClassName('btn-default')[0].click();")
|
|
|
Sleep($pageLoadTime)
|
|
|
- $gyujtogetesWaitTime = parseTimeToMs(getDataWithJs("document.getElementsByClassName('scavenge-option')[" & $mode & "].getElementsByClassName('return-countdown')[0]"))
|
|
|
- ConsoleWrite("Gyüjtögetés wait time in ms: " & $gyujtogetesWaitTime & @CRLF)
|
|
|
+ $gyujtogetesEventTimer = eventStart(parseTimeToSeconds(getDataWithJs("document.getElementsByClassName('scavenge-option')[" & $mode & "].getElementsByClassName('return-countdown')[0]")))
|
|
|
+ ConsoleWrite("Gyüjtögetés done, next event: " & $gyujtogetesEventTimer & @CRLF)
|
|
|
ConsoleWrite(@CRLF)
|
|
|
EndFunc
|
|
|
|
|
|
|
|
|
func trainUnits($landzsas, $kardforgato, $bardos, $ijasz)
|
|
|
+ if (Not eventTriggered($trainUnitsEventTimer)) Then Return false
|
|
|
+ if ($landzsas = 0 and $kardforgato = 0 and $bardos = 0 and $ijasz = 0) Then Return False
|
|
|
ConsoleWrite("Train Units started!" & @CRLF)
|
|
|
- if ($landzsas = 0 and $kardforgato = 0 and $bardos = 0 and $ijasz = 0) Then
|
|
|
- ConsoleWrite("Train Units Skip!" & @CRLF)
|
|
|
- Return False
|
|
|
- EndIf
|
|
|
navigateUrl(getGameUrl("barracks", ""))
|
|
|
Sleep($pageLoadTime)
|
|
|
if ($landzsas > 0) Then jsExecutor("document.getElementsByName('spear')[0].value = '" & $landzsas & "';")
|
|
|
@@ -85,17 +93,17 @@ func trainUnits($landzsas, $kardforgato, $bardos, $ijasz)
|
|
|
if ($bardos < 0) Then jsExecutor("document.getElementsByName('axe')[0].parentElement.children[1].click();")
|
|
|
if ($ijasz < 0) Then jsExecutor("document.getElementsByName('archer')[0].parentElement.children[1].click();")
|
|
|
sendJsClickByClass("btn-recruit")
|
|
|
- ConsoleWrite(@CRLF)
|
|
|
Sleep($pageLoadTime)
|
|
|
+ $trainUnitsEventTimer = eventStart($trainUnitRepeatTimer)
|
|
|
+ ConsoleWrite("Train Units done, next event: " & $trainUnitsEventTimer & @CRLF)
|
|
|
+ ConsoleWrite(@CRLF)
|
|
|
EndFunc
|
|
|
|
|
|
|
|
|
func trainLovassag($kem, $konnyulovas, $lovasijasz, $nehezlovas)
|
|
|
+ if (Not eventTriggered($trainLovassagEventTimer)) Then Return false
|
|
|
+ if ($kem = 0 and $konnyulovas = 0 and $lovasijasz = 0 and $nehezlovas = 0) Then Return False
|
|
|
ConsoleWrite("Train Lovassag started!" & @CRLF)
|
|
|
- if ($kem = 0 and $konnyulovas = 0 and $lovasijasz = 0 and $nehezlovas = 0) Then
|
|
|
- ConsoleWrite("Train Lovassag Skip!" & @CRLF)
|
|
|
- Return False
|
|
|
- EndIf
|
|
|
navigateUrl(getGameUrl("stable", ""))
|
|
|
Sleep($pageLoadTime)
|
|
|
if ($kem > 0) Then jsExecutor("document.getElementsByName('spy')[0].value = '" & $kem & "';")
|
|
|
@@ -108,57 +116,28 @@ func trainLovassag($kem, $konnyulovas, $lovasijasz, $nehezlovas)
|
|
|
if ($lovasijasz < 0) Then jsExecutor("document.getElementsByName('marcher')[0].parentElement.children[1].click();")
|
|
|
if ($nehezlovas < 0) Then jsExecutor("document.getElementsByName('heavy')[0].parentElement.children[1].click();")
|
|
|
sendJsClickByClass("btn-recruit")
|
|
|
- ConsoleWrite(@CRLF)
|
|
|
Sleep($pageLoadTime)
|
|
|
+ $trainLovassagEventTimer = eventStart($trainLovassagRepeatTimer)
|
|
|
+ ConsoleWrite("Train Lovassag done, next event: " & $trainLovassagEventTimer & @CRLF)
|
|
|
+ ConsoleWrite(@CRLF)
|
|
|
EndFunc
|
|
|
|
|
|
+
|
|
|
func epites($buildingId) ;Options: main, barracks, stable, watchtower, smith, place, statue, market, wood, stone, iron, farm, storage, hide, wall
|
|
|
+ if (Not eventTriggered($epitesEventTimer)) Then Return false
|
|
|
ConsoleWrite("Epites started: " & $buildingId & @CRLF)
|
|
|
navigateUrl(getGameUrl("main", ""))
|
|
|
Sleep($pageLoadTime)
|
|
|
jsExecutor("document.querySelector('{#}main_buildrow_" & $buildingId & "').querySelector('a.btn-build').click();")
|
|
|
Sleep($pageLoadTime)
|
|
|
+ $epitesEventTimer = eventStart($epitesRepeatTimer)
|
|
|
+ ConsoleWrite("Epites done, next event: " & $epitesEventTimer & @CRLF)
|
|
|
ConsoleWrite(@CRLF)
|
|
|
EndFunc
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
;; Helper Functions
|
|
|
-func parseTimeToMs($string)
|
|
|
- $parsedString = StringSplit( $string, ":")
|
|
|
- if ($parsedString[0] < 3) Then
|
|
|
- ConsoleWrite("parseTimeToMs error! Expected array size 3, actual: " & $parsedString[0] & @CRLF)
|
|
|
- return 0
|
|
|
- EndIf
|
|
|
- $hours = $parsedString[1]
|
|
|
- $minutes = $parsedString[2]
|
|
|
- $seconds = $parsedString[3]
|
|
|
- return (($hours*3600+$minutes*60+$seconds)*1000)
|
|
|
-EndFunc
|
|
|
-
|
|
|
-
|
|
|
-func getDataWithJs($jsSelector)
|
|
|
- $clipBoardCache = ClipGet()
|
|
|
- jsExecutor("window.location = '{#}'{+}" & $jsSelector & ".innerHTML")
|
|
|
- Sleep(300)
|
|
|
- Send("^l")
|
|
|
- Sleep(300)
|
|
|
- Send("^a")
|
|
|
- Sleep(300)
|
|
|
- Send("^c")
|
|
|
- $data = ClipGet()
|
|
|
- ClipPut($clipBoardCache)
|
|
|
- $data = StringSplit( $data, "#")
|
|
|
- if ($data[0] < 2) Then
|
|
|
- ConsoleWrite("getDataWithJs error! Expected array size 2, actual: " & $data[0] & @CRLF)
|
|
|
- return ""
|
|
|
- EndIf
|
|
|
- ConsoleWrite("Data received: " & $data[2] & @CRLF)
|
|
|
- return $data[2]
|
|
|
-EndFunc
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
func getGameUrl($screen, $mode)
|
|
|
return "https://" & $server & ".klanhaboru.hu/game.php?village=" & $villageId & "&screen=" & $screen & "&mode=" & $mode
|
|
|
EndFunc
|
|
|
@@ -178,7 +157,7 @@ EndFunc
|
|
|
|
|
|
func navigateUrl($url)
|
|
|
WinWaitActive($gameTitle)
|
|
|
- ConsoleWrite($url & @CRLF)
|
|
|
+ ;ConsoleWrite($url & @CRLF)
|
|
|
Sleep(300)
|
|
|
Send("^l")
|
|
|
Sleep(300)
|
|
|
@@ -188,4 +167,95 @@ func navigateUrl($url)
|
|
|
Sleep(300)
|
|
|
Send("{ENTER}")
|
|
|
Sleep(300)
|
|
|
-EndFunc
|
|
|
+EndFunc
|
|
|
+
|
|
|
+func getDataWithJs($jsSelector)
|
|
|
+ $clipBoardCache = ClipGet()
|
|
|
+ jsExecutor("window.location = '{#}'{+}" & $jsSelector & ".innerHTML")
|
|
|
+ Sleep(300)
|
|
|
+ Send("^l")
|
|
|
+ Sleep(300)
|
|
|
+ Send("^a")
|
|
|
+ Sleep(300)
|
|
|
+ Send("^c")
|
|
|
+ Sleep(300)
|
|
|
+ $data = ClipGet()
|
|
|
+ ClipPut($clipBoardCache)
|
|
|
+ $data = StringSplit( $data, "#")
|
|
|
+ if ($data[0] < 2) Then
|
|
|
+ ConsoleWrite("getDataWithJs error!" & $data & " Expected array size 2, actual: " & $data[0] & @CRLF)
|
|
|
+ return ""
|
|
|
+ EndIf
|
|
|
+ ConsoleWrite("Data received: " & $data[2] & @CRLF)
|
|
|
+ return $data[2]
|
|
|
+EndFunc
|
|
|
+
|
|
|
+func parseTimeToSeconds($string)
|
|
|
+ $parsedString = StringSplit( $string, ":")
|
|
|
+ if ($parsedString[0] < 3) Then
|
|
|
+ ConsoleWrite("parseTimeToSeconds error! Expected array size 3, actual: " & $parsedString[0] & @CRLF)
|
|
|
+ return 0
|
|
|
+ EndIf
|
|
|
+ $hours = $parsedString[1]
|
|
|
+ $minutes = $parsedString[2]
|
|
|
+ $seconds = $parsedString[3]
|
|
|
+ return ($hours*3600+$minutes*60+$seconds)
|
|
|
+EndFunc
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+#Region === EventHandlers
|
|
|
+ Func eventStart($secondsToWait = 3, $mode = "s")
|
|
|
+ return _DateAdd($mode, $secondsToWait, _NowCalc())
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func eventCountDown($targetDate, $mode = "s")
|
|
|
+ return _DateDiff($mode, _NowCalc(), $targetDate)
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func eventTimePassed($startDate, $targetDate = _NowCalc(), $mode = "s")
|
|
|
+ return _DateDiff($mode, $startDate, $targetDate)
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func eventTimeCompare($startDate, $targetDate, $mode = "s")
|
|
|
+ return _DateDiff($mode, $startDate, $targetDate)
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func eventTriggered($targetDate, $mode = "s")
|
|
|
+ return eventCountDown($targetDate, $mode) <= 0
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func compareTimeEventFormatted($startTime, $endTime = _NowCalc())
|
|
|
+ $seconds = StringFormat("%02i", Mod(eventTimeCompare($startTime, $endTime, "s"), 60))
|
|
|
+ $minutes = StringFormat("%02i", Mod(eventTimeCompare($startTime, $endTime, "n"), 60))
|
|
|
+ $hours = StringFormat("%01i", eventTimeCompare($startTime, $endTime, "h"))
|
|
|
+ if ($hours <> -1 and $minutes <> -1 and $seconds <> -1) then
|
|
|
+ return $hours &":" &$minutes &":" &$seconds
|
|
|
+ else
|
|
|
+ return ""
|
|
|
+ EndIf
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func countdownTimeEventFormatted($endTime)
|
|
|
+ $seconds = StringFormat("%02i", Mod(eventCountDown($endTime, "s"), 60))
|
|
|
+ $minutes = StringFormat("%02i", Mod(eventCountDown($endTime, "n"), 60))
|
|
|
+ $hours = StringFormat("%01i", eventCountDown($endTime, "h"))
|
|
|
+ if ($hours <> -1 and $minutes <> -1 and $seconds <> -1) then
|
|
|
+ return $hours &":" &$minutes &":" &$seconds
|
|
|
+ else
|
|
|
+ return ""
|
|
|
+ EndIf
|
|
|
+ EndFunc
|
|
|
+
|
|
|
+ Func passedTimeEventFormatted($startTime, $endTime = _NowCalc())
|
|
|
+ $seconds = StringFormat("%02i", Mod(eventTimePassed($startTime, $endTime, "s"), 60))
|
|
|
+ $minutes = StringFormat("%02i", Mod(eventTimePassed($startTime, $endTime, "n"), 60))
|
|
|
+ $hours = StringFormat("%01i", eventTimePassed($startTime, $endTime, "h"))
|
|
|
+ if ($hours <> -1 and $minutes <> -1 and $seconds <> -1) then
|
|
|
+ return $hours &":" &$minutes &":" &$seconds
|
|
|
+ else
|
|
|
+ return ""
|
|
|
+ EndIf
|
|
|
+ EndFunc
|
|
|
+#EndRegion
|