-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementign daily reward collection
- Loading branch information
1 parent
b0a821b
commit 018cba5
Showing
8 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,252 @@ | ||
from pyclashbot.bot.nav import check_if_on_clash_main_menu | ||
from pyclashbot.detection.image_rec import pixel_is_equal | ||
from pyclashbot.utils.logger import Logger | ||
import numpy | ||
from pyclashbot.memu.client import screenshot, click | ||
import time | ||
|
||
|
||
def collect_daily_rewards_state(vm_index, logger, next_state): | ||
if collect_all_daily_rewards(vm_index, logger) is False: | ||
logger.change_status("Failed to collect daily rewards") | ||
return "restart" | ||
|
||
return next_state | ||
|
||
|
||
def check_for_daily_rewards(vm_index) -> bool: | ||
iar = numpy.asarray(screenshot(vm_index)) | ||
pixels = [ | ||
iar[185][40], | ||
iar[195][40], | ||
iar[200][45], | ||
iar[210][45], | ||
iar[220][40], | ||
iar[230][40], | ||
] | ||
colors = [ | ||
[232, 202, 0], | ||
[179, 123, 0], | ||
[17, 114, 181], | ||
[62, 60, 88], | ||
[174, 78, 5], | ||
[244, 223, 15], | ||
] | ||
|
||
for i, p in enumerate(pixels): | ||
if not pixel_is_equal(p, colors[i], 10): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def collect_challenge_rewards(vm_index, logger, rewards) -> bool: | ||
# if not on clash main, reutrn False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_challenge_rewards(). Returning False" | ||
) | ||
return False | ||
|
||
# open daily rewards menu | ||
click(vm_index, 41, 206) | ||
time.sleep(2) | ||
|
||
# click first task's reward | ||
if rewards[0]: | ||
click(vm_index, 195, 190) | ||
logger.change_status("Collected 1st daily challenge reward") | ||
logger.add_daily_reward() | ||
time.sleep(1) | ||
|
||
# click third task's reward | ||
if rewards[2]: | ||
click(vm_index, 207, 320) | ||
logger.change_status("Collected 2nd daily challenge reward") | ||
logger.add_daily_reward() | ||
time.sleep(1) | ||
|
||
# click second task's reward | ||
if rewards[1]: | ||
click(vm_index, 250, 254) | ||
logger.change_status("Collected 3rd daily challenge reward") | ||
logger.add_daily_reward() | ||
time.sleep(1) | ||
|
||
# click deadspace a bunch | ||
deadspace_clicks = 5 | ||
if rewards[1]: | ||
deadspace_clicks = 10 | ||
click(vm_index, 15, 290, clicks=deadspace_clicks, interval=0.33) | ||
|
||
# if not on clash main, reutrn False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_challenge_rewards(). Returning False" | ||
) | ||
return False | ||
|
||
return True | ||
|
||
|
||
def collect_daily_bonus(vm_index, logger) -> bool: | ||
# if not on clash main, retunr False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_daily_bonus(). Returning False" | ||
) | ||
return False | ||
|
||
# open daily rewards menu | ||
click(vm_index, 41, 206) | ||
time.sleep(2) | ||
|
||
# click the daily bonus reward | ||
click(vm_index, 206, 415) | ||
logger.add_daily_reward() | ||
logger.change_status("Collected daily reward chest") | ||
time.sleep(1) | ||
|
||
# click deadspace a bunch | ||
click(vm_index, 10, 300, clicks=10, interval=1) | ||
|
||
# if not on clash main, retunr False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_daily_bonus(). Returning False" | ||
) | ||
return False | ||
|
||
return True | ||
|
||
|
||
def collect_weekly_bonus(vm_index, logger) -> bool: | ||
# if not on clash main, retunr False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_weekly_bonus(). Returning False" | ||
) | ||
return False | ||
|
||
# open daily rewards menu | ||
click(vm_index, 41, 206) | ||
time.sleep(2) | ||
|
||
# click the weekly bonus reward | ||
click(vm_index, 197, 500) | ||
logger.change_status("Collected weekly reward chest") | ||
logger.add_daily_reward() | ||
time.sleep(1) | ||
|
||
# click deadspace a bunch | ||
click(vm_index, 15, 300, clicks=10, interval=0.33) | ||
|
||
# if not on clash main, retunr False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_weekly_bonus(). Returning False" | ||
) | ||
return False | ||
|
||
return True | ||
|
||
|
||
def collect_all_daily_rewards(vm_index, logger): | ||
# if not on clash main, reutrn False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main at start of collect_daily_rewards(). Returning False" | ||
) | ||
return False | ||
|
||
# check which rewards are available | ||
rewards = check_which_rewards_are_available(vm_index, logger) | ||
time.sleep(1) | ||
|
||
# collect the basic 3 daily rewards for completing tasks | ||
if rewards[0] or rewards[1] or rewards[2]: | ||
if collect_challenge_rewards(vm_index, logger, rewards) is False: | ||
logger.change_status("Failed to collect challenge rewards") | ||
return False | ||
|
||
# collect the daily bonus reward if it exists | ||
if rewards[3] and collect_daily_bonus(vm_index, logger) is False: | ||
logger.change_status("Failed to collect daily bonus reward") | ||
return False | ||
|
||
# collect the weekly bonus reward if it exists | ||
if rewards[4] and collect_weekly_bonus(vm_index, logger) is False: | ||
logger.change_status("Failed to collect weekly bonus reward") | ||
return False | ||
|
||
return True | ||
|
||
|
||
def check_which_rewards_are_available(vm_index, logger): | ||
logger.change_status("Checking which rewards are available") | ||
|
||
# if not on clash main, return False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main before check_which_rewards_are_available() " | ||
) | ||
return False | ||
|
||
# open daily rewards menu | ||
click(vm_index, 41, 206) | ||
time.sleep(2) | ||
|
||
# check which rewards are available | ||
rewards = check_rewards_menu_pixels(vm_index) | ||
|
||
# click deadspace a bunch | ||
click(vm_index, 15, 290, clicks=3, interval=0.33) | ||
time.sleep(2) | ||
|
||
# if not on clash main, return False | ||
if not check_if_on_clash_main_menu(vm_index): | ||
logger.change_status( | ||
"Not on clash main after check_which_rewards_are_available()" | ||
) | ||
return False | ||
|
||
positives = 0 | ||
for _ in rewards: | ||
if _: | ||
positives += 1 | ||
|
||
print(f"There are {positives} to collect") | ||
return rewards | ||
|
||
|
||
def check_rewards_menu_pixels(vm_index): | ||
iar = numpy.asarray(screenshot(vm_index)) | ||
pixels = [ | ||
iar[192][345], | ||
iar[345][262], | ||
iar[330][345], | ||
iar[415][242], | ||
iar[502][235], | ||
] | ||
|
||
colors = [ | ||
[125, 161, 188], | ||
[181, 211, 231], | ||
[126, 162, 189], | ||
[223, 131, 28], | ||
[113, 156, 0], | ||
] | ||
|
||
bools = [] | ||
for i, p in enumerate(pixels): | ||
bool = pixel_is_equal(p, colors[i], 15) | ||
bools.append(not (bool)) | ||
|
||
return bools | ||
|
||
|
||
if __name__ == "__main__": | ||
vm_index = 12 | ||
logger = Logger() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.