Skip to content

Commit

Permalink
run pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmiglio committed Nov 27, 2022
1 parent 7d00126 commit 1c5b8a2
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 108 deletions.
33 changes: 17 additions & 16 deletions pyclashbot/bot/battlepass_rewards_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy
from ahk import AHK
from pyclashbot.bot.clashmain import check_if_on_clash_main_menu

from pyclashbot.bot.clashmain import check_if_on_clash_main_menu
from pyclashbot.detection import pixel_is_equal
from pyclashbot.memu import click, screenshot

Expand Down Expand Up @@ -38,11 +38,12 @@ def check_if_has_battlepass_rewards():

def collect_battlepass_rewards(logger):
logger.change_status("Collecting battlepass rewards.")

#should be on clash main at this point
if not check_if_on_clash_main_menu():return "restart"

#declare locations of reward coords

# should be on clash main at this point
if not check_if_on_clash_main_menu():
return "restart"

# declare locations of reward coords
chest_locations = [
[300, 280],
[300, 340],
Expand All @@ -52,10 +53,10 @@ def collect_battlepass_rewards(logger):
[300, 540],
]

#loop until the battlepass rewards icon on the main menu indicates there are no more rewards
# loop until the battlepass rewards icon on the main menu indicates there are no more rewards
loops = 0
while check_if_has_battlepass_rewards():
#if too many loops
# if too many loops
if loops > 15:
logger.change_status("looped through collect battlepass too many times.")
return "restart"
Expand All @@ -67,25 +68,25 @@ def collect_battlepass_rewards(logger):

# click every chest locations in the chest_locations list
for coord in chest_locations:
click(coord[0], coord[1],duration=0.1)
click(coord[0], coord[1], duration=0.1)
time.sleep(0.33)

# click deadspace
for _ in range(15):
click(20, 440,duration=0.1)
click(20, 440, duration=0.1)
time.sleep(0.1)

# close battlepass to reset UI and return to clash main
click(210, 630)
time.sleep(1)

#increment the battlepass reward collection counter
# increment the battlepass reward collection counter
logger.add_battlepass_reward_collection()

logger.change_status("Done collecting battlepass rewards.")


#should be on clash main at this point
if not check_if_on_clash_main_menu():return "restart"
else: return "clashmain"

# should be on clash main at this point
if not check_if_on_clash_main_menu():
return "restart"
else:
return "clashmain"
124 changes: 68 additions & 56 deletions pyclashbot/bot/free_offer_collection.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
import time

import numpy
from pyclashbot.bot.clashmain import check_if_on_clash_main_menu
from pyclashbot.detection.image_rec import find_references, get_first_location, pixel_is_equal

from pyclashbot.memu.client import click, get_file_count, make_reference_image_list, print_pix_list, screenshot, scroll_down_super_fast
from pyclashbot.bot.clashmain import check_if_on_clash_main_menu
from pyclashbot.detection.image_rec import (
find_references,
get_first_location,
pixel_is_equal,
)
from pyclashbot.memu.client import (
click,
get_file_count,
make_reference_image_list,
print_pix_list,
screenshot,
scroll_down_super_fast,
)


def collect_free_offer_from_shop(logger):
logger.change_status("Collecting free offer from shop.")

if not check_if_on_clash_main_menu():return"restart"
if not check_if_on_clash_main_menu():
return "restart"

#get to shop
# get to shop
get_to_shop_page_from_main(logger)

#scroll a few times, each time looking for the free offer
# scroll a few times, each time looking for the free offer
logger.change_status("Looking for free offer")
free_offer_coords=None
loops=0
free_offer_coords = None
loops = 0
while free_offer_coords is None:
scroll_down_super_fast()
time.sleep(2)

free_offer_coords=find_free_offer_icon()
free_offer_coords = find_free_offer_icon()

loops += 1
if loops > 10:
break

loops+=1
if loops>10:break

if free_offer_coords is None:
logger.change_status("Failed to find free offer icon.")
#get to clash main from shop
if get_to_clash_main_from_shop(logger)=="restart":return "restart"
else: return
# get to clash main from shop
if get_to_clash_main_from_shop(logger) == "restart":
return "restart"
else:
return

#click free offer
# click free offer
logger.change_status("Found free offer icon. Collecting it.")
click(free_offer_coords[0],free_offer_coords[1])
click(free_offer_coords[0], free_offer_coords[1])
time.sleep(2)
click(200,425)
click(200, 425)
logger.add_free_offer_collection()

#click deadspace
# click deadspace
for _ in range(4):
click(18,379)
click(18, 379)

# get to clash main from shop
if get_to_clash_main_from_shop(logger) == "restart":
return "restart"

#get to clash main from shop
if get_to_clash_main_from_shop(logger)=="restart":return "restart"

def find_free_offer_icon():
current_image = screenshot()
Expand All @@ -70,15 +88,16 @@ def find_free_offer_icon():

def get_to_clash_main_from_shop(logger):
logger.change_status("Getting to clash main from shop.")
#click main
click(240,630)
# click main
click(240, 630)
time.sleep(2)

loops=0
loops = 0
while not check_if_on_clash_main_menu():
loops+=1
if loops>20:return"restart"
click(200,620)
loops += 1
if loops > 20:
return "restart"
click(200, 620)
time.sleep(2)

logger.change_status("Made it to clash main from shop.")
Expand All @@ -87,16 +106,18 @@ def get_to_clash_main_from_shop(logger):
def get_to_shop_page_from_main(logger):
logger.change_status("Getting to shop from main.")

