Skip to content

Commit

Permalink
fixing free offer collection, and card upgrading.
Browse files Browse the repository at this point in the history
disabling random decks and card mastery modes (broken since december 23 update)
  • Loading branch information
matthewmiglio committed Dec 16, 2023
1 parent a202c4d commit 307f4f9
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 196 deletions.
12 changes: 10 additions & 2 deletions src/pyclashbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from pyclashbot.utils.logger import Logger, initalize_pylogging
from pyclashbot.utils.thread import PausableThread, StoppableThread



initalize_pylogging()


Expand Down Expand Up @@ -52,13 +54,17 @@ def make_job_dictionary(values: dict[str, str | int]) -> dict[str, str | int]:
# job toggles
"open_chests_user_toggle": values["open_chests_user_toggle"],
"request_user_toggle": values["request_user_toggle"],
"card_mastery_user_toggle": values["card_mastery_user_toggle"],


# "card_mastery_user_toggle": values["card_mastery_user_toggle"],
"card_mastery_user_toggle": False,
"free_offer_user_toggle": values["free_offer_user_toggle"],
"1v1_battle_user_toggle": values["1v1_user_toggle"],
"2v2_battle_user_toggle": values["2v2_user_toggle"],
"upgrade_user_toggle": values["card_upgrade_user_toggle"],
"war_user_toggle": values["war_user_toggle"],
"random_decks_user_toggle": values["random_decks_user_toggle"],
# "random_decks_user_toggle": values["random_decks_user_toggle"],
"random_decks_user_toggle": False,
"open_bannerbox_user_toggle": values["open_bannerbox_user_toggle"],
"random_plays_user_toggle": values["random_plays_user_toggle"],
"skip_fight_if_full_chests_user_toggle": values[
Expand Down Expand Up @@ -426,3 +432,5 @@ def main_gui(start_on_run=False, settings: None | dict[str, str] = None) -> None
if __name__ == "__main__":
cli_args = arg_parser()
main_gui(start_on_run=cli_args.start)


2 changes: 1 addition & 1 deletion src/pyclashbot/bot/bannerbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ def check_if_can_purchase_100_tickets_bannerbox(vm_index):


if __name__ == "__main__":
pass
collect_bannerbox_rewards_state(11,Logger(),'next_state')
55 changes: 28 additions & 27 deletions src/pyclashbot/bot/free_offer_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,54 +32,49 @@
FREE_OFFER_SCROLL_TIMEOUT = 35 # seconds


def get_to_shop_page(vm_index, logger):
click(vm_index, SHOP_PAGE_BUTTON[0], SHOP_PAGE_BUTTON[1])
if wait_for_clash_main_shop_page(vm_index, logger) == "restart":
logger.change_status(
status="Error 085708235 Failure waiting for clash main shop page "
)
return False
return True


def free_offer_collection_state(vm_index, logger: Logger, next_state: str) -> str:
"""method to handle the entirety of the free offer collection state in the state tree"""
logger.set_current_state("free_offer_collection")
logger.change_status(status="Free offer collection state")
logger.add_free_offer_collection_attempt()


clash_main_check = check_if_on_clash_main_menu(vm_index)
if clash_main_check is not True:
logger.change_status(status="ERROR 356 Not on clash main menu for free_offer_collection_state")
logger.log(f'There are the pixels the bot saw after failing to find clash main:')
logger.change_status(
status="ERROR 356 Not on clash main menu for free_offer_collection_state"
)
logger.log(
f"There are the pixels the bot saw after failing to find clash main:"
)
for pixel in clash_main_check:
logger.log(f' {pixel}')
logger.log(f" {pixel}")

return "restart"


if check_if_on_clash_main_menu(vm_index) is not True:
logger.change_status(status="ERROR 625436252356 Not on clash main menu")
return "restart"

# get to shop page
click(vm_index, SHOP_PAGE_BUTTON[0], SHOP_PAGE_BUTTON[1])
if wait_for_clash_main_shop_page(vm_index, logger) == "restart":
logger.change_status(
status="Error 085708235 Failure waiting for clash main shop page "
)
if get_to_shop_page(vm_index, logger) is False:
logger.change_status("Failed to get to shop page!")
return "restart"

logger.change_status(status="Searching for free offer")

start_time: float = time.time()
prints = 0
while 1:
# if looped too much, return
time_taken: float = time.time() - start_time
if time_taken > FREE_OFFER_SCROLL_TIMEOUT:
logger.log(
f"Scrolled longer than {FREE_OFFER_SCROLL_TIMEOUT} seconds so breaking"
)
logger.log(f"Scrolled longer than {FREE_OFFER_SCROLL_TIMEOUT}s so breaking")
break

if prints * 10 < time_taken:
logger.change_status(
status=f"Searching for free offer: {str(time_taken)[:4]}"
)
prints += 1

# look for free offer
if find_and_click_free_offer(vm_index, logger) == "fail":
continue
Expand Down Expand Up @@ -114,6 +109,7 @@ def find_and_click_free_offer(vm_index, logger: Logger) -> Literal["fail", "good
# scroll
scroll_down_fast_on_left_side_of_screen(vm_index)
time.sleep(1)
click(vm_index, 13, 250)
return "fail"

# if the coord exists, click the offer
Expand Down Expand Up @@ -142,7 +138,7 @@ def buy_this_free_offer(vm_index, logger) -> Literal["good"]:

# click deadspace for if its a chest
logger.log("Clicking deadspace if its a chest")
click(vm_index, 10, 344, clicks=15, interval=0.75)
click(vm_index, 5, 344, clicks=15, interval=0.75)
time.sleep(1)

return "good"
Expand Down Expand Up @@ -191,4 +187,9 @@ def find_free_offer_icon(vm_index):


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

free_offer_collection_state(vm_index, logger, "next_state")

# get_to_shop_page(vm_index, logger)
48 changes: 25 additions & 23 deletions src/pyclashbot/bot/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,21 +773,28 @@ def check_if_on_card_page(vm_index) -> bool:
Returns:
bool: True if the bot is on the card page, False otherwise.
"""
if not region_is_color(vm_index, region=[75, 579, 31, 11], color=(73, 105, 139)):
return False
if not region_is_color(vm_index, region=[170, 577, 29, 10], color=(72, 105, 138)):
return False
iar = numpy.asarray(screenshot(vm_index))
pixels = [
iar[110][294],
iar[137][317],
iar[117][310],
iar[479][56],
iar[485][56],
]

lines = [
check_line_for_color(
vm_index, x_1=393, y_1=9, x_2=410, y_2=29, color=(66, 198, 24)
),
check_line_for_color(
vm_index, x_1=67, y_1=54, x_2=99, y_2=84, color=(96, 196, 255)
),
colors = [
[150, 62, 4],
[165 , 75, 2],
[255, 238, 230],
[232, 0, 248],
[214, 2, 226],
]

return all(lines)
for i, p in enumerate(pixels):
if not pixel_is_equal(colors[i],p,tol=15):
return False

return True


def get_to_challenges_tab_from_main(vm_index, logger) -> Literal["restart", "good"]:
Expand Down Expand Up @@ -960,7 +967,7 @@ def check_if_on_clash_main_shop_page(vm_index) -> bool:


def wait_for_clash_main_shop_page(
vm_index, logger: Logger, printmode=False
vm_index, logger: Logger
) -> Literal["restart", "good"]:
"""
Wait for the bot to navigate to the main shop page in the Clash of Clans game.
Expand All @@ -975,21 +982,14 @@ def wait_for_clash_main_shop_page(
Literal["restart", "good"]: "restart" if the bot needs to be restarted, "good" otherwise.
"""
start_time = time.time()
if printmode:
logger.change_status(status="Waiting for clash main shop page")
else:
logger.log("Waiting for clash main shop page")
while not check_if_on_clash_main_shop_page(vm_index):
time_taken = time.time() - start_time
if time_taken > 20:
logger.change_status(
status="Error 764527546 Waiting too long for clash main shop page"
)
return "restart"
if printmode:
logger.change_status(status="Done waiting for clash main shop page")
else:
logger.log("Done waiting for clash main shop page")

return "good"


Expand Down Expand Up @@ -1220,6 +1220,8 @@ def check_for_end_2v2_battle_screen(vm_index) -> bool:


if __name__ == "__main__":
vm_index = 1
vm_index = 11




while 1:print(check_if_in_1v1_battle(vm_index))
Loading

0 comments on commit 307f4f9

Please sign in to comment.