Przeglądaj źródła

upload existing code v1.0)

chestercs 2 lat temu
rodzic
commit
52c8666d56
2 zmienionych plików z 370 dodań i 0 usunięć
  1. 118 0
      .gitignore
  2. 252 0
      klanhaboru_sandbox.au3

+ 118 - 0
.gitignore

@@ -0,0 +1,118 @@
+/logs
+config.ini
+
+
+
+
+# Created by https://www.gitignore.io/api/windows,intellij,notepadpp
+# Edit at https://www.gitignore.io/?templates=windows,intellij,notepadpp
+
+### Intellij ###
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
+
+# User-specific stuff
+.idea/**/workspace.xml
+.idea/**/tasks.xml
+.idea/**/usage.statistics.xml
+.idea/**/dictionaries
+.idea/**/shelf
+
+# Generated files
+.idea/**/contentModel.xml
+
+# Sensitive or high-churn files
+.idea/**/dataSources/
+.idea/**/dataSources.ids
+.idea/**/dataSources.local.xml
+.idea/**/sqlDataSources.xml
+.idea/**/dynamic.xml
+.idea/**/uiDesigner.xml
+.idea/**/dbnavigator.xml
+
+# Gradle
+.idea/**/gradle.xml
+.idea/**/libraries
+
+# Gradle and Maven with auto-import
+# When using Gradle or Maven with auto-import, you should exclude module files,
+# since they will be recreated, and may cause churn.  Uncomment if using
+# auto-import.
+# .idea/modules.xml
+# .idea/*.iml
+# .idea/modules
+
+# CMake
+cmake-build-*/
+
+# Mongo Explorer plugin
+.idea/**/mongoSettings.xml
+
+# File-based project format
+*.iws
+
+# IntelliJ
+out/
+
+# mpeltonen/sbt-idea plugin
+.idea_modules/
+
+# JIRA plugin
+atlassian-ide-plugin.xml
+
+# Cursive Clojure plugin
+.idea/replstate.xml
+
+# Crashlytics plugin (for Android Studio and IntelliJ)
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+fabric.properties
+
+# Editor-based Rest Client
+.idea/httpRequests
+
+# Android studio 3.1+ serialized cache file
+.idea/caches/build_file_checksums.ser
+
+### Intellij Patch ###
+# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
+
+# *.iml
+# modules.xml
+# .idea/misc.xml
+# *.ipr
+
+# Sonarlint plugin
+.idea/sonarlint
+
+### NotepadPP ###
+# Notepad++ backups #
+*.bak
+
+### Windows ###
+# Windows thumbnail cache files
+Thumbs.db
+ehthumbs.db
+ehthumbs_vista.db
+
+# Dump file
+*.stackdump
+
+# Folder config file
+[Dd]esktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Windows Installer files
+*.cab
+*.msi
+*.msix
+*.msm
+*.msp
+
+# Windows shortcuts
+*.lnk
+
+# End of https://www.gitignore.io/api/windows,intellij,notepadpp

+ 252 - 0
klanhaboru_sandbox.au3

