Skip to content

Commit

Permalink
adding bannerbox collects stat, adjusting some gui boxes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmiglio committed Dec 25, 2023
1 parent 8cba76e commit 1c08511
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 79 deletions.
126 changes: 64 additions & 62 deletions src/pyclashbot/bot/bannerbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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...")
Expand All @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions src/pyclashbot/interface/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def get_random_donate_image_path():
text_color="blue",
size=(5, 1),
),
],
[
sg.Text("Account Order"),
sg.Text(
"-",
Expand All @@ -146,7 +148,7 @@ def get_random_donate_image_path():
],
],
title="Account Switching",
expand_x=True,
# expand_x=True,
),
sg.Frame(
layout=[
Expand All @@ -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),
]
]

Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions src/pyclashbot/interface/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: "),
],
Expand Down Expand Up @@ -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"),
],
Expand Down
44 changes: 29 additions & 15 deletions src/pyclashbot/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1c08511

Please sign in to comment.