class GetLoot: def __init__(self, button, MOUSE_OPTION): self.MOUSE_OPTION = MOUSE_OPTION self.SendToClient = Hotkey(MOUSE_OPTION) self.button = button def TakeLoot(self, SQMs): if self.button == 'right': if self.MOUSE_OPTION == 1: pass_mouse_position = self.SendToClient.Position() else: pass_mouse_position = [0, 0] start_loot_time = time.time() for i, j in zip(range(0, 18, +2), range(1, 19, +2)): self.SendToClient.RightClick(SQMs[i], SQMs[j]) end_loot_time = time.time() - start_loot_time if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(pass_mouse_position[0], pass_mouse_position[1]) print("Looted In: ", end_loot_time) elif self.button == 'left': if self.MOUSE_OPTION == 1: pass_mouse_position = self.SendToClient.Position() else: pass_mouse_position = [0, 0] start_loot_time = time.time() for i, j in zip(range(0, 18, +2), range(1, 19, +2)): self.SendToClient.LeftClick(SQMs[i], SQMs[j]) end_loot_time = time.time() - start_loot_time if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(pass_mouse_position[0], pass_mouse_position[1]) print("Looted In: ", end_loot_time)
def AttackTarget(monster, BattlePosition, SQMs, TargetNumber, MOUSE_OPTION, HOOK_OPTION): SendToClient = Hotkey(MOUSE_OPTION) Target[0], Target[1] = ScanTarget(BattlePosition, monster, HOOK_OPTION) TargetNumber = NumberOfTargets(BattlePosition, monster, HOOK_OPTION) print("Number of " + monster + ": ", TargetNumber) if Target[0] != 0 and Target[1] != 0: attacking = IsAttacking(BattlePosition, HOOK_OPTION, monster) TargetNumber = int( NumberOfTargets(BattlePosition, monster, HOOK_OPTION)) if not attacking: print("Attacking a Target") if MOUSE_OPTION == 1: past_mouse_position = SendToClient.Position() else: past_mouse_position = [0, 0] SendToClient.LeftClick(Target[0], Target[1]) if MOUSE_OPTION == 1: SendToClient.MoveTo(past_mouse_position[0], past_mouse_position[1]) if TargetNumber is not None: return TargetNumber else: return 0 else: print("You are attacking") TargetNumber = NumberOfTargets(BattlePosition, monster, HOOK_OPTION) if TargetNumber != 0: return TargetNumber else: return 0 else: return 0
class CaveBotController: def __init__(self, MOUSE_OPTION, ScriptName, LootButton, TimeToStand, Walk, Loot, ForRefresh, MapPosition, BattlePosition, SQMs): self.MOUSE_OPTION = MOUSE_OPTION self.SendToClient = Hotkey(self.MOUSE_OPTION) self.ScriptName = ScriptName self.LootButton = LootButton self.TimeToStand = TimeToStand self.EnabledWalk = Walk self.EnabledLooting = Loot self.WalkForRefresh = ForRefresh self.MapPosition = MapPosition self.BattlePosition = BattlePosition self.SQMs = SQMs self.Target = [] # Remember Set For Get From Cavebot (for me) self.FollowMode = True ''' StartCaveBot Take The Data From Module CaveBot And Search For Mark With Status TRUE, When He Finds, He Starts The Engine Of CaveBot. ''' def StartCaveBot(self, data, MonstersToAttack): while IsEnable(): for i in range(len(data)): if not IsEnable(): return else: if data[i]['status']: self.HandleCaveBot(data, i, MonstersToAttack) ''' The Handler ''' def HandleCaveBot(self, data, i, Monsters): global TargetNumber MarkLocation = [0, 0] sleep(self.TimeToStand) if not IsEnable(): return ''' Disconsider This Block If You Don't Mark The Walk Option... ''' # region Walk if self.EnabledWalk: while MarkLocation[0] == 0 and MarkLocation[1] == 0: MarkLocation[0], MarkLocation[1] = LocateCenterImage('images/MapSettings/' + data[i]["mark"] + '.png', Region=( self.MapPosition[0], self.MapPosition[1], self.MapPosition[2], self.MapPosition[3]), Precision=0.8) if MarkLocation[0] == 0 and MarkLocation[1] == 0: print("Mark: { ", data[i]["mark"], " } Not Located, Try Again") if self.WalkForRefresh: sleep(.3) self.SendToClient.Press('up_arrow') sleep(.1) self.SendToClient.Press('left_arrow') sleep(.7) self.SendToClient.Press('down_arrow') sleep(.1) self.SendToClient.Press('right_arrow') sleep(.1) else: print("successfully Located The Mark: { ", data[i]["mark"], " } Clicking On Your Position") MarkLocation[0] = self.MapPosition[0] + MarkLocation[0] MarkLocation[1] = self.MapPosition[1] + MarkLocation[1] # Clicking In Mark Position if self.MOUSE_OPTION == 1: PastPosition = self.SendToClient.Position() else: PastPosition = [0, 0] self.SendToClient.LeftClick(MarkLocation[0], MarkLocation[1]) if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(PastPosition[0], PastPosition[1]) # endregion ''' The Attack, Is Every Time Enabled. ''' # region Attack for Monster in Monsters: FirstMonstersNumber = 0 SecondMonstersNumber = 0 Number = NumberOfTargets(self.BattlePosition, Monster) # NumberOfMonster.append(Number) while Number > 0: if not IsEnable(): return self.Target = ScanTarget(self.BattlePosition, Monster) if self.Target[0] != 0 and self.Target[1] != 0: # Verify If You Are Already Attacking ! if not IsAttacking(self.BattlePosition): print("Attacking The Target") if self.MOUSE_OPTION == 1: PastPosition = self.SendToClient.Position() else: PastPosition = [0, 0] self.SendToClient.LeftClick(self.Target[0], self.Target[1]) if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(PastPosition[0], PastPosition[1]) FirstMonstersNumber = NumberOfTargets(self.BattlePosition, Monster) else: print("You are attacking") FirstMonstersNumber = NumberOfTargets(self.BattlePosition, Monster) # Control Follow Mode In Attack (Follow Or Idle) if self.FollowMode: IsNeedFollow = NeedFollow() if IsNeedFollow: print("Clicking In Follow") if self.MOUSE_OPTION == 1: PastPosition = self.SendToClient.Position() else: PastPosition = [0, 0] FollowPosition = LocateCenterImage('images/TibiaSettings/NotFollow.png', Precision=0.7) self.SendToClient.LeftClick(FollowPosition[0], FollowPosition[1]) if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(PastPosition[0], PastPosition[1]) sleep(.2) self.Target = ScanTarget(self.BattlePosition, Monster) if self.Target[0] != 0 and self.Target[1] != 0: # Verify If You Are Already Attacking ! if IsAttacking(self.BattlePosition): # For Debugging # print("Attacking The Target") if self.MOUSE_OPTION == 1: PastPosition = self.SendToClient.Position() else: PastPosition = [0, 0] self.SendToClient.LeftClick(self.Target[0], self.Target[1]) if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(PastPosition[0], PastPosition[1]) SecondMonstersNumber = NumberOfTargets(self.BattlePosition, Monster) else: # For Debugging # print("You are attacking") SecondMonstersNumber = NumberOfTargets(self.BattlePosition, Monster) if SecondMonstersNumber < FirstMonstersNumber: self.TakeLoot() self.Target = [] sleep(0.2) Number = NumberOfTargets(self.BattlePosition, Monster) if Number == 0: break if self.EnabledWalk: if CheckWaypoint(data[i]["mark"], self.MapPosition): data[i]['status'] = False if i + 1 == len(data): data[i - i]['status'] = True with open('Scripts/' + self.ScriptName + '.json', 'w') as wJson: json.dump(data, wJson, indent=4) else: data[i + 1]['status'] = True with open('Scripts/' + self.ScriptName + '.json', 'w') as wJson: json.dump(data, wJson, indent=4) else: self.HandleCaveBot(data, i, Monsters) # endregion def TakeLoot(self): if self.MOUSE_OPTION == 1: PastPosition = self.SendToClient.Position() else: PastPosition = [0, 0] # For Debugging # StartLootTime = time() for i, j in zip(range(0, 18, + 2), range(1, 19, + 2)): if self.LootButton == 'right': self.SendToClient.RightClick(self.SQMs[i], self.SQMs[j]) elif self.LootButton == 'left': self.SendToClient.LeftClick(self.SQMs[i], self.SQMs[j]) # For Debugging # EndLootTime = time() - StartLootTime if self.MOUSE_OPTION == 1: self.SendToClient.MoveTo(PastPosition[0], PastPosition[1])