From 1c08511997fccba42e2e0652ffad19ce028e837a Mon Sep 17 00:00:00 2001 From: Matt Main_PC Date: Mon, 25 Dec 2023 02:16:36 -0500 Subject: [PATCH] adding bannerbox collects stat, adjusting some gui boxes --- src/pyclashbot/bot/bannerbox.py | 126 +++++++++++++++-------------- src/pyclashbot/interface/layout.py | 7 +- src/pyclashbot/interface/stats.py | 6 ++ src/pyclashbot/utils/logger.py | 44 ++++++---- 4 files changed, 104 insertions(+), 79 deletions(-) diff --git a/src/pyclashbot/bot/bannerbox.py b/src/pyclashbot/bot/bannerbox.py index 304e6347e..0460153cc 100644 --- a/src/pyclashbot/bot/bannerbox.py +++ b/src/pyclashbot/bot/bannerbox.py @@ -11,76 +11,25 @@ def collect_bannerbox_rewards_state(vm_index: int, logger: Logger, next_state: str): - if collect_bannerbox_rewards(vm_index, logger): - return next_state - return "restart" - - -def check_for_collected_all_bannerbox_rewards_icon(vm_index): - iar = numpy.asarray(screenshot(vm_index)) - - pixels = [ - iar[570][288], - iar[587][353], - iar[589][289], - iar[563][296], - iar[576][282], - ] - colors = [ - [36, 36, 36], - [194, 189, 195], - [190, 190, 190], - [201, 202, 207], - [252, 252, 252], - ] - - for i, p in enumerate(pixels): - if not pixel_is_equal(colors[i], p, tol=10): - return False - return True - - -def check_if_bannerbox_icon_exists_on_clashmain(vm_index): - iar = numpy.asarray(screenshot(vm_index)) - pixels = [ - iar[181][350], - iar[190][334], - iar[195][345], - iar[220][364], - iar[229][378], - iar[240][400], - ] - - colors = [ - [150, 113, 33], - [178, 133, 43], - [169, 126, 37], - [150, 102, 28], - [143, 104, 31], - [128, 89, 22], - ] - - for i, p in enumerate(pixels): - # print(p) - if not pixel_is_equal(p, colors[i], tol=35): - return True - - return False - - -def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool: - logger.change_status("Collecting bannerbox rewards") - # if not in clash main, return false if not check_if_on_clash_main_menu(vm_index): logger.change_status("Not in clash main menu") return False + #if bannerbox rewards are done, return True if not check_if_bannerbox_icon_exists_on_clashmain(vm_index): - logger.change_status("Account doesn't have bannerbox icon") + logger.change_status("Account doesn't have bannerbox icon. Skipping bannerbox rewards") return True - # click bannerbox button on clash main + if collect_bannerbox_rewards(vm_index, logger): + return next_state + return "restart" + + +def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool: + logger.change_status("Collecting bannerbox rewards") + + # open bannerbox button on clash main click( vm_index, BANNERBOX_ICON_ON_CLASH_MAIN_PAGE[0], @@ -128,6 +77,7 @@ def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool: SECOND_100_TICKETS_PURCHASE_BUTTON[0], SECOND_100_TICKETS_PURCHASE_BUTTON[1], ) + logger.add_bannerbox_collect() # click deadspace until back on clash main logger.change_status("Skipping through bannerbox rewards...") @@ -145,6 +95,58 @@ def collect_bannerbox_rewards(vm_index, logger: Logger) -> bool: return True +def check_for_collected_all_bannerbox_rewards_icon(vm_index): + iar = numpy.asarray(screenshot(vm_index)) + + pixels = [ + iar[570][288], + iar[587][353], + iar[589][289], + iar[563][296], + iar[576][282], + ] + colors = [ + [36, 36, 36], + [194, 189, 195], + [190, 190, 190], + [201, 202, 207], + [252, 252, 252], + ] + + for i, p in enumerate(pixels): + if not pixel_is_equal(colors[i], p, tol=10): + return False + return True + + +def check_if_bannerbox_icon_exists_on_clashmain(vm_index): + iar = numpy.asarray(screenshot(vm_index)) + pixels = [ + iar[181][350], + iar[190][334], + iar[195][345], + iar[220][364], + iar[229][378], + iar[240][400], + ] + + colors = [ + [150, 113, 33], + [178, 133, 43], + [169, 126, 37], + [150, 102, 28], + [143, 104, 31], + [128, 89, 22], + ] + + for i, p in enumerate(pixels): + # print(p) + if not pixel_is_equal(p, colors[i], tol=35): + return True + + return False + + def check_if_can_purchase_100_tickets_bannerbox(vm_index): iar = screenshot(vm_index) diff --git a/src/pyclashbot/interface/layout.py b/src/pyclashbot/interface/layout.py index 2ae095c0e..4f358aeb5 100644 --- a/src/pyclashbot/interface/layout.py +++ b/src/pyclashbot/interface/layout.py @@ -135,6 +135,8 @@ def get_random_donate_image_path(): text_color="blue", size=(5, 1), ), + ], + [ sg.Text("Account Order"), sg.Text( "-", @@ -146,7 +148,7 @@ def get_random_donate_image_path(): ], ], title="Account Switching", - expand_x=True, + # expand_x=True, ), sg.Frame( layout=[ @@ -162,6 +164,7 @@ def get_random_donate_image_path(): expand_x=True, expand_y=True, ), + sg.Frame(layout=bot_stats, title="Bot Stats", expand_x=True, expand_y = True), ] ] @@ -182,7 +185,7 @@ def get_random_donate_image_path(): expand_x=True, ) ], - [sg.Frame(layout=bot_stats, title="Bot Stats", expand_x=True)], + ], expand_x=True, expand_y=True, diff --git a/src/pyclashbot/interface/stats.py b/src/pyclashbot/interface/stats.py index aa04dfc4d..4a0b44c3d 100644 --- a/src/pyclashbot/interface/stats.py +++ b/src/pyclashbot/interface/stats.py @@ -38,6 +38,9 @@ def stat_box(stat_name: str, size=(5, 1)) -> sg.Text: [ sg.Text("Card Mastery Rewards: "), ], + [ + sg.Text("Bannerbox Collects: "), + ], [ sg.Text("Cards Upgraded: "), ], @@ -69,6 +72,9 @@ def stat_box(stat_name: str, size=(5, 1)) -> sg.Text: [ stat_box("card_mastery_reward_collections"), ], + [ + stat_box("bannerbox_collects"), + ], [ stat_box("upgrades"), ], diff --git a/src/pyclashbot/utils/logger.py b/src/pyclashbot/utils/logger.py index a13a957d6..b1e11365a 100644 --- a/src/pyclashbot/utils/logger.py +++ b/src/pyclashbot/utils/logger.py @@ -103,29 +103,36 @@ def __init__( self.winrate: str = "00.0%" # job stats - self.requests = 0 - self.shop_buys = 0 - self.daily_reward_attempts = 0 - self.donates = 0 self.battlepass_collects = 0 - self.daily_rewards = 0 - self.request_attempts = 0 - self.donate_attempts = 0 - self.deck_randomize_attempts = 0 - self.chests_unlocked = 0 + self.battlepass_collect_attempts = 0 + self.bannerbox_collects = 0 self.cards_upgraded = 0 self.card_upgrade_attempts = 0 self.card_mastery_reward_collections = 0 - self.shop_offer_collections = 0 - self.shop_buy_attempts = 0 - self.battlepass_collect_attempts = 0 self.chest_unlock_attempts = 0 self.card_mastery_reward_collection_attempts = 0 + self.chests_unlocked = 0 + self.daily_rewards = 0 + self.donates = 0 + self.daily_reward_attempts = 0 + self.donate_attempts = 0 + self.deck_randomize_attempts = 0 + self.request_attempts = 0 + self.requests = 0 + self.shop_buys = 0 + self.shop_offer_collections = 0 + self.shop_buy_attempts = 0 self.war_attempts = 0 - self.switch_account_attempts = 0 - self.account_switches = 0 - self.current_account = "-" + + + + + #account stuff self.account_order = '-' + self.current_account = "-" + self.account_switches = 0 + self.switch_account_attempts = 0 + # restart stats self.auto_restarts = 0 @@ -171,6 +178,7 @@ def _update_stats(self) -> None: "card_mastery_reward_collections": self.card_mastery_reward_collections, "shop_offer_collections": self.shop_offer_collections, "battlepass_collects": self.battlepass_collects, + 'bannerbox_collects':self.bannerbox_collects, "daily_rewards": self.daily_rewards, "current_status": self.current_status, "winrate": self.winrate, @@ -420,6 +428,12 @@ def add_battlepass_collect_attempt(self): """increments logger's battlepass_collect_attempts by 1""" self.battlepass_collect_attempts += 1 + def add_bannerbox_collect(self): + """increments logger's bannerbox_collects by 1""" + self.bannerbox_collects += 1 + + + def add_daily_reward_attempt(self): """increments logger's free_offer_collection_attempts by 1""" self.daily_reward_attempts += 1