Skip to content

Commit

Permalink
Fix account switching bug (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
packetsss authored Dec 11, 2023
1 parent b896b72 commit a202c4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/pyclashbot/bot/account_switching.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def switch_accounts(vm_index, logger, account_index_to_switch_to):
# click switch SSID button
logger.change_status("Clicking switch SSID button")
click(vm_index, 221, 368)
time.sleep(8)
time.sleep(4)

# click the account index in question
account_coord = SSID_COORDS[account_index_to_switch_to]
logger.change_status("Clicking the account to switch to...")
logger.change_status(
f"Clicking {account_coord}, switch account #{account_index_to_switch_to}"
)
click(vm_index, account_coord[0], account_coord[1])
time.sleep(4)

Expand Down
13 changes: 9 additions & 4 deletions src/pyclashbot/bot/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,20 @@ def state_tree(
):
logger.log("Account switching job isn't ready. Skipping this state")
return next_state

logger.log(
f"Attempt to switch to account #{job_list['next_account']} of {job_list['account_switching_slider']}"
)

if switch_accounts(vm_index, logger, job_list["next_account"]) is False:
return "restart"

# increment next account iteration
if job_list["next_account"] < job_list["account_switching_slider"]:
job_list["next_account"] += job_list["next_account"] + 1
else:
job_list["next_account"] += 1
if job_list["next_account"] >= job_list["account_switching_slider"]:
job_list["next_account"] = 0

logger.log(f"Next account is {job_list['next_account']} / {job_list['account_switching_slider']}")

# update current account # to GUI
current_account = (
Expand Down
8 changes: 4 additions & 4 deletions src/pyclashbot/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,12 @@ def check_if_can_switch_account(self, increment):
# count games
games_played = self._1v1_fights + self._2v2_fights + self.war_fights

# if games_played or deck_randomize_attempts is zero return false
if games_played == 0 and switch_account_attempts == 0:
# if games_played or deck_randomize_attempts is zero return true
if games_played == 0:
self.log(
f"Can't switch account. {games_played} Games and {switch_account_attempts} Attempts"
f"Can switch account. {games_played} Games and {switch_account_attempts} Attempts"
)
return False
return True

# if games_played / int(increment) > deck_randomize_attempts
if games_played / int(increment) >= switch_account_attempts:
Expand Down

0 comments on commit a202c4d

Please sign in to comment.