27 lines
877 B
Python
27 lines
877 B
Python
import time
|
|
import cv2 as cv
|
|
import pyautogui
|
|
from core.Logger import Logger
|
|
class Spell:
|
|
def __init__(self, monitor, path, name, castTime = 0, cooldown = 2) -> None:
|
|
self.spellName = name
|
|
self.castTime = castTime
|
|
self.logger = Logger("Spell")
|
|
self.cooldown = cooldown
|
|
self.monitor = monitor
|
|
self.spellIcon = cv.imread("assets/spells/" + path, cv.IMREAD_GRAYSCALE)
|
|
self.lastUsed = None
|
|
|
|
def isOnCooldown(self):
|
|
if self.lastUsed is None:
|
|
return False
|
|
return time.time() - self.lastUsed <= self.cooldown
|
|
|
|
def cast(self):
|
|
if self.isOnCooldown() is False:
|
|
self.logger.log("Casting " + self.spellName)
|
|
lastCursorPosition = pyautogui.position()
|
|
self.monitor.findMatchAndClickIfAvailable(self.spellIcon)
|
|
time.sleep(self.castTime)
|
|
pyautogui.moveTo(lastCursorPosition)
|
|
self.lastUsed = time.time() |