Skip to content

Commit

Permalink
Added auto (grind) attack function to barbarians (#285)
Browse files Browse the repository at this point in the history
* feat(activateMiracle): added activation level export

- Refactor `obtainMiraclesAvailable` to now include activation levels via the `wonderActivationLevel` field.
- Improvement enables better management of auto grind for barbarians based on activation levels.

* feat(autoBarbarians): added `autoBarbarians` to the options menu

* fix(attackBarbarians): Fixed issue with acquiring unit speed due to translation

* feat(attackBarbarians): Added unit name acquisition in  function

* feat(autoBarbarians)!: auto Barbarian function

- Added presets to make barbarian grinding easier automatically;
- Added usage warnings for users to better understand;
- Added Hephaestus availability check to easily switch between presets;
- Added auto-recognition of floating city usage through the preset;
- Added visualization for users of the troops required by the presets they are using;

* feat(autoBarbarians): Added attack and looting action functions

- Adjusted data modeling of the `DEFAULT_SCHEMATICS` object for greater efficiency;
- Applied syntax and dialog corrections;
- Removed extra comments previously added as information for development
- Fixed error with `float_city` variable being within a very specific scope;
- Added auto-attack operation loop:
- Added `get_units_scattered` function to manage the amount of scattered troops;

* fix(autoBarbarians): Fixed translation and data modeling

- Added a development feature-flag for hephaestus and custom schematic selection;
- Fixed translation errors that presented syntax in pt-BR;
- Removed unnecessary inputs added in development;

* fix(autoBarbarians): Formatted by Black Fomatter

* fix(autoBarbarians): dedicated function for background and cleanup

- dedicated `do_it` function for background;
- renamed the attack function from `do_it` to `do_attack`;
- removed some unnecessary comments;
- translated some writings that are in pt-BR;

* fix(autoBarbarians): Fixed problem where attacks would not follow up if troops took longer than expected to return

* feat(attackBarbarians): Added option in  to filter only abortables as parameter

* fix(autoBarbarians): Validation to wait for the troops to return completely;

- Added the `get_current_looting` function to check if the barbarians' city is still being looted, and if it is, wait for the units to return;
- Removed redundancy in the function call to start looting;

* remove gettext

---------

Co-authored-by: ikagod <[email protected]>
  • Loading branch information
RyanPrado and ikagod authored Jan 8, 2025
1 parent f992305 commit eaa35d4
Show file tree
Hide file tree
Showing 4 changed files with 1,038 additions and 21 deletions.
19 changes: 17 additions & 2 deletions ikabot/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ikabot.function.alertAttacks import alertAttacks
from ikabot.function.alertLowWine import alertLowWine
from ikabot.function.attackBarbarians import attackBarbarians
from ikabot.function.autoBarbarians import autoBarbarians
from ikabot.function.autoPirate import autoPirate
from ikabot.function.buyResources import buyResources
from ikabot.function.checkForUpdate import checkForUpdate
Expand Down Expand Up @@ -47,6 +48,7 @@
from ikabot.helpers.process import updateProcessList
from ikabot.web.session import *


def menu(session, checkUpdate=True):
"""
Parameters
Expand Down Expand Up @@ -131,7 +133,8 @@ def menu(session, checkUpdate=True):
16: webServer,
17: autoPirate,
18: investigate,
19: attackBarbarians,
1901: attackBarbarians,
1902: autoBarbarians,
2001: searchForIslandSpaces,
2002: dumpWorld,
2101: proxyConf,
Expand Down Expand Up @@ -163,7 +166,7 @@ def menu(session, checkUpdate=True):
print("(16) Ikabot Web Server")
print("(17) Auto-Pirate")
print("(18) Investigate")
print("(19) Attack barbarians")
print("(19) Attack / Grind barbarians")
print("(20) Dump / Monitor world")
print("(21) Options / Settings")
total_options = len(menu_actions) + 1
Expand Down Expand Up @@ -212,6 +215,18 @@ def menu(session, checkUpdate=True):
if selected > 0:
selected += 900

if selected == 19:
banner()
print("(0) Back")
print("(1) Simple Attack")
print("(2) Auto Grind")
selected = read(min=0, max=2, digit=True)
if selected == 0:
menu(session)
return
if selected > 0:
selected += 1900

if selected == 12:
banner()
print("(0) Back")
Expand Down
12 changes: 8 additions & 4 deletions ikabot/function/activateMiracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ def obtainMiraclesAvailable(session):
}
data = session.post(params=params)
data = json.loads(data, strict=False)
html = data[1][1][1]
match = re.search(r'<div id="wonderLevelDisplay"[^>]*>\\n\s*(\d+)\s*</div>', html)
level = 0
if match:
level = int(match.group(1))

data = data[2][1]
available = data["js_WonderViewButton"]["buttonState"] == "enabled"
if available is False:
Expand All @@ -82,6 +88,7 @@ def obtainMiraclesAvailable(session):
if island["id"] == city["islandId"]:
island["activable"] = True
island["ciudad"] = city
island["wonderActivationLevel"] = level
island["available"] = available
if available is False:
island["available_in"] = enddate - currentdate
Expand Down Expand Up @@ -268,10 +275,7 @@ def activateMiracle(session, event, stdin_fd, predetermined_input):

iterations += 1
duration = wait_time * iterations
print(

"It is not possible to calculate the time of finalization. (at least: {})".format(daysHoursMinutes(duration))
)
print("It is not possible to calculate the time of finalization. (at least: {})".format(daysHoursMinutes(duration)))
print("Proceed? [Y/n]")

try:
Expand Down
25 changes: 10 additions & 15 deletions ikabot/function/attackBarbarians.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def plan_attack(session, city, babarians_info):
if len(plan) > 0:
round_def = len(plan) + 1
attack_round["round"] = read(
msg=
"In which battle round do you want to send them? (min: 2, default: {:d}): "
.format(round_def),
msg= "In which battle round do you want to send them? (min: 2, default: {:d}): ".format(round_def),
min=2,
default=round_def,
)
Expand All @@ -233,9 +231,7 @@ def plan_attack(session, city, babarians_info):
max_ships = total_ships - sum([ar["ships"] for ar in plan])
if max_ships > 0:
attack_round["ships"] = read(
msg=
"How many ships do you want to send in this round? (min: 0, max: {:d}): "
.format(max_ships),
msg= "How many ships do you want to send in this round? (min: 0, max: {:d}): ".format(max_ships),
min=0,
max=max_ships,
)
Expand All @@ -252,11 +248,7 @@ def plan_attack(session, city, babarians_info):
resp = read(values=["y", "Y", "n", "N"], default="n")
if resp.lower() != "y":
print("")
print(

"Do you want to select the troops that will be used to collect the remaining resources? (they need to destroy the wall) [y/N]"

)
print("Do you want to select the troops that will be used to collect the remaining resources? (they need to destroy the wall) [y/N]")
resp = read(values=["y", "Y", "n", "N"], default="n")
if resp.lower() != "y":
break
Expand Down Expand Up @@ -352,12 +344,15 @@ def get_unit_data(session, city_id, unit_id):
weight = int(weight)

speed = re.search(
r'<span class="textLabel">Speed:</span>\s*(\d+)\s*<br/>',
r'<span class="textLabel">.*?</span>\s*(\d+)\s*<br/>',
html,
).group(1)
speed = int(speed)

return {"speed": speed, "weight": weight}
name = re.search(r'<div class="contentBox01h">\s*<h3 class="header">([^<]+)</h3>', html).group(1)
name = str(name)

return {"speed": speed, "weight": weight, "name": name}


def city_is_in_island(city, island):
Expand Down Expand Up @@ -502,11 +497,11 @@ def filter_loading(attacks):
return [attack for attack in attacks if attack["event"]["missionState"] == 1]


def filter_traveling(attacks):
def filter_traveling(attacks,onlyCanAbort=True):
return [
attack
for attack in attacks
if attack["event"]["missionState"] == 2 and attack["event"]["canAbort"]
if attack["event"]["missionState"] == 2 and (onlyCanAbort is False or (onlyCanAbort is True and attack["event"]["canAbort"]))
]


Expand Down
Loading

0 comments on commit eaa35d4

Please sign in to comment.