@@ -0,0 +1,252 @@
+;;Klanhaboru fun
+AutoItSetOption("SendKeyDelay", 3)
+AutoItSetOption("SendKeyDownDelay", 5)
+AutoItSetOption("WinTitleMatchMode", 2)
+Global $gameTitle = "Klánháború"
+Global $pageLoadTime = 1500 ;inMs
+Global $gyujtogetesWaitTime = 1200000 ;20m default fallback value
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; User Config
+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")
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+WinActivate("chrome")
+WinWaitActive($gameTitle)
+Sleep(1000)
+While 1
+   gyujtogetes(2, -1, -1, -1, -1, -1, -1, -1, -1) ;$mode, $landzsas, $kardforgato, $bardos, $ijasz, $konnyulovas, $lovasijasz, $nehezlovas, $lovag
+   Sleep($gyujtogetesWaitTime)
+   trainUnits(0, 0, 0, 5) ;$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
+WEnd
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Functions
+func gyujtogetes($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)
+   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
+	  ConsoleWrite("Gyüjtögetés Skip!" & @CRLF)
+	  Return False
+   EndIf
+   navigateUrl(getGameUrl("place", "scavenge"))
+   Sleep($pageLoadTime)
+
+   if ($landzsas > 0) Then
+	  jsExecutor("document.getElementsByName('spear')[0].value = '" & $landzsas & "';")
+   EndIf
+   if ($kardforgato > 0) Then
+	  jsExecutor("document.getElementsByName('sword')[0].value = '" & $kardforgato & "';")
+   EndIf
+   if ($bardos > 0) Then
+	  jsExecutor("document.getElementsByName('axe')[0].value = '" & $bardos & "';")
+   EndIf
+   if ($ijasz > 0) Then
+	  jsExecutor("document.getElementsByName('archer')[0].value = '" & $ijasz & "';")
+   EndIf
+   if ($konnyulovas > 0) Then
+	  jsExecutor("document.getElementsByName('light')[0].value = '" & $konnyulovas & "';")
+   EndIf
+   if ($lovasijasz > 0) Then
+	  jsExecutor("document.getElementsByName('marcher')[0].value = '" & $lovasijasz & "';")
+   EndIf
+   if ($nehezlovas > 0) Then
+	  jsExecutor("document.getElementsByName('heavy')[0].value = '" & $nehezlovas & "';")
+   EndIf
+   if ($lovag > 0) Then
+	  jsExecutor("document.getElementsByName('knight')[0].value = '" & $lovag & "';")
+   EndIf
+
+   if ($landzsas < 0) Then
+	  jsExecutor("document.getElementsByName('spear')[0].parentElement.children[1].click();")
+   EndIf
+   if ($kardforgato < 0) Then
+	  jsExecutor("document.getElementsByName('sword')[0].parentElement.children[1].click();")
+   EndIf
+   if ($bardos < 0) Then
+	  jsExecutor("document.getElementsByName('axe')[0].parentElement.children[1].click();")
+   EndIf
+   if ($ijasz < 0) Then
+	  jsExecutor("document.getElementsByName('archer')[0].parentElement.children[1].click();")
+   EndIf
+   if ($konnyulovas < 0) Then
+	  jsExecutor("document.getElementsByName('light')[0].parentElement.children[1].click();")
+   EndIf
+   if ($lovasijasz < 0) Then
+	  jsExecutor("document.getElementsByName('marcher')[0].parentElement.children[1].click();")
+   EndIf
+   if ($nehezlovas < 0) Then
+	  jsExecutor("document.getElementsByName('heavy')[0].parentElement.children[1].click();")
+   EndIf
+   if ($lovag < 0) Then
+	  jsExecutor("document.getElementsByName('knight')[0].parentElement.children[1].click();")
+   EndIf
+   ;sendJsClickByClass("fill-all")
+   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)
+   ConsoleWrite(@CRLF)
+EndFunc
+
+
+func trainUnits($landzsas, $kardforgato, $bardos, $ijasz)
+   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 & "';")
+   EndIf
+   if ($kardforgato > 0) Then
+	  jsExecutor("document.getElementsByName('sword')[0].value = '" & $kardforgato & "';")
+   EndIf
+   if ($bardos > 0) Then
+	  jsExecutor("document.getElementsByName('axe')[0].value = '" & $bardos & "';")
+   EndIf
+   if ($ijasz > 0) Then
+	  jsExecutor("document.getElementsByName('archer')[0].value = '" & $ijasz & "';")
+   EndIf
+
+   if ($landzsas < 0) Then
+	  jsExecutor("document.getElementsByName('spear')[0].parentElement.children[1].click();")
+   EndIf
+   if ($kardforgato < 0) Then
+	  jsExecutor("document.getElementsByName('sword')[0].parentElement.children[1].click();")
+   EndIf
+   if ($bardos < 0) Then
+	  jsExecutor("document.getElementsByName('axe')[0].parentElement.children[1].click();")
+   EndIf
+   if ($ijasz < 0) Then
+	  jsExecutor("document.getElementsByName('archer')[0].parentElement.children[1].click();")
+   EndIf
+   sendJsClickByClass("btn-recruit")
+   ConsoleWrite(@CRLF)
+   Sleep($pageLoadTime)
+EndFunc
+
+
+func trainLovassag($kem, $konnyulovas, $lovasijasz, $nehezlovas)
+   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 & "';")
+   EndIf
+   if ($konnyulovas > 0) Then
+	  jsExecutor("document.getElementsByName('light')[0].value = '" & $konnyulovas & "';")
+   EndIf
+   if ($lovasijasz > 0) Then
+	  jsExecutor("document.getElementsByName('marcher')[0].value = '" & $lovasijasz & "';")
+   EndIf
+   if ($nehezlovas > 0) Then
+	  jsExecutor("document.getElementsByName('heavy')[0].value = '" & $nehezlovas & "';")
+   EndIf
+
+   if ($kem < 0) Then
+	  jsExecutor("document.getElementsByName('spy')[0].parentElement.children[1].click();")
+   EndIf
+   if ($konnyulovas < 0) Then
+	  jsExecutor("document.getElementsByName('light')[0].parentElement.children[1].click();")
+   EndIf
+   if ($lovasijasz < 0) Then
+	  jsExecutor("document.getElementsByName('marcher')[0].parentElement.children[1].click();")
+   EndIf
+   if ($nehezlovas < 0) Then
+	  jsExecutor("document.getElementsByName('heavy')[0].parentElement.children[1].click();")
+   EndIf
+   sendJsClickByClass("btn-recruit")
+   ConsoleWrite(@CRLF)
+   Sleep($pageLoadTime)
+EndFunc
+
+func epites($buildingId) ;Options: main, barracks, stable, watchtower, smith, place, statue, market, wood, stone, iron, farm, storage, hide, wall
+   ConsoleWrite("Epites started: " & $buildingId & @CRLF)
+   navigateUrl(getGameUrl("main", ""))
+   Sleep($pageLoadTime)
+   jsExecutor("document.querySelector('{#}main_buildrow_" & $buildingId & "').querySelector('a.btn-build').click();")
+   Sleep($pageLoadTime)
+   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
+
+func sendJsClickById($elementId)
+   jsExecutor("document.getElementsById('" & $elementId & "').click();")
+EndFunc
+
+func sendJsClickByClass($classId)
+   jsExecutor("document.getElementsByClassName('" & $classId & "')[0].click();")
+EndFunc
+
+func jsExecutor($code)
+   $code = "javascript:(function(){{}" & $code & "{}})();"
+   navigateUrl($code)
+EndFunc
+
+func navigateUrl($url)
+   WinWaitActive($gameTitle)
+   ConsoleWrite($url & @CRLF)
+   Sleep(300)
+   Send("^l")
+   Sleep(300)
+   Send("^a")
+   Sleep(300)
+   Send($url)
+   Sleep(300)
+   Send("{ENTER}")
+   Sleep(300)
+EndFunc