grind_at_home.py 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. import logging
  2. import math
  3. import random
  4. import secrets
  5. import time
  6. from threading import Timer
  7. import httpx
  8. from colorama import Back, Fore, Style
  9. class RepeatedTimer(object):
  10. def __init__(self, interval, function, *args, **kwargs):
  11. self._timer = None
  12. self.interval = interval
  13. self.function = function
  14. self.args = args
  15. self.kwargs = kwargs
  16. self.is_running = False
  17. self.start()
  18. def _run(self):
  19. self.is_running = False
  20. self.start()
  21. self.function(*self.args, **self.kwargs)
  22. def start(self):
  23. if not self.is_running:
  24. self._timer = Timer(self.interval, self._run)
  25. self._timer.daemon = True
  26. self._timer.start()
  27. self.is_running = True
  28. def stop(self):
  29. self._timer.cancel()
  30. self.is_running = False
  31. class GrindAtHome:
  32. def __init__(self, account):
  33. self.account = account
  34. self.monsters = {}
  35. self.shops = {}
  36. self.area = {}
  37. # self.area_c = secrets.token_hex(6)
  38. self.area_c = self.account.config['area_c']
  39. self.notifications = {}
  40. self.friends = {}
  41. self.me = {}
  42. self.location = {'x': None, 'y': None}
  43. self.stashed_time = {}
  44. self.stashed_geo = {}
  45. self.inventory = {}
  46. self.hp_total = 0
  47. self.hp_current = 0
  48. self.mana_total = 0
  49. self.mana_current = 0
  50. self.gold = 0
  51. self.orns = 0
  52. self.light_bonus = False
  53. self.level = 0
  54. self.tier = 0
  55. self.username = ''
  56. self.arena_do = False
  57. self.arena_time = time.time()
  58. self.clan_uuid = None
  59. self.clan = {}
  60. self.kingdom_raids_time = time.time()
  61. self.kingdom_raids_do = False
  62. self.kingdom_war_time = time.time()
  63. self.kingdom_war_do = False
  64. self.blacksmith_time = time.time()
  65. self.blacksmith_do = False
  66. # @staticmethod
  67. def nextLocation(self, distance):
  68. home_x = float(self.account.config['home_x'])
  69. home_y = float(self.account.config['home_y'])
  70. if distance == 'small':
  71. radius = 0.00001
  72. elif distance == 'medium':
  73. radius = 0.0001
  74. elif distance == 'big':
  75. radius = 0.0005
  76. else:
  77. radius = 0.000001
  78. random_alpha = 2 * math.pi * random.random()
  79. random_radius = radius * math.sqrt(random.random())
  80. new_x = random_radius * math.cos(random_alpha) + home_x
  81. new_y = random_radius * math.sin(random_alpha) + home_y
  82. new_x = round(new_x, 7)
  83. new_y = round(new_y, 7)
  84. return (new_x, new_y)
  85. # FirstRequests
  86. def firstRequests(self):
  87. logger = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  88. self.get_me()
  89. self.get_inventory(initial=True)
  90. self.account.get('/codex/completed/')
  91. logger.debug('/codex/completed/')
  92. self.get_friends(initial=True)
  93. self.get_area(initial=True)
  94. self.get_monsters(initial=True)
  95. self.get_shops(initial=True)
  96. self.account.get('/quests/daily/')
  97. logger.debug('/quests/daily/')
  98. self.get_notifications(initial=True)
  99. self.get_clan()
  100. def idle(self):
  101. logger = logging.getLogger('ornauto.GrindAtHome.idle')
  102. exit = False
  103. rt_mon = RepeatedTimer(30, self.get_monsters)
  104. rt_shop = RepeatedTimer(30, self.get_shops)
  105. rt_notif = RepeatedTimer(60, self.get_notifications)
  106. rt_frnd = RepeatedTimer(120, self.get_friends)
  107. # rt_area = RepeatedTimer(60, self.get_area, 'small')
  108. rt_area = RepeatedTimer(60, self.get_area, 'small')
  109. rt_arena = RepeatedTimer(60, self.arena_check)
  110. rt_kingdom_raids = RepeatedTimer(60, self.kingdom_raids_check)
  111. rt_kingdom_war = RepeatedTimer(60, self.kingdom_war_check)
  112. rt_blacksmith = RepeatedTimer(60, self.blacksmith_check)
  113. while not exit:
  114. # pass
  115. time.sleep(random.uniform(1000, 4000) / 1000)
  116. self.fight()
  117. self.grab_chests()
  118. if self.arena_do:
  119. self.arena_battle()
  120. if self.kingdom_raids_do:
  121. self.kingdom_raids_battle()
  122. if self.kingdom_war_do:
  123. self.kingdom_war_battle()
  124. if self.blacksmith_do:
  125. self.blacksmith_upgrade()
  126. def get_monsters(self, initial=False):
  127. logger = logging.getLogger('ornauto.GrindAtHome.get_monsters')
  128. result_monsters = None
  129. if initial:
  130. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  131. logger_initial.debug('/monsters/')
  132. try:
  133. result_monsters = self.account.get('/monsters/', params={'i': 1}).json()
  134. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  135. pass
  136. else:
  137. logger.debug('/monsters/')
  138. try:
  139. result_monsters = self.account.get('/monsters/').json()
  140. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  141. pass
  142. if result_monsters is not None:
  143. if not result_monsters['success'] and result_monsters['throttled']:
  144. logger.debug('throttled')
  145. elif result_monsters['success'] and 'throttled' not in result_monsters:
  146. self.monsters = result_monsters
  147. def get_area(self, distance='small', initial=False):
  148. logger = logging.getLogger('ornauto.GrindAtHome.get_area')
  149. loc_x, loc_y = self.nextLocation(distance)
  150. if initial:
  151. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  152. logger_initial.debug('/area/')
  153. try:
  154. result_area = self.account.get(
  155. '/area/',
  156. params={
  157. 'i': 1,
  158. 'latitude': loc_x,
  159. 'longitude': loc_y,
  160. 'm': 'false',
  161. 'c': self.area_c,
  162. }
  163. ).json()
  164. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  165. pass
  166. else:
  167. logger.debug('/area/')
  168. try:
  169. result_area = self.account.get(
  170. '/area/',
  171. params={
  172. 'latitude': loc_x,
  173. 'longitude': loc_y,
  174. 'm': 'false',
  175. 'c': self.area_c,
  176. }
  177. ).json()
  178. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  179. pass
  180. self.area = result_area
  181. def get_shops(self, initial=False):
  182. logger = logging.getLogger('ornauto.GrindAtHome.get_shops')
  183. if initial:
  184. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  185. logger_initial.debug('/shops/')
  186. try:
  187. result_shops = self.account.get('/shops/', params={'i': 1}).json()
  188. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  189. pass
  190. else:
  191. logger.debug('/shops/')
  192. try:
  193. result_shops = self.account.get('/shops/').json()
  194. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  195. pass
  196. self.shops = result_shops
  197. def get_notifications(self, initial=False):
  198. logger = logging.getLogger('ornauto.GrindAtHome.get_notifications')
  199. if initial:
  200. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  201. logger_initial.debug('/notifications/')
  202. else:
  203. logger.debug('/notifications/')
  204. try:
  205. result_notifications = self.account.get('/notifications/', params={'v': 2}).json()
  206. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  207. pass
  208. if result_notifications and result_notifications['success']:
  209. if result_notifications['result'] != []:
  210. logger.info(Fore.YELLOW + result_notifications['result'][0]['items'][0]['title'] + Style.RESET_ALL)
  211. if 'subtitle' in result_notifications['result'][0]['items'][0]:
  212. logger.info(Fore.YELLOW + result_notifications['result'][0]['items'][0]['subtitle'] + Style.RESET_ALL)
  213. if 'description' in result_notifications['result'][0]['items'][0]:
  214. logger.info(Fore.YELLOW + result_notifications['result'][0]['items'][0]['description'] + Style.RESET_ALL)
  215. if 'gold' in result_notifications['result'][0]['items'][0] and result_notifications['result'][0]['items'][0]['gold'] > 0:
  216. string = Fore.YELLOW + 'Gold: ' + '{}' + Style.RESET_ALL
  217. logger.info(string.format(result_notifications['result'][0]['items'][0]['gold']))
  218. if 'orns' in result_notifications['result'][0]['items'][0] and result_notifications['result'][0]['items'][0]['orns'] > 0:
  219. string = Fore.YELLOW + 'Orns: ' + '{}' + Style.RESET_ALL
  220. logger.info(string.format(result_notifications['result'][0]['items'][0]['orns']))
  221. if 'exp' in result_notifications['result'][0]['items'][0] and result_notifications['result'][0]['items'][0]['exp'] > 0:
  222. string = Fore.YELLOW + 'Exp: ' + '{}' + Style.RESET_ALL
  223. logger.info(string.format(result_notifications['result'][0]['items'][0]['exp']))
  224. self.get_me()
  225. self.get_inventory()
  226. self.notifications = result_notifications
  227. def get_friends(self, initial=False):
  228. logger = logging.getLogger('ornauto.GrindAtHome.get_friends')
  229. if initial:
  230. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  231. logger_initial.debug('/friends/')
  232. else:
  233. logger.debug('/friends/')
  234. try:
  235. result_friends = self.account.get('/friends/').json()
  236. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  237. pass
  238. self.friends = result_friends
  239. def get_me(self):
  240. logger = logging.getLogger('ornauto.GrindAtHome.get_me')
  241. logger.debug('/me/')
  242. result_me = None
  243. try:
  244. result_me = self.account.get('/me/', params={'w': 515, 'v': self.account.config['x-orna-version']}).json()
  245. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  246. pass
  247. if result_me is None or result_me['success'] is False:
  248. logger.critical('Failure')
  249. exit(1)
  250. else:
  251. self.hp_total = result_me['user']['hp']
  252. self.hp_current = result_me['user']['current_hp']
  253. self.mana_total = result_me['user']['mana']
  254. self.mana_current = result_me['user']['current_mana']
  255. self.gold = result_me['user']['gold']
  256. self.orns = result_me['user']['orns']
  257. self.light_bonus = result_me['user']['light_bonus']
  258. self.level = result_me['user']['level']
  259. self.clan_uuid = result_me['user']['clan']['uuid']
  260. self.tier = result_me['user']['tier']
  261. self.username = result_me['user']['username']
  262. self.me = result_me
  263. def fight(self):
  264. logger = logging.getLogger('ornauto.GrindAtHome.fight')
  265. # mon = max(self.monsters, key=lambda d: d["level"])
  266. # Check if monster can be removed from time stash
  267. mon = None
  268. result = []
  269. for monster in self.monsters['result']:
  270. result.append(monster)
  271. for monster in self.area['result']:
  272. result.append(monster)
  273. for monster in result:
  274. color_i = Fore.WHITE + Style.BRIGHT
  275. if monster['uuid'] in self.stashed_time:
  276. if (time.time() - self.stashed_time[monster['uuid']]['time'] > 300):
  277. name = ''
  278. level = ''
  279. arisen = ''
  280. berserk = ''
  281. boss = ''
  282. color_b = ''
  283. space_1 = ''
  284. space_2 = ''
  285. space_3 = ''
  286. tier = ''
  287. color_i = Fore.WHITE + Style.BRIGHT
  288. if 'name' in self.stashed_time[monster['uuid']]:
  289. name = self.stashed_time[monster['uuid']]['name']
  290. if 'level' in self.stashed_time[monster['uuid']]:
  291. level = self.stashed_time[monster['uuid']]['level']
  292. if 'berserk' in self.stashed_time[monster['uuid']]:
  293. if self.stashed_time[monster['uuid']]['berserk']:
  294. berserk = 'Berserk'
  295. space_1 = ' '
  296. color_b = Fore.RED + Style.BRIGHT
  297. if 'boss' in self.stashed_time[monster['uuid']]:
  298. if self.stashed_time[monster['uuid']]['boss']:
  299. boss = 'Boss'
  300. space_2 = ' '
  301. color_b = Fore.RED + Style.BRIGHT
  302. if 'arisen' in self.stashed_time[monster['uuid']]:
  303. if self.stashed_time[monster['uuid']]['arisen']:
  304. arisen = 'Arisen'
  305. space_3 = ' '
  306. color_b = Fore.RED + Style.BRIGHT
  307. if 'tier' in self.stashed_time[monster['uuid']]:
  308. tier = self.stashed_time[monster['uuid']]['tier']
  309. logger_string = Fore.WHITE + Style.BRIGHT + 'Removing ({tier}★) {color_b}{boss}{space_2}{berserk}{space_1}{arisen}{space_3}{color_i}{name} ({level}) from time stash' + Style.RESET_ALL
  310. logger.info(logger_string.format(name=name, level=level, tier=tier, berserk=berserk, boss=boss, arisen=arisen, space_1=space_1, space_2=space_2, space_3=space_3, color_b=color_b, color_i=color_i, color_e=Style.RESET_ALL))
  311. del(self.stashed_time[monster['uuid']])
  312. # Check for bosses
  313. for monster in self.area['result']:
  314. if monster['uuid'] not in self.stashed_time and monster['uuid'] not in self.stashed_geo:
  315. if mon is None:
  316. mon = monster
  317. elif monster['level'] > mon['level']:
  318. mon = monster
  319. # If no bosses check through quest mobs
  320. if mon is None:
  321. for monster in self.monsters['result']:
  322. if monster['uuid'] not in self.stashed_time and monster['uuid'] not in self.stashed_geo:
  323. if monster['is_quest']:
  324. if mon is None:
  325. mon = monster
  326. elif monster['level'] > mon['level']:
  327. mon = monster
  328. # If no bosses check through regular mobs
  329. if mon is None:
  330. for monster in self.monsters['result']:
  331. if monster['uuid'] not in self.stashed_time and monster['uuid'] not in self.stashed_geo:
  332. # If mobs are berserk and arisen, they should not be higher than player level
  333. if not ((monster['is_berserk'] and monster['is_arisen']) and (monster['level'] > (self.level + 10))):
  334. if mon is None:
  335. mon = monster
  336. elif monster['level'] > mon['level']:
  337. mon = monster
  338. # If no monsters on map
  339. if mon is None:
  340. logger.info(Fore.WHITE + Style.BRIGHT + 'No monsters to fight. Sleeping for 5 seconds.' + Style.RESET_ALL)
  341. # self.get_monsters()
  342. time.sleep(5)
  343. return
  344. for item in self.inventory['result']:
  345. need_hp = False
  346. need_mp = False
  347. if item['name'] == 'Small Health Potion':
  348. if item['count'] < 50:
  349. need_hp = True
  350. if item['name'] == 'Small Mana Potion':
  351. if item['count'] < 50:
  352. need_mp = True
  353. if need_hp or need_mp:
  354. self.shop_for_potions(hp=need_hp, mp=need_mp)
  355. if (self.hp_current / self.hp_total < 0.50) or (self.mana_current / self.mana_total < 0.50) or mon['is_berserk'] or mon['level'] >= self.level or mon['is_boss']:
  356. self.autoheal()
  357. # Check if we need to use a Torch
  358. use_torch = True
  359. for active_item in self.me['user']['active_items']:
  360. if active_item['name'] == 'Torch':
  361. use_torch = False
  362. if use_torch:
  363. self.use_torch()
  364. uuid_mon = mon['uuid']
  365. time.sleep(random.uniform(500, 1000) / 1000)
  366. logger.debug('/battles/monster/')
  367. try:
  368. result = self.account.post('/battles/monster/', data={'uuid': uuid_mon})
  369. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  370. pass
  371. name = mon['name']
  372. level = mon['level']
  373. berserk = mon['is_berserk']
  374. boss = mon['is_boss']
  375. arisen = mon['is_arisen']
  376. tier = mon['tier']
  377. berserk_text = ''
  378. berserk_color = ''
  379. boss_text = ''
  380. arisen_text = ''
  381. space_1 = ''
  382. space_2 = ''
  383. space_3 = ''
  384. if berserk:
  385. berserk_text = 'Berserk'
  386. berserk_color = Fore.RED + Style.BRIGHT
  387. space_1 = ' '
  388. if boss:
  389. boss_text = 'Boss'
  390. berserk_color = Fore.RED + Style.BRIGHT
  391. space_2 = ' '
  392. if arisen:
  393. arisen_text = 'Arisen'
  394. berserk_color = Fore.RED + Style.BRIGHT
  395. space_3 = ' '
  396. if result and not result.json()['success']:
  397. if result.json()['message'] == 'You must wait before you can challenge this monster again':
  398. self.stashed_time[uuid_mon] = {'time': time.time(), 'name': mon['name'], 'level': mon['level'], 'tier': mon['tier'], 'berserk': mon['is_berserk'], 'boss': mon['is_boss'], 'arisen': mon['is_arisen']}
  399. logger_str = Fore.WHITE + Style.BRIGHT + 'Moving ({tier}★) {color_b}{boss}{space_2}{berserk}{space_1}{arisen}{space_3}{color_i}{} ({}) to time stash' + Style.RESET_ALL
  400. logger.info(logger_str.format(mon['name'], mon['level'], tier=tier, berserk=berserk_text, boss=boss_text, arisen=arisen_text, space_1=space_1, space_2=space_2, space_3=space_3, color_b=berserk_color, color_i=color_i, color_e=Style.RESET_ALL))
  401. return
  402. if result.json()['message'] == 'Move closer to challenge this monster':
  403. self.stashed_geo[uuid_mon] = mon['location']
  404. logger_str = Fore.WHITE + Style.BRIGHT + 'Moving ({tier}★) {color_b}{boss}{space_2}{berserk}{space_1}{arisen}{space_3}{color_i}{} ({}) to geo stash' + Style.RESET_ALL
  405. logger.info(logger_str.format(mon['name'], mon['level'], tier=tier, berserk=berserk_text, boss=boss_text, arisen=arisen_text, space_1=space_1, space_2=space_2, space_3=space_3, color_b=berserk_color, color_i=color_i, color_e=Style.RESET_ALL))
  406. return
  407. logger.info('Fighting ({tier}★) {color_b}{boss}{space_2}{berserk}{space_1}{arisen}{space_3}{color_e}{} ({})'.format(name, level, tier=tier, berserk=berserk_text, boss=boss_text, arisen=arisen_text, space_1=space_1, space_2=space_2, space_3=space_3, color_b=berserk_color, color_e=Style.RESET_ALL))
  408. if result and result.json()['success']:
  409. uuid = result.json()['result']['uuid']
  410. # time.sleep(random.uniform(500, 1500) / 1000)
  411. logger.debug('/battles/monster/')
  412. try:
  413. result = self.account.get('/battles/monster/', params={'uuid': uuid})
  414. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  415. pass
  416. if result and result.json()['success']:
  417. uuid_new = result.json()['result']['uuid']
  418. state_id = ''
  419. has_won = False
  420. has_lost = False
  421. while(not has_won and not has_lost):
  422. if 'state_id' in result.json():
  423. state_id = result.json()['state_id']
  424. time.sleep(random.uniform(150, 500) / 1000)
  425. logger.debug('/battles/monster/turn/')
  426. need_mp = False
  427. if 'player_mana' in result.json():
  428. if result.json()['player_mana'] < 35:
  429. need_mp = True
  430. if 'result' in result.json():
  431. if 'player_mana' in result.json()['result']:
  432. if result.json()['result']['player_mana'] < 35:
  433. need_mp = True
  434. if need_mp:
  435. ssmp_uuid = None
  436. ssmp_id = None
  437. lmp_uuid = None
  438. lmp_id = None
  439. gmp_uuid = None
  440. gmp_id = None
  441. smp_uuid = None
  442. smp_id = None
  443. xmp_uuid = None
  444. xmp_id = None
  445. data_uuid = None
  446. data_id = None
  447. # Drink MP
  448. for item in self.inventory['result']:
  449. if item['name'] == 'Small Mana Potion':
  450. ssmp_uuid = item['uuid']
  451. ssmp_id = item['id']
  452. if item['name'] == 'Large Mana Potion':
  453. lmp_uuid = item['uuid']
  454. lmp_id = item['id']
  455. if item['name'] == 'Greater Mana Potion':
  456. gmp_uuid = item['uuid']
  457. gmp_id = item['id']
  458. if item['name'] == 'Super Mana Potion':
  459. smp_uuid = item['uuid']
  460. smp_id = item['id']
  461. if item['name'] == 'X Mana Potion':
  462. xmp_uuid = item['uuid']
  463. xmp_id = item['id']
  464. if ssmp_uuid is None and ssmp_id is None:
  465. # No small potions so exit
  466. logger.critical('No more potions in inventory. Quit.')
  467. exit(1)
  468. if ssmp_uuid is not None and ssmp_id is not None:
  469. data_uuid = ssmp_uuid
  470. data_id = ssmp_id
  471. if mon['is_boss'] or mon['is_berserk']:
  472. if lmp_uuid is not None and lmp_id is not None:
  473. data_uuid = lmp_uuid
  474. data_id = lmp_id
  475. try:
  476. result = self.account.post(
  477. '/battles/monster/turn/',
  478. data={
  479. 'uuid': uuid_new,
  480. 'type': 'item',
  481. 'item_uuid': data_uuid,
  482. 'item_id': data_id,
  483. 'grouped': True,
  484. 'state_id': state_id
  485. }
  486. )
  487. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  488. pass
  489. logging.info('Used 1 ' + Fore.BLUE + 'Small Mana Potion' + Style.RESET_ALL)
  490. # elif mon['name'] in [
  491. # # 'Ghost',
  492. # # 'Gheist',
  493. # # 'Undead Golem',
  494. # # 'Demon Knight',
  495. # # 'Greater Demon',
  496. # # 'Lesser Sluagh',
  497. # # 'Skeleton Rogue',
  498. # # 'Skeleton Warrior',
  499. # # 'Vampire',
  500. # # 'Greater Vampire',
  501. # # 'Darkest Demon',
  502. # # 'Dark Slime',
  503. # # 'Odok',
  504. # # 'Odok Brute',
  505. # # 'Reaper',
  506. # # 'Vampire Lord',
  507. # # 'Dokkalfar Knight',
  508. # # 'Dokkalfar Lord',
  509. # # 'Gorgon',
  510. # # 'Racul',
  511. # # 'Kraken',
  512. # # 'Demon', # temporary while weapon is dark
  513. # ]:
  514. # # Attack with Holy
  515. # try:
  516. # result = self.account.post(
  517. # '/battles/monster/turn/',
  518. # data={
  519. # 'uuid': uuid_new,
  520. # 'type': 'spell',
  521. # 'spell_id': 'Holystrike',
  522. # 'state_id': state_id
  523. # }
  524. # )
  525. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  526. # pass
  527. # elif mon['name'] in [
  528. # # 'Blue Slime',
  529. # # 'Living Armor',
  530. # # 'Blue Flame',
  531. # # 'Golem',
  532. # # 'Mythril Armor',
  533. # # 'Wisp',
  534. # # 'Magma Golem',
  535. # # 'Great Gazer',
  536. # # "Will-O'-The-Wisp",
  537. # # # 'Twilight Wisp', # resists all
  538. # # 'Sandstone Golem',
  539. # # # 'Arisen Mimic King', # resits all
  540. # # 'Orichalcum Golem',
  541. # # 'Jelly',
  542. # # 'Lizarr Warrior',
  543. # # 'Lizarr Knight',
  544. # # 'Lizarr Lord',
  545. # # 'Lizarr Noble',
  546. # # 'Earth Core',
  547. # # 'Castor',
  548. # # 'Frost Mage',
  549. # # 'Sea Demon',
  550. # # 'Great Lizarr Knight',
  551. # # 'Great Lizarr Noble',
  552. # # 'Great Lizarr Warrior',
  553. # # 'Sea Wyvern',
  554. # # 'Hydra',
  555. # # 'Coral Beast',
  556. # # 'Coral Serpent',
  557. # # 'Coral Varmint',
  558. # # 'Pollux',
  559. # # 'Fallen Demeter, the Earth Magus',
  560. # ] or (mon['name'] in ['Undead Golem', 'Great Gazer', 'Hydra'] and mon['is_arisen']): # Cerberus and Lost Pharaoh and Camazotz are only here while wep dmg is Dark
  561. # # Attack with Lightning
  562. # try:
  563. # result = self.account.post(
  564. # '/battles/monster/turn/',
  565. # data={
  566. # 'uuid': uuid_new,
  567. # 'type': 'spell',
  568. # 'spell_id': 'Lightningstrike',
  569. # 'state_id': state_id
  570. # }
  571. # )
  572. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  573. # pass
  574. # elif mon['name'] in [
  575. # # 'Flame',
  576. # # 'Gazer',
  577. # # 'Colossus',
  578. # # 'Balor Flame',
  579. # # 'Firefly',
  580. # # 'Flame Core',
  581. # # 'Pyre',
  582. # # 'Scorcher',
  583. # # 'Infernal Bear',
  584. # # 'Fallen Vulcan, the Red Knight',
  585. # # 'Arisen Vulcan, the Red Knight',
  586. # ]:
  587. # # Attack with Water
  588. # try:
  589. # result = self.account.post(
  590. # '/battles/monster/turn/',
  591. # data={
  592. # 'uuid': uuid_new,
  593. # 'type': 'spell',
  594. # 'spell_id': 'Icestrike',
  595. # 'state_id': state_id
  596. # }
  597. # )
  598. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  599. # pass
  600. # elif mon['name'] in [
  601. # # 'Great Mimic',
  602. # # 'Ancient Mimic',
  603. # # 'Mighty Mimic',
  604. # # 'Ancient Gazer',
  605. # # 'Great Wyvern',
  606. # # 'Sea Wyvern',
  607. # # 'Dark Dragon',
  608. # # 'Drake',
  609. # # 'Mimic King',
  610. # # 'Small Dragon',
  611. # # 'Arcane Dragon',
  612. # # 'Tiamat',
  613. # # 'Typhon',
  614. # # 'Fafnir',
  615. # ]:
  616. # # Attack with none of these:
  617. # # physical, dark, earthern, fire, holy, lightning, water
  618. # # Most likely DRAGON or arcane
  619. # # drop from special lists to just hit with physical
  620. # try:
  621. # result = self.account.post(
  622. # '/battles/monster/turn/',
  623. # data={
  624. # 'uuid': uuid_new,
  625. # 'type': 'spell',
  626. # 'spell_id': 'Dragonstrike',
  627. # 'state_id': state_id
  628. # }
  629. # )
  630. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  631. # pass
  632. # elif mon['name'] in [
  633. # # 'Legionnaire',
  634. # # 'Frost Troll',
  635. # # 'Crimson Wood',
  636. # # 'Fallen Ithra, the White Knight',
  637. # # 'Arisen Ithra, the White Knight',
  638. # # 'Fey Cactus',
  639. # # 'Scruug',
  640. # # 'Frost Core',
  641. # # 'Walking Wood',
  642. # # 'Great Sprout',
  643. # # 'Sprout',
  644. # ]:
  645. # # Attack with Fire
  646. # try:
  647. # result = self.account.post(
  648. # '/battles/monster/turn/',
  649. # data={
  650. # 'uuid': uuid_new,
  651. # 'type': 'spell',
  652. # 'spell_id': 'Firestrike',
  653. # 'state_id': state_id
  654. # }
  655. # )
  656. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  657. # pass
  658. # elif mon['name'] in [
  659. # # 'Arcane Flame',
  660. # # 'Ancient Gazer',
  661. # # 'Gargoyle',
  662. # # 'Heimdall',
  663. # # 'Nidhogg',
  664. # # 'Draugr',
  665. # # 'Draugr Mage',
  666. # # 'Ancient Draugr',
  667. # # 'Ancient Draugr Mage',
  668. # # 'Draugr Lord',
  669. # # 'Ancient Draugr Lord',
  670. # ]:
  671. # # Attack with Earthern
  672. # try:
  673. # result = self.account.post(
  674. # '/battles/monster/turn/',
  675. # data={
  676. # 'uuid': uuid_new,
  677. # 'type': 'spell',
  678. # 'spell_id': 'Earthstrike',
  679. # 'state_id': state_id
  680. # }
  681. # )
  682. # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  683. # pass
  684. # # elif mon['name'] in [
  685. # # 'Camazotz',
  686. # # ]:
  687. # # # Attack with Physical or weapon type
  688. # # try:
  689. # # result = self.account.post(
  690. # # '/battles/monster/turn/',
  691. # # data={
  692. # # 'uuid': uuid_new,
  693. # # 'type': 'spell',
  694. # # 'spell_id': 'TripleCut',
  695. # # 'state_id': state_id
  696. # # }
  697. # # )
  698. # # except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  699. # # pass
  700. # Immune to physical so attach with one spell. Other spells can be utility.
  701. elif mon['name'] in [
  702. 'Ghost',
  703. 'Gheist',
  704. 'Orichalcum Golem',
  705. 'Ancient Mimic',
  706. 'Mighty Mimic',
  707. 'Tiamat',
  708. 'Typhon',
  709. 'Fafnir',
  710. ] or (mon['name'] == 'Great Gazer' and mon['is_arisen'] == True):
  711. # Attack with Earthern
  712. try:
  713. result = self.account.post(
  714. '/battles/monster/turn/',
  715. data={
  716. 'uuid': uuid_new,
  717. 'type': 'spell',
  718. 'spell_id': 'Dragonstrike',
  719. 'state_id': state_id
  720. }
  721. )
  722. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  723. pass
  724. else:
  725. # Volley II from offhand arrows
  726. try:
  727. result = self.account.post(
  728. '/battles/monster/turn/',
  729. data={
  730. 'uuid': uuid_new,
  731. 'type': 'ability',
  732. 'state_id': state_id
  733. }
  734. )
  735. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  736. pass
  737. if result and result.json()['success']:
  738. has_won = result.json()['result']['won']
  739. has_lost = result.json()['result']['lost']
  740. if has_won:
  741. for i in range(len(self.area['result'])):
  742. if self.area['result'][i]['uuid'] == uuid_mon:
  743. del(self.area['result'][i])
  744. break
  745. for i in range(len(self.monsters['result'])):
  746. if self.monsters['result'][i]['uuid'] == uuid_mon:
  747. del(self.monsters['result'][i])
  748. break
  749. elif has_lost:
  750. # self.stashed_time[uuid_mon] = time.time()
  751. self.stashed_time[uuid_mon] = {'time': time.time(), 'name': mon['name'], 'level': mon['level'], 'tier': mon['tier'], 'berserk': mon['is_berserk'], 'boss': mon['is_boss'], 'arisen': mon['is_arisen']}
  752. logger_str = Fore.WHITE + Style.BRIGHT + 'Lost battle. Moving ({tier}★) {color_b}{boss}{space_2}{berserk}{space_1}{arisen}{space_3}{color_i}{} ({}) to time stash.' + Style.RESET_ALL
  753. logger.info(logger_str.format(mon['name'], mon['level'], tier=tier, berserk=berserk_text, boss=boss_text, arisen=arisen_text, space_1=space_1, space_2=space_2, space_3=space_3, color_b=berserk_color, color_i=color_i, color_e=Style.RESET_ALL))
  754. self.get_me()
  755. def autoheal(self):
  756. logger = logging.getLogger('ornauto.GrindAtHome.autoheal')
  757. time.sleep(random.uniform(500, 1000) / 1000)
  758. logger.debug('/me/')
  759. try:
  760. result = self.account.post('/me/', data={'action': 'autoheal'})
  761. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  762. pass
  763. if result and result.json()['success']:
  764. for item in result.json()['result']:
  765. color = ''
  766. if 'Health Potion' in item:
  767. color = Fore.RED
  768. elif 'Mana Potion' in item:
  769. color = Fore.BLUE
  770. logger.info('Used {} {color_b}{}{color_e}'.format(result.json()['result'][item], item, color_b=color, color_e=Style.RESET_ALL))
  771. for item in result.json()['used_items']:
  772. for thing in self.inventory['result']:
  773. if item == thing['id']:
  774. thing['count'] -= result.json()['used_items'][item]
  775. self.hp_current = result.json()['current_hp']
  776. self.mana_current = result.json()['current_mana']
  777. def grab_chests(self):
  778. logger = logging.getLogger('ornauto.GrindAtHome.grab_chests')
  779. assert self.area
  780. if 'location' in self.area and self.area['success']:
  781. for chest in self.area['chests']:
  782. if 'fountain' not in chest['sprite']:
  783. chest_name = chest['sprite'].split('/')[-1].split('.')[0]
  784. chest_loc = (chest['location'][0], chest['location'][1])
  785. chest_uuid = chest['uuid']
  786. time.sleep(random.uniform(500, 1000) / 1000)
  787. logger.debug('/chest/')
  788. logger.info('Opening Chest')
  789. try:
  790. result = self.account.post('/chest/', data={'uuid': chest_uuid})
  791. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  792. pass
  793. if result and result.json()['success']:
  794. count = ''
  795. count_space = ''
  796. if 'count' in result.json()['result']:
  797. count = result.json()['result']['count']
  798. count_space = ' '
  799. logger.info('Received {count}{count_space}{}'.format(result.json()['result']['name'], count=count, count_space=count_space))
  800. if 'needs_inventory_refresh' in result.json():
  801. if result.json()['needs_inventory_refresh']:
  802. self.get_inventory()
  803. self.get_area()
  804. self.get_monsters()
  805. self.get_shops()
  806. def get_inventory(self, initial=False):
  807. logger = logging.getLogger('ornauto.GrindAtHome.get_inventory')
  808. if initial:
  809. logger_initial = logging.getLogger('ornauto.GrindAtHome.firstRequests')
  810. logger_initial.debug('/inventory/')
  811. else:
  812. logger.debug('/inventory/')
  813. try:
  814. result_inventory = self.account.get('/inventory/').json()
  815. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  816. pass
  817. self.inventory = result_inventory
  818. def use_torch(self):
  819. logger = logging.getLogger('ornauto.GrindAtHome.use_torch')
  820. time.sleep(random.uniform(500, 1500) / 1000)
  821. logger.debug('/me/')
  822. try:
  823. result = self.account.post(
  824. '/me/',
  825. data={
  826. 'type_id': '0217c711-ffac-4447-a356-bd2dc2778b53', # torch id
  827. 'action': 'item'
  828. }
  829. )
  830. logger.info('Used ' + Fore.YELLOW + 'torch!' + Style.RESET_ALL)
  831. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  832. pass
  833. self.get_me()
  834. self.get_inventory()
  835. def shop_for_potions(self, hp=False, mp=False):
  836. logger = logging.getLogger('ornauto.GrindAtHome.shop_for_potions')
  837. shop_use = None
  838. for shop in self.shops['result']:
  839. if shop['name'] == "pseudoscope's Shop":
  840. shop_use = shop
  841. break
  842. elif ' Shop' in shop['name']:
  843. shop_use = shop
  844. assert shop_use
  845. time.sleep(random.uniform(500, 1500) / 1000)
  846. logger.debug('/shopkeeper/')
  847. try:
  848. result = self.account.get('/shopkeeper/', params={'uuid': shop_use['uuid']})
  849. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  850. pass
  851. if result and result.json()['success']:
  852. for item in result.json()['result']['inventory']:
  853. if item['name'] == 'Small Health Potion':
  854. uuid_hp = item['id']
  855. if item['name'] == 'Small Mana Potion':
  856. uuid_mp = item['id']
  857. if hp:
  858. try:
  859. result = self.account.post(
  860. '/shopkeeper/',
  861. data={
  862. 'item_id': uuid_hp,
  863. 'action': 'buy',
  864. 'quantity': 1000,
  865. 'uuid': shop_use['uuid']
  866. }
  867. )
  868. logger.info('Bought 1000 ' + Fore.RED + 'Small Health Potions' + Style.RESET_ALL)
  869. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  870. pass
  871. if mp:
  872. try:
  873. result = self.account.post(
  874. '/shopkeeper/',
  875. data={
  876. 'item_id': uuid_mp,
  877. 'action': 'buy',
  878. 'quantity': 1000,
  879. 'uuid': shop_use['uuid']
  880. }
  881. )
  882. logger.info('Bought 1000 ' + Fore.BLUE + 'Small Mana Potions' + Style.RESET_ALL)
  883. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  884. pass
  885. self.get_me()
  886. self.get_inventory()
  887. def arena_check(self):
  888. logger = logging.getLogger('ornauto.GrindAtHome.arena_check')
  889. if (time.time() - self.arena_time > random.uniform(480, 720)):
  890. self.arena_do = True
  891. def arena_battle(self):
  892. logger = logging.getLogger('ornauto.GrindAtHome.arena_battle')
  893. # rt_mon = RepeatedTimer(30, self.get_monsters)
  894. # rt_shop = RepeatedTimer(30, self.get_shops)
  895. # rt_notif = RepeatedTimer(60, self.get_notifications)
  896. # rt_frnd = RepeatedTimer(120, self.get_friends)
  897. # rt_area = RepeatedTimer(60, self.get_area, 'small')
  898. logger.debug('/battles/arena/')
  899. result = None
  900. try:
  901. result = self.account.post('/battles/arena/', data={'state': 1}).json()
  902. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  903. pass
  904. tokens = None
  905. if result:
  906. if result['success']:
  907. tokens = result['result']['tokens']
  908. rematch = False
  909. if tokens > 125:
  910. count = 0
  911. while tokens > 100:
  912. count += 1
  913. time.sleep(random.uniform(1000, 3000) / 1000)
  914. logger.debug('/battles/arena/')
  915. try:
  916. result = self.account.post('/battles/arena/', data={'ranked': True}).json()
  917. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  918. pass
  919. if result:
  920. if result['success']:
  921. uuid_ranked = result['result']['uuid']
  922. result_get = None
  923. logger.debug('/battles/arena/')
  924. try:
  925. result_get = self.account.get('/battles/arena/', params={'uuid': uuid_ranked}).json()
  926. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  927. pass
  928. if not rematch:
  929. logger.debug('/battles/arena/')
  930. try:
  931. result = self.account.post('/battles/arena/', data={'state': 1}).json()
  932. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  933. pass
  934. if result:
  935. if result['success']:
  936. time.sleep(random.uniform(100, 3000) / 1000)
  937. logger.info(' ({count}) Arena fight against {}'.format(result_get['result']['opponent']['name'], count=count))
  938. state_id = ''
  939. has_won = False
  940. has_lost = False
  941. while (not has_won and not has_lost):
  942. time.sleep(random.uniform(1000, 3000) / 1000)
  943. if 'state_id' in result:
  944. state_id = result['state_id']
  945. logger.debug('/battles/arena/turn/')
  946. try:
  947. result = self.account.post(
  948. '/battles/arena/turn/',
  949. data={
  950. 'uuid': uuid_ranked,
  951. 'type': 'ability',
  952. 'state_id': state_id
  953. }
  954. ).json()
  955. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  956. pass
  957. if result and result['success']:
  958. has_won = result['result']['won']
  959. has_lost = result['result']['lost']
  960. if has_won:
  961. logger.info('{}Won{} arena battle!'.format(Fore.GREEN, Style.RESET_ALL))
  962. rematch = True
  963. tokens -= 1
  964. if has_lost:
  965. logger.info('{}Lost{} arena battle.'.format(Fore.RED, Style.RESET_ALL))
  966. rematch = True
  967. tokens -= 1
  968. self.arena_time = time.time()
  969. self.arena_do = False
  970. def get_clan(self):
  971. logger = logging.getLogger('ornauto.GrindAtHome.get_clan')
  972. logger.debug('/clans/')
  973. try:
  974. result = self.account.get('/clans/', params={'uuid': self.clan_uuid}).json()
  975. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  976. pass
  977. if result and 'success' in result and result['success']:
  978. self.clan = result
  979. def kingdom_raids_battle(self):
  980. logger = logging.getLogger('ornauto.GrindAtHome.kingdom_raids_battle')
  981. self.get_clan()
  982. time.sleep(random.uniform(100, 3000) / 1000)
  983. uuid_raid = None
  984. for raid in self.clan['result']['raids']:
  985. goahead = True
  986. if 'summary' in raid['raid']:
  987. for item in raid['raid']['summary']:
  988. if raid['raid']['summary'][item]['player']['username'] == self.username and raid['raid']['summary'][item]['damage'] > 0:
  989. goahead = False
  990. if goahead:
  991. if raid['raid']['active'] and raid['raid']['battleable'] and (raid['raid']['time_left'] is None or raid['raid']['time_left'] <= 1):
  992. uuid_raid = raid['raid']['uuid']
  993. name = raid['name']
  994. level = raid['level']
  995. berserk = raid['is_berserk']
  996. berserk_text = ''
  997. berserk_color = Fore.RED + Style.BRIGHT
  998. color_e = Style.RESET_ALL
  999. space_1 = ''
  1000. if berserk:
  1001. berserk_text = 'Berserk'
  1002. berserk_color = Fore.RED + Style.BRIGHT
  1003. space_1 = ' '
  1004. logger.info('Fighting Kingdom Raid - {color_b}{berserk}{color_e}{space_1}{} ({})'.format(name, level, berserk=berserk_text, space_1=space_1, color_b=berserk_color, color_e=Style.RESET_ALL))
  1005. logger.debug('/battles/raid/')
  1006. try:
  1007. result_1 = self.account.post('/battles/raid/', data={'uuid': uuid_raid}).json()
  1008. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1009. pass
  1010. uuid_raid_new = None
  1011. if result_1:
  1012. if 'success' in result_1 and result_1['success']:
  1013. uuid_raid_new = result_1['result']['uuid']
  1014. assert uuid_raid_new
  1015. logger.debug('/battles/raid/')
  1016. try:
  1017. result = self.account.get('/battles/raid/', params={'uuid': uuid_raid_new}).json()
  1018. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1019. pass
  1020. uuid_raid_turn = result['result']['uuid']
  1021. if result and 'success' in result and result['success']:
  1022. has_won = False
  1023. has_lost = False
  1024. state_id = ''
  1025. while (not has_won and not has_lost):
  1026. if 'total_damage' in result and result['total_damage'] > 0:
  1027. logger.info('Inflicted {} damage.'.format(result['total_damage']))
  1028. self.get_me()
  1029. self.get_clan()
  1030. break
  1031. time.sleep(random.uniform(1000, 3000) / 1000)
  1032. if 'state_id' in result:
  1033. state_id = result['state_id']
  1034. logger.debug('/battles/raid/turn/')
  1035. try:
  1036. result = self.account.post(
  1037. '/battles/raid/turn/',
  1038. data={
  1039. 'uuid': uuid_raid_turn,
  1040. 'type': 'ability',
  1041. 'state_id': state_id,
  1042. }
  1043. ).json()
  1044. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1045. pass
  1046. if result and result['success']:
  1047. has_won = result['result']['won']
  1048. has_lost = result['result']['lost']
  1049. if has_won:
  1050. logger.info('{}Won{} Kingdom Raid battle!'.format(Fore.GREEN, Style.RESET_ALL))
  1051. if has_lost:
  1052. logger.info('{}Lost{} Kingdom Raid battle.'.format(Fore.RED, Style.RESET_ALL))
  1053. if has_won or has_lost:
  1054. logger.info('Inflicted {} damage.'.format(result['total_damage']))
  1055. self.get_me()
  1056. self.get_clan()
  1057. self.kingdom_raids_time = time.time()
  1058. self.kingdom_raids_do = False
  1059. def kingdom_raids_check(self):
  1060. logger = logging.getLogger('ornauto.GrindAtHome.kingdom_raids_check')
  1061. if (time.time() - self.kingdom_raids_time > random.uniform(480, 720)):
  1062. self.kingdom_raids_do = True
  1063. def blacksmith_check(self):
  1064. logger = logging.getLogger('ornauto.GrindAtHome.blacksmith_check')
  1065. if (time.time() - self.blacksmith_time > random.uniform(600, 720)):
  1066. self.blacksmith_do = True
  1067. def blacksmith_upgrade(self):
  1068. logger = logging.getLogger('ornauto.GrindAtHome.blacksmith_upgrade')
  1069. result_1 = None
  1070. logger.debug('/blacksmith/')
  1071. try:
  1072. result_1 = self.account.get('/blacksmith/').json()
  1073. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1074. pass
  1075. upgrade_these = []
  1076. if result_1 and 'success' in result_1 and result_1['success']:
  1077. if 'finished' in result_1:
  1078. for item in result_1['finished']:
  1079. if item['base_name'] not in ['Adamantine Helmet']:
  1080. upgrade_these.append(item['uuid'])
  1081. logger.info('Finished upgrading {}'.format(item['name']))
  1082. if len(upgrade_these) > 0:
  1083. for thing in upgrade_these:
  1084. time.sleep(random.uniform(1000, 3000) / 1000)
  1085. result_2 = None
  1086. logger.debug('/blacksmith/')
  1087. try:
  1088. result_2 = self.account.post('/blacksmith/', data={'uuid': thing, 'action': 'upgrade'}).json()
  1089. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1090. pass
  1091. if result_2 and 'success' in result_2 and result_2['success']:
  1092. logger.info('Upgrading uuid {}'.format(thing))
  1093. self.blacksmith_time = time.time()
  1094. self.blacksmith_do = False
  1095. def kingdom_war_check(self):
  1096. logger = logging.getLogger('ornauto.GrindAtHome.kingdom_war_check')
  1097. if (time.time() - self.kingdom_war_time > random.uniform(1600, 2000)):
  1098. self.kingdom_war_do = True
  1099. def kingdom_war_battle(self):
  1100. logger = logging.getLogger('ornauto.GrindAtHome.kingdom_war_battle')
  1101. self.get_clan()
  1102. time.sleep(random.uniform(100, 3000) / 1000)
  1103. uuid_war = None
  1104. if self.clan['result']['war']['active'] and self.clan['result']['war']['can_battle'] and 'battle' in self.clan['result']['war'] and self.clan['result']['war']['battle']['available']:
  1105. uuid_war = self.clan['result']['war']['battle']['uuid']
  1106. name = self.clan['result']['war']['battle']['opponent']['username']
  1107. job = self.clan['result']['war']['battle']['opponent']['job']
  1108. logger.info('Fighting Kingdom War - {} ({})'.format(name, job))
  1109. logger.debug('/battles/clan/')
  1110. try:
  1111. result_1 = self.account.post('/battles/clan/', data={'uuid': uuid_raid}).json()
  1112. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1113. pass
  1114. uuid_war_new = None
  1115. if result_1:
  1116. if 'success' in result_1 and result_1['success']:
  1117. uuid_war_new = result_1['result']['uuid']
  1118. assert uuid_war_new
  1119. logger.debug('/battles/clan/')
  1120. try:
  1121. result = self.account.get('/battles/clan/', params={'uuid': uuid_war_new}).json()
  1122. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1123. pass
  1124. uuid_war_turn = result['result']['uuid']
  1125. if result and 'success' in result and result['success']:
  1126. has_won = False
  1127. has_lost = False
  1128. state_id = ''
  1129. while (not has_won and not has_lost):
  1130. time.sleep(random.uniform(1000, 3000) / 1000)
  1131. if 'state_id' in result:
  1132. state_id = result['state_id']
  1133. logger.debug('/battles/clan/turn/')
  1134. try:
  1135. result = self.account.post(
  1136. '/battles/clan/turn/',
  1137. data={
  1138. 'uuid': uuid_war_turn,
  1139. 'type': 'ability',
  1140. 'state_id': state_id,
  1141. }
  1142. ).json()
  1143. except (httpx.UnsupportedProtocol, httpx.ReadError, httpx.RemoteProtocolError) as e:
  1144. pass
  1145. if result and result['success']:
  1146. has_won = result['result']['won']
  1147. has_lost = result['result']['lost']
  1148. if has_won:
  1149. logger.info('{}Won{} Kingdom War battle!'.format(Fore.GREEN, Style.RESET_ALL))
  1150. if has_lost:
  1151. logger.info('{}Lost{} Kingdom War battle.'.format(Fore.RED, Style.RESET_ALL))
  1152. if has_won or has_lost:
  1153. self.get_me()
  1154. self.get_clan()
  1155. self.kingdom_war_time = time.time()
  1156. self.kingdom_war_do = False