#check if on main
# check if on main
if not check_if_on_clash_main_menu():
logger.change_status("Not on clash main so cant start collect free offer stuff.")
logger.change_status(
"Not on clash main so cant start collect free offer stuff."
)
return "restart"

#click shop icon
click(35,636)
# click shop icon
click(35, 636)
time.sleep(1)

#check if on shop
# check if on shop
if not check_if_on_shop_page_with_delay():
logger.change_status("Failed to get to shop page.")
return "restart"
Expand All @@ -105,43 +126,34 @@ def get_to_shop_page_from_main(logger):


def check_if_on_shop_page():
iar=numpy.asarray(screenshot())
pix_list=[
iar = numpy.asarray(screenshot())

pix_list = [
iar[624][71],
iar[636][55],
iar[623][85],
iar[625][71],
]
color_list=[
[103,234,56],
[56,85,101],
[247,194,75],
[103,236,56],

color_list = [
[103, 234, 56],
[56, 85, 101],
[247, 194, 75],
[103, 236, 56],
]
for n in range(4):
this_pixel=pix_list[n]
this_color=color_list[n]
if not pixel_is_equal(this_pixel,this_color,tol=35):
this_pixel = pix_list[n]
this_color = color_list[n]
if not pixel_is_equal(this_pixel, this_color, tol=35):
return False
return True


def check_if_on_shop_page_with_delay():
start_time=time.time()
while time.time()-start_time<3:
start_time = time.time()
while time.time() - start_time < 3:
print("looping thru")
if check_if_on_shop_page():
print("made it")
return True
time.sleep(0.5)
return False








43 changes: 20 additions & 23 deletions pyclashbot/bot/level_up_reward_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,40 @@ def collect_level_up_rewards(logger):
# starts and ends on clash main
logger.change_status("Collecting level up rewards.")
loops = 0

#should be on clash main at this point
if not check_if_on_clash_main_menu():return "restart"

#loop until the level up rewards icon on the main menu indicates there are no more rewards
# should be on clash main at this point
if not check_if_on_clash_main_menu():
return "restart"

# loop until the level up rewards icon on the main menu indicates there are no more rewards
while check_if_has_level_up_rewards():
#loop counter
# loop counter
loops += 1
if loops>20:
return"restart"
if loops > 20:
return "restart"

#click logo in top left
# click logo in top left
click(17, 48)
time.sleep(1)
#click chest

# click chest
click(135, 160)
time.sleep(1)
#click dead space to skip through rewards

# click dead space to skip through rewards
for _ in range(20):
click(20, 450)
time.sleep(0.33)
#increment counter

# increment counter
logger.add_level_up_chest_collection()

#should be on clash main at this point, if not click deadspace a little, then check again.
# should be on clash main at this point, if not click deadspace a little, then check again.
if not check_if_on_clash_main_menu():
#try to get to main by clicking deadspace more
# try to get to main by clicking deadspace more
for _ in range(20):
click(20, 450)
time.sleep(0.33)
#if this didnt help getting to main then return restart
if not check_if_on_clash_main_menu():return"restart"





# if this didnt help getting to main then return restart
if not check_if_on_clash_main_menu():
return "restart"
2 changes: 0 additions & 2 deletions pyclashbot/bot/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def request_random_card_from_clash_main(logger):
return None




def request_random_card(logger, maximum_scrolls=10):
# method to request a random card
# starts on the request screen (the one with a bunch of pictures of the cards)
Expand Down
7 changes: 5 additions & 2 deletions pyclashbot/bot/war.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def handle_war_attacks(logger):
# sometimes the player lacks the cards to make a complete deck at this point
# if you STILL done have a deck, return to main
if not check_if_has_a_deck_for_this_war_battle():
logger.change_status("Fight not avialable yet/Not enough cards to complete deck. Skipping war attack this time.")
logger.change_status(
"Fight not avialable yet/Not enough cards to complete deck. Skipping war attack this time."
)
for _ in range(5):
click(20, 440)
get_to_clash_main_from_clan_page(logger)
Expand Down Expand Up @@ -112,7 +114,8 @@ def fight_war_battle(logger):
click(random.randint(70, 355), random.randint(320, 490))
time.sleep(1)

for n in range(15): logger.change_status("Manual wait for end battle..."+str(n))
for n in range(15):
logger.change_status("Manual wait for end battle..." + str(n))


def make_a_random_deck_for_this_war_battle():
Expand Down
1 change: 0 additions & 1 deletion pyclashbot/interface/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
statistics["war_battles_fought"] += 1
statistics["requests"] += 1
statistics["free_offer_collections"] += 1


# update the statistics
window["current_status"].update(statistics["current_status"]) # type: ignore
Expand Down
1 change: 0 additions & 1 deletion pyclashbot/interface/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def stat_box(stat_name: str, size=(5, 1)) -> sg.Text:
[
sg.Text("Free Offer Collections: "),
],

]

collections_stats_values = [
Expand Down
5 changes: 2 additions & 3 deletions pyclashbot/interface/tab_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import PySimpleGUI as sg
from pyclashbot.interface.stats import (
stat_box,
)

from pyclashbot.interface.stats import stat_box
from pyclashbot.interface.theme import THEME

sg.theme(THEME)
Expand Down
Loading

0 comments on commit 1c5b8a2

Please sign in to comment.