Skip to content

Commit

Permalink
Merge pull request #220 from newerton/feature/new-rarity-label
Browse files Browse the repository at this point in the history
chore: fix the send heroes to house
  • Loading branch information
newerton authored Jul 24, 2022
2 parents 6f20c82 + bfae482 commit 2db3c22
Show file tree
Hide file tree
Showing 22 changed files with 72 additions and 22 deletions.
18 changes: 9 additions & 9 deletions config/EXAMPLE-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ chests:
divide: 2
chest_01: 0.01425
chest_02: 0.03250
chest_03: 0.16250
chest_04: 0.32500
chest_03: 0.11250
chest_04: 0.27625

threshold:
default: 0.7
error_message: 0.7
back_button: 0.9
work_button: 0.95
home_enable_button: 0.95
heroes_green_bar: 0.95
heroes_red_bar: 0.98
heroes_full_bar: 0.8
home_enable_button: 0.9
heroes_green_bar: 0.9
heroes_red_bar: 0.9
heroes_full_bar: 0.9
heroes_send_all: 0.9
heroes_rest_all: 0.9
chest: 0.70
Expand All @@ -53,9 +53,9 @@ heroes:
scroll_attempts: 3

offsets:
work_button_green: [160, 190]
work_button_full: [90, 120]
house_button: [280, 310]
work_button_green: [200, 230]
work_button_full: [140, 170]
house_button: [340, 370]

metamask:
enable: false
Expand Down
Binary file modified images/themes/default/bar_empty_stamina.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/themes/default/bar_green_stamina.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/themes/default/bar_red_stamina.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/bar_red_stamina_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/bar_red_stamina_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/themes/default/home_enable_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def login(self):
if password_icon_position is not False:
password = self.accounts[account_active]['password']
x, y, _, _ = password_icon_position[0]
self.actions.move((int(x+100), int(y+10)), 1)
self.actions.move((int(x+100), int(y+20)), 1)
if(self.actions.click()):
self.actions.sleep(1, 1, forceTime=True)
pyautogui.hotkey('del')
Expand Down
63 changes: 54 additions & 9 deletions src/heroes.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from pyclick import HumanClicker
from PIL import Image, ImageSequence
from cv2 import cv2

import numpy as np
import os
import pyautogui
import random


humanClicker = HumanClicker()

heroes_work_clicked = 0
Expand All @@ -25,6 +28,7 @@ def importLibs(self):
from src.actions import Actions
from src.auth import Auth
from src.config import Config
from src.desktop import Desktop
from src.error import Errors
from src.game import Game
from src.images import Images
Expand All @@ -34,6 +38,7 @@ def importLibs(self):
self.actions = Actions()
self.auth = Auth()
self.config = Config().read()
self.desktop = Desktop()
self.errors = Errors()
self.game = Game()
self.images = Images()
Expand Down Expand Up @@ -263,9 +268,27 @@ def clickHouseButtons(self):
if homeButtons is False:
return

bar_red_stamina = self.images.image('bar_red_stamina')
red_bars = self.recognition.positions(
bar_red_stamina, threshold=threshold['heroes_red_bar'])
red_bars = []
bar_empty_stamina = self.images.image('bar_empty_stamina')
bars_empty = self.recognition.positions(
bar_empty_stamina, threshold=threshold['heroes_red_bar'])

if bars_empty is not False:
red_bars.extend(bars_empty)

bar_red_stamina_1 = self.images.image('bar_red_stamina_1')
red_bars_1 = self.recognition.positions(
bar_red_stamina_1, threshold=threshold['heroes_red_bar'])

if red_bars_1 is not False:
red_bars.extend(red_bars_1)

bar_red_stamina_2 = self.images.image('bar_red_stamina_2')
red_bars_2 = self.recognition.positions(
bar_red_stamina_2, threshold=threshold['heroes_red_bar'])

if red_bars_2 is not False:
red_bars.extend(red_bars_2)

return self.sendingToHouse(rarities, red_bars, homeButtons, offset, 'red')

Expand Down Expand Up @@ -357,7 +380,7 @@ def sendingToWork(self, bar_green_elements, workButtons, offset, type):
return len(working_bars)

def sendingToHouse(self, rarities, bar_red_elements, homeButtons, offset, type):
if bar_red_elements is False:
if len(bar_red_elements) == 0:
return

if self.config['log']['console'] is not False:
Expand All @@ -372,6 +395,10 @@ def sendingToHouse(self, rarities, bar_red_elements, homeButtons, offset, type):
if sendHome is True:
red_bars.append(bar)

if self.config['log']['console'] is not False:
self.log.console('%d RED STAMINA bars detected to send Home' %
len(bar_red_elements), emoji='🥵', color='red')

if len(red_bars) > 0:
message = 'Sending {} heroes to house.'.format(
len(red_bars), type)
Expand Down Expand Up @@ -414,11 +441,29 @@ def checkHeroesRaritySendToHouseButton(self):
rarities = self.accounts[account_active]['rarity']

positions = []
screenshot = self.desktop.printScreen()
for rarity in rarities:
label_rarity = self.images.image('/heroes_types/'+rarity)
position = self.recognition.positions(
label_rarity, threshold=threshold['heroes'][rarity])
if position is not False:
positions.append(position[0])
if self.config['log']['console'] is not False:
print('Checking rarity: {}'.format(rarity))

label_rarity = self.images.image(
'/heroes_types/diamonds/'+rarity, extension='.gif')

for frame in ImageSequence.Iterator(label_rarity):
frame = frame.convert('RGBA').copy()
opencvImage = cv2.cvtColor(
np.array(frame), cv2.COLOR_RGB2BGR)
position = self.recognition.positions(
opencvImage, baseImage=screenshot, threshold=threshold['heroes'][rarity])
if position is not False:
if self.config['log']['console'] is not False:
print('Found {}'.format(rarity))
positions.append(position[0])

# position = self.recognition.positions(
# label_rarity, threshold=threshold['heroes'][rarity])
# print('position_rarity', position)
# if position is not False:
# positions.append(position[0])

return positions
11 changes: 8 additions & 3 deletions src/images.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from cv2 import cv2

from PIL import Image

class Images:
def __init__(self, theme='default'):
Expand All @@ -11,12 +11,17 @@ def __init__(self, theme='default'):
else:
self.theme = theme

def image(self, image, theme=False, path=None):
def image(self, image, theme=False, path=None, extension='.png'):
themePath = './images/themes/default/'
if theme == True:
themePath = './images/themes/' + self.theme + '/'

if path != None:
themePath = path

return cv2.imread(themePath + image + '.png')
if(extension != '.gif'):
return cv2.imread(themePath + image + extension)

if(extension == '.gif'):
im = Image.open(themePath + image + extension)
return im

0 comments on commit 2db3c22

Please sign in to comment.