Advertisement
Crazyzach

SodaDungeon

Jun 6th, 2016
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.10 KB | None | 0 0
  1. require "math"
  2.  
  3.  
  4. PATRON_IMAGES = {
  5. [""] = {},
  6. ["Dark Mage"] = {"dark_mage.png", "dark_mage_mirrored.png"},
  7. ["Healer"] = {"healer.png", "healer_mirrored.png"},
  8. ["Knight"] = {"knight.png", "knight_mirrored.png"},
  9. ["Thief"] = {"thief.png", "thief_mirrored.png"},
  10. }
  11.  
  12.  
  13. function get_table_keys(table_)
  14. keys = {}
  15. for key, value in pairs(table_) do
  16. table.insert(keys, key)
  17. end
  18.  
  19. return keys
  20. end
  21.  
  22.  
  23. function map(array, predicate)
  24. local result = {}
  25. for _, value in ipairs(array) do
  26. table.insert(result, predicate(value))
  27. end
  28.  
  29. return result
  30. end
  31.  
  32.  
  33. function any(array)
  34. for _, value in ipairs(array) do
  35. if value == true then
  36. return true
  37. end
  38. end
  39.  
  40. return false
  41. end
  42.  
  43.  
  44. -- All these return a boolean, indicating either success or failure of the
  45. -- action described by the function identifier.
  46. function leave()
  47. return existsClick("leave.png")
  48. end
  49.  
  50.  
  51. function yes()
  52. return existsClick("yes.png")
  53. end
  54.  
  55.  
  56. function enter_tavern()
  57. return existsClick("tavern.png")
  58. end
  59.  
  60.  
  61. function tavern_refresh_patrons()
  62. return existsClick("tavern_refresh_patrons.png") and yes()
  63. end
  64.  
  65.  
  66. function tavern_hire()
  67. return existsClick("tavern_hire.png")
  68. end
  69.  
  70.  
  71. function mage_talk()
  72. return existsClick("Wizard.png")
  73. end
  74.  
  75.  
  76. function mage_warp()
  77. return existsClick("warp.png")
  78. end
  79.  
  80.  
  81. function dungeon_level_up(times)
  82. times = times or 1
  83.  
  84. -- Not sure what continueClick returns, it's undocumented. Assume it's a
  85. -- boolean, similarly to what existsClick returns.
  86. return continueClick("dungeon_level_up.png", times)
  87. end
  88.  
  89.  
  90. function dungeon_level_down(times)
  91. times = times or 1
  92.  
  93. -- Not sure what continueClick returns, it's undocumented. Assume it's a
  94. -- boolean, similarly to what existsClick returns.
  95. return continueClick("dungeon_level_down.png")
  96. end
  97.  
  98.  
  99. function dungeon_go()
  100. return existsClick("dungeon_go.png") and yes()
  101. end
  102.  
  103.  
  104. function hire_patrons(type_, count)
  105. local images = PATRON_IMAGES[type_]
  106. local hired = 0
  107. local any_existed = false
  108.  
  109. while count > hired do
  110. any_existed = false
  111. for _, image in ipairs(images) do
  112. if existsClick(image) then
  113. tavern_hire()
  114. hired = hired + 1
  115. any_existed = true
  116. break
  117. end
  118. end
  119.  
  120. if not any_existed then
  121. break
  122. end
  123. end
  124.  
  125. return hired
  126. end
  127.  
  128.  
  129. function hire_with_refresh(type_, count)
  130. local patrons = 0
  131. while patrons < count do
  132. local need = count - patrons
  133. local hired = hire_patrons(type_, need)
  134.  
  135. patrons = patrons + hired
  136. if patrons < count then
  137. tavern_refresh_patrons()
  138. end
  139. end
  140. end
  141.  
  142.  
  143. function show_configuration_dialog()
  144. patrons = get_table_keys(PATRON_IMAGES)
  145. table.sort(patrons)
  146.  
  147. dialogInit()
  148. addTextView("Patrons:")
  149. newRow()
  150. addTextView("#1:")
  151. addSpinner("configuration_patron_1", patrons, patrons[0])
  152. newRow()
  153. addTextView("#2:")
  154. addSpinner("configuration_patron_2", patrons, patrons[0])
  155. newRow()
  156. addTextView("#3:")
  157. addSpinner("configuration_patron_3", patrons, patrons[0])
  158. newRow()
  159. addTextView("#4:")
  160. addSpinner("configuration_patron_4", patrons, patrons[0])
  161. newRow()
  162. addTextView("#5:")
  163. addSpinner("configuration_patron_5", patrons, patrons[0])
  164. newRow()
  165. addTextView("Level:")
  166. addEditNumber("configuration_level", "0")
  167. dialogShow("Configuration")
  168.  
  169. -- Truncate possible float value to integer, negative values can't be entered
  170. -- apparently
  171. configuration_level = math.floor(configuration_level)
  172.  
  173. -- Check for configuration errors:
  174. local patrons = {}
  175. for index = 1, 5 do
  176. table.insert(patrons, _G["configuration_patron_" .. index])
  177. end
  178.  
  179. return any(map(patrons, function(value) return value ~= "" end))
  180. end
  181.  
  182.  
  183. function show_error_dialog(message)
  184. dialogInit()
  185. addTextView(message)
  186. dialogShow("Error")
  187. end
  188.  
  189.  
  190. function initialize()
  191. Settings:setCompareDimension(true, 1920)
  192. Settings:setScriptDimension(true, 1920)
  193. Settings:set("MinSimilarity", 0.9)
  194. end
  195.  
  196.  
  197. -- There's basically no error handling: the calling code is expected to respect
  198. -- the game context created by previous function calls.
  199. function main()
  200. if not show_configuration_dialog() then
  201. show_error_dialog("At least one patron must be hired!")
  202. return
  203. end
  204.  
  205. while true do
  206. enter_tavern()
  207.  
  208. for index = 1, 5 do
  209. local type_ = _G["configuration_patron_" .. index]
  210. if type_ ~= "" then
  211. hire_with_refresh(type_, 1)
  212. end
  213. end
  214.  
  215.  
  216. if configuration_level ~= 0 then
  217. dungeon_level_up()
  218. dungeon_level_up(configuration_level)
  219. end
  220.  
  221. dungeon_go()
  222.  
  223. -- Check if the leave button is displayed every minute, indicating that the
  224. -- run is over. It does not need to be checked any more often, because runs
  225. -- usually lasts several minutes or even hours. Choosing a more frequent
  226. -- value would be needlessly taxing on the CPU.
  227. while not leave() do
  228. wait(60)
  229. end
  230.  
  231. -- Make sure that the shadow effect has fully disappeared before using
  232. -- enter_tavern() again.
  233. wait(3)
  234. end
  235. end
  236.  
  237.  
  238. initialize()
  239. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement