Skip to content

Commit

Permalink
many small patches
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmiglio committed Mar 10, 2024
1 parent e423ce3 commit 16bcfe5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/pyclashbot/bot/bannerbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool:
logger.change_status("Checking bannerbox rewards availability")

# Check if the bannerbox icon is yellow (i.e., if there are enough tickets)
if not check_if_bannerbox_icon_have_a_star(vm_index):
logger.change_status("Not enough tickets for bannerbox rewards.")
return True # There are no tickets, but this is not an error
# if not check_if_bannerbox_icon_have_a_star(vm_index):
# logger.change_status("Not enough tickets for bannerbox rewards.")
# return True # There are no tickets, but this is not an error

logger.change_status("Opening bannerbox rewards...")

Expand Down
14 changes: 10 additions & 4 deletions src/pyclashbot/bot/buy_shop_offers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

from pyclashbot.utils.logger import Logger

SHOP_BUY_TIMEOUT = 35

def buy_shop_offers_state(
vm_index: int,
Expand Down Expand Up @@ -53,6 +54,8 @@ def buy_shop_offers_state(
logger.change_status("Failed to buy offers. Returning restart")
return "restart"

time.sleep(3)

# if not on clash main, return False
if check_if_on_clash_main_menu(vm_index) is not True:
logger.change_status("Not on clash main after buying offers. Returning restart")
Expand All @@ -78,10 +81,10 @@ def buy_shop_offers_main(
purchase_total = 0

start_time = time.time()
timeout = 25
done_buying = False
logger.change_status("Starting to buy offers")
while 1:
if time.time() - start_time > timeout:
while 1 and done_buying is False:
if time.time() - start_time > SHOP_BUY_TIMEOUT:
break

# scroll a little
Expand All @@ -95,7 +98,7 @@ def buy_shop_offers_main(
buy_offers_from_this_shop_page(
vm_index, logger, gold_buy_toggle, free_offers_toggle
)
is True
is True and done_buying is False
):
purchase_total += 1
logger.change_status("Bought an offer from the shop!")
Expand All @@ -105,16 +108,19 @@ def buy_shop_offers_main(
# if only free offers are toggled, AND purchase total is 1, then it's done
if free_offers_toggle and not gold_buy_toggle and purchase_total == 1:
print("only free offers toggles and purchase total is 1, breaking")
done_buying=True
break

# if both modes are toggled, and total is 6, break
if gold_buy_toggle and free_offers_toggle and purchase_total == 6:
print("both modes toggled and purchase total is 6, breaking")
done_buying=True
break

# if only gold offers are toggled, and purchase total is 6, break
if gold_buy_toggle and not free_offers_toggle and purchase_total == 5:
print("only gold offers toggled and purchase total is 6, breaking")
done_buying=True
break

logger.change_status("Done buying offers. Returning to clash main")
Expand Down
7 changes: 5 additions & 2 deletions src/pyclashbot/bot/card_mastery_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def collect_card_mastery_rewards(vm_index, logger: Logger) -> bool:
# get to clash main
logger.change_status("Returning to clash main menu")
click(vm_index, 243, 600)
time.sleep(3)
time.sleep(5)

# if not on clash main, return False
if check_if_on_clash_main_menu(vm_index) is not True:
Expand Down Expand Up @@ -117,4 +117,7 @@ def card_mastery_rewards_exist(vm_index):


if __name__ == "__main__":
pass
vm_index=12
logger=Logger()

collect_card_mastery_rewards(vm_index, logger)
2 changes: 1 addition & 1 deletion src/pyclashbot/bot/daily_challenge_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def check_which_rewards_are_available(vm_index, logger):
rewards = check_rewards_menu_pixels(vm_index)

# click deadspace a bunch
click(vm_index, 15, 290, clicks=3, interval=0.33)
click(vm_index, 15, 400, clicks=3, interval=0.33)
time.sleep(2)

# if not on clash main, return False
Expand Down
5 changes: 3 additions & 2 deletions src/pyclashbot/bot/do_fight_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def mag_dump(vm_index, logger):
]

logger.log("Mag dumping...")
for index in range(8):
for index in range(3):
print(f"mag dump play {index}")
card_coord = random.choice(card_coords)
play_coord = (random.randint(101, 440), random.randint(50, 526))
Expand Down Expand Up @@ -686,7 +686,8 @@ def get_to_main_after_fight(vm_index, logger):
clicked_ok_or_exit = True
continue
else:
print("Already clicked OK or EXIT so not checking for those buttons again")
# print("Already clicked OK or EXIT so not checking for those buttons again")
pass

# if on events page, click clash main button
if check_for_events_page(vm_index):
Expand Down
10 changes: 10 additions & 0 deletions src/pyclashbot/bot/donate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Literal
from pyclashbot.bot.nav import (
check_if_on_clash_main_menu,
check_if_on_profile_page,
get_to_clan_tab_from_clash_main,
handle_trophy_reward_menu,
check_for_trophy_reward_menu,
Expand Down Expand Up @@ -37,6 +38,15 @@ def donate_cards_state(vm_index, logger: Logger, next_state):
logger.add_donate_attempt()

donate_start_time = time.time()

#if on profile page for whatever reason, close it
if check_if_on_profile_page(vm_index):
#click deadspace to leave profile page
click(vm_index, 15, 300)
time.sleep(2)



# if not on clash main, reutrn False
if check_if_on_clash_main_menu(vm_index) is not True:
logger.log("Not on clash main for donate state. Returning False")
Expand Down
4 changes: 3 additions & 1 deletion src/pyclashbot/bot/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def wait_for_2v2_battle_start(vm_index, logger: Logger) -> Literal["restart", "g
if random.randint(0, 2) == 1:
click(vm_index=vm_index, x_coord=20, y_coord=200)

time.sleep(1)

return False


Expand Down Expand Up @@ -1199,7 +1201,7 @@ def handle_clash_main_tab_notifications(

print('Trying to get to events page...')
click(vm_index, 408, 600)
time.sleep(1.77)
time.sleep(1)

print("On events page")

Expand Down
1 change: 1 addition & 0 deletions src/pyclashbot/bot/open_chests_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def open_chest(vm_index, logger: Logger, chest_index) -> Literal["restart", "goo
):
break

click(vm_index, CLASH_MAIN_DEADSPACE_COORD[0], CLASH_MAIN_DEADSPACE_COORD[1])
chests_opened = logger.get_chests_opened()
logger.log(f"Opened {chests_opened - prev_chests_opened} chests")
return "good"
Expand Down
57 changes: 53 additions & 4 deletions src/pyclashbot/bot/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,57 @@ def state_tree(


if __name__ == "__main__":
vm_index = 12
logger=Logger()
vm_index=12
next_state='next state'
# request_state(vm_index, logger, next_state)
donate_cards_state(vm_index, logger, next_state)
state='account_switch'
job_list= {
# job toggles
"open_battlepass_user_toggle": False,
"open_chests_user_toggle": False,
"request_user_toggle": False,
"donate_toggle": False,
"card_mastery_user_toggle": False,
"memu_attach_mode_toggle": False,
"free_offer_user_toggle": False,
"gold_offer_user_toggle": False,
"1v1_battle_user_toggle": False,
"2v2_battle_user_toggle": True,
"upgrade_user_toggle": False,
"war_user_toggle": False,
"random_decks_user_toggle": False,
"open_bannerbox_user_toggle": True,
"daily_rewards_user_toggle": False,
"random_plays_user_toggle": False,
"skip_fight_if_full_chests_user_toggle": False,
"battlepass_collect_user_toggle": False,
"disable_win_track_toggle": False,
"level_up_chest_user_toggle": True,

# job increments
"card_upgrade_increment_user_input": 1,
"shop_buy_increment_user_input": 1,
"request_increment_user_input": 1,
"donate_increment_user_input": 1,
"daily_reward_increment_user_input": 1,
"card_mastery_collect_increment_user_input": 1,
"open_chests_increment_user_input": 1,
"deck_randomization_increment_user_input": 1,
"war_attack_increment_user_input": 1,
"battlepass_collect_increment_user_input": 1,
"level_up_chest_increment_user_input": 1,

# account switching input info
"account_switching_increment_user_input": 1,
"account_switching_toggle": False,
"account_switching_slider": 1,
"next_account": 0,
"random_account_switch_list": [0],
}

while 1:
state = state_tree(
vm_index,
logger,
state,
job_list,
)
2 changes: 2 additions & 0 deletions src/pyclashbot/bot/war_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def do_war_battle(vm_index, logger) -> Literal["restart", "good"]:
# click a random play coord
random_play_coord = (random.randint(63, 205), random.randint(55, 455))
click(vm_index, random_play_coord[0], random_play_coord[1])
time.sleep(6)

logger.change_status(status="Done with this war fight")
return "good"

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 @@ -731,16 +731,16 @@ def check_if_can_request(self, increment) -> bool:
def check_if_can_donate(self, increment) -> bool:
increment = int(increment)
if increment <= 1:
self.log(f"Increment is {increment} so can always Request")
self.log(f"Increment is {increment} so can always donate")
return True

# count requests
# count donates
donate_attempts = self.donate_attempts

# count games
games_played = self._1v1_fights + self._2v2_fights + self.war_fights

# if request_attempts is zero return true
# if donate_attempts is zero return true
if donate_attempts == 0:
self.log(
f"Can donate bc attempts is {donate_attempts} and games played is {games_played}"
Expand All @@ -754,7 +754,7 @@ def check_if_can_donate(self, increment) -> bool:
)
return True

# if games_played / increment > request_attempts
# if games_played / increment > donate_attempts
if games_played / increment >= donate_attempts:
self.change_status(
f"Can donate. attempts = {donate_attempts} & games played = {games_played}"
Expand Down

0 comments on commit 16bcfe5

Please sign in to comment.