Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
creating timed spells module
Browse files Browse the repository at this point in the history
  • Loading branch information
MuriloChianfa committed May 12, 2022
1 parent 3fe1da1 commit 3b1a9c6
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 38 deletions.
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,9 @@

# Needed Python and Libs to Run

- [![Python 3.8.2](https://img.shields.io/badge/python-3.8.2-blue.svg)](https://www.python.org/downloads/release/python-382/)
- [![Python 3.10.1](https://img.shields.io/badge/python-3.10.1-blue.svg)](https://www.python.org/downloads/release/python-3101/)

- Install [pywin32](http://www.qarevolution.com/5-step-install-pywin32-using-pip/) with: `pip install pywin32`

- Install [pygetwindow](https://pypi.org/project/PyGetWindow/) with: `pip install pygetwindow`

- Install [opencv](https://pypi.org/project/opencv-python/) with: `pip install opencv-python`

- Install [numpy](https://pypi.org/project/numpy/) with: `pip install numpy`

- Install [pyautogui](https://pypi.org/project/PyAutoGUI/) with: `pip install pyautogui`

- Install [Pillow](https://pypi.org/project/Pillow/2.2.2/) with: `pip install Pillow`

- Install [keyboard](https://pypi.org/project/keyboard/) with: `pip install keyboard`
- python -m pip install -r requirements.txt

# Features Status

Expand All @@ -44,7 +32,7 @@
- [Cave Bot](#Cave-Bot-Module) : :warning: :heavy_check_mark:
- [Color Change]() : :warning:
- [Creature Info]() : :warning:
- [Food Eater]() : :warning:
- [Food Eater]() : :heavy_check_mark:
- [FPS Changer]() : :warning:
- [General Options]() : :warning:
- [Healer Friends]() : :warning:
Expand Down
23 changes: 22 additions & 1 deletion core/GUI.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pyautogui
import tkinter as tk
from tkinter import SUNKEN, RAISED
from tkinter import SUNKEN, RAISED, ttk
from PIL import Image, ImageTk

from core.Defaults import *
Expand Down Expand Up @@ -131,6 +131,27 @@ def addLabel(self, textOfLabel, position):
labelID.place(x=position[0], y=position[1])
return labelID

def addList(self, columns, height, sizes, position):
style = ttk.Style()
style.theme_use('winnative')
style.configure('Treeview.Heading', background="gray")

frame = tk.Frame(self.windowID, height=sizes[1], width=sizes[0])
frame.place(x=position[0], y=position[1])

table = ttk.Treeview(self.windowID, columns=columns, height=height, show='headings')
table.place(x=position[0], y=position[1])

return table

def addScrollbar(self):
from tkinter import VERTICAL, RIGHT, Y

sb = tk.Scrollbar(self.windowID, orient=VERTICAL)
sb.pack(side=RIGHT, fill=Y)

return sb

def addMinimalLabel(self, textOfLabel, position, h=16):
labelID = tk.Label(self.windowID,
text=textOfLabel,
Expand Down
8 changes: 8 additions & 0 deletions core/GUISetter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def Int(self, VarName):

return Variable, InitiatedVariable

# For Usage This:
# Variable, Initiated = self.Setter.Variables.Int('')
def array(self, name):
initiated_array = SetVariables(self.Locate).GetVar(name)
array = initiated_array

return array, initiated_array


class SetVariables:
def __init__(self, Locate):
Expand Down
2 changes: 1 addition & 1 deletion core/ThreadManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def UnPauseThread(self):
# This Function Is Not Ready To Use !!!
def KillThread(self):
for i in range(len(ActivatedThreads)):
if ActivatedThreads[i][1] == self.Name:
if 1 not in ActivatedThreads[i] and ActivatedThreads[i][1] == self.Name:
ActivatedThreads.remove(ActivatedThreads[i])
Queue.put('Kill')
# print(f"{self.Name} Killed")
Expand Down
Binary file modified images/Modules/TimedSpells.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 2 additions & 9 deletions modules/ChooseConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,15 @@ def bootstrap():
start_configuration = time.time()
Directory = os.getcwd()

shutil.copyfile(Directory + '\\Scripts' + '\\Json.json',
os.path.join(Directory + '\\Scripts' + '\\' + NameCreateJson.get() + '.json'))
shutil.copyfile(Directory + '\\scripts' + '\\Json.json',
os.path.join(Directory + '\\scripts' + '\\' + NameCreateJson.get() + '.json'))

TibiaAuto = pygetwindow.getWindowsWithTitle("Choose your config")[0]
TibiaAuto.minimize()

pyautogui.PAUSE = 0.005

time.sleep(.8)

with open(preferences_path, 'r') as LoadedJson:
preferences = json.load(LoadedJson)

time.sleep(.5)
time.sleep(.5)

try:
HealthLocation = GetHealthPosition()
print('')
Expand Down
8 changes: 3 additions & 5 deletions modules/Root.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# from modules.PythonScripts import PythonScripts
# from modules.SaveConfig import SaveConfig
# from modules.SortLoot import SortLoot
# from modules.TimedSpells import TimedSpells
from modules.TimedSpells import TimedSpells


SETTED_VARIABLES = False
Expand All @@ -56,7 +56,6 @@
CavebotScriptsPath = None



class root:
def __init__(self, CharName, LoadedJson):
self.root = GUI('root', 'TibiaAuto V12')
Expand Down Expand Up @@ -85,7 +84,7 @@ def __init__(self, CharName, LoadedJson):
self.root.addButton('Auto Fish', OpenAutoFish, [92, 23], [245, 83]).configure(state='disabled')
self.root.addButton('Auto Amulet', OpenAutoSSA, [92, 23], [147, 108])
self.root.addButton('Auto Ring', OpenAutoRing, [92, 23], [245, 108])
self.root.addButton('Timed Spells', OpenTimedSpells, [92, 23], [147, 135]).configure(state='disabled')
self.root.addButton('Timed Spells', OpenTimedSpells, [92, 23], [147, 135])
self.root.addButton('Auto Login', OpenAutoLogin, [92, 23], [245, 135]).configure(state='disabled')

self.root.addButton('Creature Info', OpenCreatureInfo, [92, 23], [147, 188]).configure(state='disabled')
Expand Down Expand Up @@ -342,7 +341,6 @@ def OpenSortLoot():


def OpenTimedSpells():
print("TimedSpells In Development...")
# TimedSpells(root)
TimedSpells(root, MOUSE_OPTION)

# endregion
241 changes: 235 additions & 6 deletions modules/TimedSpells.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,240 @@
from engine.GUI import *
"""
Food eater module
"""

EnabledTimedSpells = False
from time import sleep

from conf.Hotkeys import Hotkey

from core.GUI import *
from core.GUIManager import *
from core.GUISetter import GUISetter, check_gui

from tkinter import CENTER, VERTICAL

from core.ThreadManager import ThreadManager

from engine.ScanFood import scan_food


class TimedSpells:
def __init__(self, root):
self.TimedSpells = GUI('TimedSpells', 'Module: Timed Spells')
self.TimedSpells.DefaultWindow('TimedSpells', [306, 473], [1.2, 2.29])
started = False
enabled = False

gui_changes = []

def __init__(self, root, MOUSE_OPTION):
self.root = root
self.window = GUI('TimedSpells', 'Module: Timed spells')
self.window.DefaultWindow('TimedSpells', [306, 473], [1.2, 2.29])
self.Setter = GUISetter("TimedSpellsLoader")
self.SendToClient = Hotkey(MOUSE_OPTION)
self.ThreadManager = ThreadManager("ThreadTimedSpells")

self.gui_vars()
self.gui()

self.check()
self.check_state()

self.window.Protocol(self.destroy)
self.window.loop()

def trigger(self):
if TimedSpells.enabled:
TimedSpells.enabled = False
self.enabled_button.configure(text='TimedSpells: OFF', relief=RAISED, bg=rgb((127, 17, 8)))
self.pause()
else:
TimedSpells.enabled = True
self.enabled_button.configure(text='TimedSpells: ON', relief=SUNKEN, bg=rgb((158, 46, 34)))
self.run()

self.check()
self.check_state()

def trigger_table(self):
self.check()
self.check_state()

def run(self):
if not TimedSpells.started:
self.ThreadManager.NewThread(self.execute)
TimedSpells.started = False
else:
self.ThreadManager.UnPauseThread()
print('TimedSpells: ON')

def pause(self):
self.ThreadManager.PauseThread()
print('TimedSpells: OFF')

def execute(self):
hotkey = 0
cast_time = 1
current_time = 2

spells = []

for spell in self.table.get_children():
spells.append(self.table.item(spell)["values"])

for spell in spells:
if self.check_instant.get():
self.SendToClient.Press(spell[hotkey])

spell.extend([0])

while TimedSpells.enabled:
for spell in spells:
spell[current_time] += 1

if spell[cast_time] == spell[current_time]:
spell[current_time] = 0
self.SendToClient.Press(spell[hotkey])

sleep(1)

def destroy(self):
check_gui(TimedSpells.gui_changes, self.init_check_print, self.check_print.get(), 'CheckPrint')
check_gui(TimedSpells.gui_changes, self.init_instant, self.check_instant.get(), 'InstantExecute')
check_gui(TimedSpells.gui_changes, self.init_food_hotkey, self.food_hotkey.get(), 'Hotkey')

spells = []

for spell in self.table.get_children():
spells.append(self.table.item(spell)["values"])

check_gui(TimedSpells.gui_changes, self.init_spells, spells, 'Spells')

if len(TimedSpells.gui_changes) != 0:
for each_change in range(len(TimedSpells.gui_changes)):
self.Setter.SetVariables.SetVar(
TimedSpells.gui_changes[each_change][0],
TimedSpells.gui_changes[each_change][1]
)

if not TimedSpells.enabled:
print('Killing thread: ', self.ThreadManager)
self.ThreadManager.KillThread()

self.window.destroyWindow()

def gui_vars(self):
self.check_print, self.init_check_print = self.Setter.Variables.Bool('CheckPrint')
self.check_instant, self.init_instant = self.Setter.Variables.Bool('InstantExecute')
self.food_hotkey, self.init_food_hotkey = self.Setter.Variables.Str('Hotkey')
self.cast_every, self.init_cast_every = self.Setter.Variables.Str('CastEvery')
self.spells, self.init_spells = self.Setter.Variables.array('Spells')

def validate_cast_every(self, *args):
seconds = self.entry_cast_every.get()

if len(seconds) < 2:
return

if not seconds[-1].isdigit():
self.cast_every.set(seconds[:-1])
return

self.cast_every.set(seconds[:2])

def remove_item(self):
current_item = self.table.focus()

if (type(self.table.item(current_item)['values']) is str):
return

# print(self.table.item(current_item))
self.table.delete(current_item)

def add_item(self):
for child in self.table.get_children():
if self.food_hotkey.get() in self.table.item(child)["values"]:
return

# print(self.table.item(child)["values"])

self.table.insert('', tk.END, text='', values=(
self.food_hotkey.get(),
self.entry_cast_every.get()
))

def gui(self):
self.label = self.window.addLabel('Hotkey to press', [40, 45])
self.hotkey_button = self.window.addOption(self.food_hotkey, self.SendToClient.Hotkeys, [145, 40], 10)

self.label2 = self.window.addLabel('Cast every', [40, 75])
self.label3 = self.window.addLabel('seconds', [230, 75])
self.entry_cast_every = self.window.addEntry([145, 75], self.cast_every, 12)
self.cast_every.trace("w", self.validate_cast_every)

self.add_button = self.window.addButton('Add', self.add_item, [75, 23], [70, 110])
self.remove_button = self.window.addButton('Remove', self.remove_item, [75, 23], [170, 110])

self.table = self.window.addList(('hotkey', 'time'), 8, [230, 100], [40, 150])

self.table.column('hotkey', width=115)
self.table.column('time', anchor=CENTER, width=115)

self.table.heading('hotkey', text="Hotkey", anchor=CENTER)
self.table.heading('time', text="Time", anchor=CENTER)

self.scroll = self.window.addScrollbar()

self.table.config(yscrollcommand=self.scroll.set)
self.scroll.config(command=self.table.yview)

for spell in self.init_spells:
self.table.insert('', tk.END, text='', values=(
spell[0],
spell[1]
))

self.check_print_button = self.window.addCheck(self.check_print, [11, 365], self.init_check_print,
"Print on Tibia's screen")
self.check_print_button.configure(bg=rgb((114, 94, 48)), activebackground=rgb((114, 94, 48)),
selectcolor=rgb((114, 94, 48)))

self.check_instant_button = self.window.addCheck(self.check_instant, [11, 385], self.init_instant,
"Execute instant")
self.check_instant_button.configure(bg=rgb((114, 94, 48)), activebackground=rgb((114, 94, 48)),
selectcolor=rgb((114, 94, 48)))

if not TimedSpells.enabled:
self.enabled_button = self.window.addButton('TimedSpells: OFF', self.trigger, [287, 23], [11, 411])
else:
self.enabled_button = self.window.addButton('TimedSpells: ON', self.trigger, [287, 23], [11, 411])
self.enabled_button.configure(relief=SUNKEN, bg=rgb((158, 46, 34)))

self.ok_button = self.window.addButton('Ok', self.destroy, [73, 21], [115, 440])

def check(self):
if TimedSpells.enabled:
self.hotkey_button.configure(state='disabled')
else:
self.hotkey_button.configure(state='normal')

def check_state(self):
if TimedSpells.enabled:
Disable(self.label)
Disable(self.hotkey_button)
Disable(self.check_print_button)
Disable(self.label2)
Disable(self.label3)
Disable(self.entry_cast_every)
Disable(self.add_button)
Disable(self.remove_button)
Disable(self.check_instant_button)
else:
Enable(self.label)
Enable(self.hotkey_button)
Enable(self.check_print_button)
Enable(self.label2)
Enable(self.label3)
Enable(self.entry_cast_every)
Enable(self.add_button)
Enable(self.remove_button)
Enable(self.check_instant_button)

self.TimedSpells.loop()
ExecGUITrigger()
Loading

0 comments on commit 3b1a9c6

Please sign in to comment.