Skip to content

Commit

Permalink
Add updating all workplaces related to this city
Browse files Browse the repository at this point in the history
  • Loading branch information
pecataToshev committed Dec 27, 2023
1 parent a8d7be2 commit 0da4032
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions ikabot/function/islandWorkplaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,19 @@ def extract_workplace_data(init_data, material_ind, json):
if upgrading:
end_upgrade_time = daysHoursMinutes(int(end_upgrade_time) - time_now)
data.update({
# workplace related
'material': material_ind,
'level': background_data[view + 'Level'], # resourceLevel / tradegoodLevel
'upgradeEndTime': end_upgrade_time,
'upgrading': upgrading,
'material': material_ind,
'totalWorkers': template_data['valueWorkers'],
'freeCitizens': template_data['valueCitizens'],
'goldPerHour': template_data['valueWorkCosts'],
'upgradeEndTime': end_upgrade_time,
'production': template_data['js_resource_tooltip_total_production']['text'],
'totalWorkers': template_data['valueWorkers'],
'maxWorkers': slider_data['max_value'],
'overchargedWorkers': slider_data['overcharge'],
# city related
'availableWood': json[0][1]['headerData']['currentResources']['resource'],
'freeCitizens': template_data['valueCitizens'],
'goldPerHour': template_data['valueWorkCosts'],
})

if not data['upgrading'] and json[1][0] == 'changeView':
Expand Down Expand Up @@ -281,9 +283,9 @@ def wait_for_action(workplaces_length):
return [action_id, action_id]

msg = "\nSelect target workplace between 1 and {}: ".format(workplaces_length)
workplace = read(msg=msg, min=1, max=workplaces_length, digit=True)
workplace_id = read(msg=msg, min=1, max=workplaces_length, digit=True)

return [action_id, workplace]
return [action_id, workplace_id]

def donate(workplace):
"""
Expand Down Expand Up @@ -317,7 +319,20 @@ def donate(workplace):
if donation == input_max:
donation = maximum_donation

print("\nDonating {} wood".format(donation))
execute = read(
msg="{} wood will be donated. Continue? [Y/N]".format(addThousandSeparator(donation)),
values=['y', 'Y', 'n', 'N']
)

if execute.lower() == 'n':
print("Aborting...")
return workplace

print("\nDonating {} wood to {} workplace from {}".format(
addThousandSeparator(donation),
materials_names[workplace['material']],
workplace['cityName']
))

return extract_workplace_data(
workplace,
Expand Down Expand Up @@ -433,7 +448,16 @@ def set_workers(workplace):
else:
print("Unknown action ", action)

# update all other workplaces related to this city
for ind, wp in enumerate(workplaces):
if wp['cityId'] == workplace['cityId'] and ind != workplace_ind:
wp['availableWood'] = workplace['availableWood']
wp['freeCitizens'] = workplace['freeCitizens']
wp['goldPerHour'] = workplace['goldPerHour']

# update operational workplace
workplaces[workplace_ind] = workplace

print("\nOperation is successful!")
enter()

Expand Down

0 comments on commit 0da4032

Please sign in to comment.