diff --git a/main.py b/main.py index a96d8921..fdaf3d24 100644 --- a/main.py +++ b/main.py @@ -65,13 +65,16 @@ def handleGameplayTasks(context): context['gameWindow']['previousMonsters'] = context['gameWindow']['monsters'] return context hasCreaturesToAttackAfterCheck = hasCreaturesToAttack(context) - if hasCreaturesToAttackAfterCheck: - if context['cavebot']['closestCreature'] is not None: - context['way'] = 'cavebot' + if context['targeting']['enabled'] == False: + context['way'] = 'waypoint' + else: + if hasCreaturesToAttackAfterCheck: + if context['cavebot']['closestCreature'] is not None: + context['way'] = 'cavebot' + else: + context['way'] = 'waypoint' else: context['way'] = 'waypoint' - else: - context['way'] = 'waypoint' if hasCreaturesToAttackAfterCheck and shouldAskForCavebotTasks(context): currentRootTask = currentTask.rootTask if currentTask is not None else None isTryingToAttackClosestCreature = currentRootTask is not None and (currentRootTask.name == 'attackClosestCreature') diff --git a/src/gameplay/context.py b/src/gameplay/context.py index 970cc8e5..6a3dc417 100644 --- a/src/gameplay/context.py +++ b/src/gameplay/context.py @@ -23,6 +23,17 @@ 'waypoints': { 'currentIndex': None, 'points': np.array([ + ('', 'lure', (33158, 32317, 12), {}), + # maior que X mobs ligar o target + # habilitar o target ao tomar block + # ('', 'lure', (33165, 32287, 12), {}), + # ('', 'lure', (33139, 32287, 12), {}), + # ('', 'lure', (33156, 32268, 12), {}), + # ('', 'lure', (33171, 32237, 12), {}), + # ('', 'lure', (33142, 32240, 12), {}), + + + # werehyaena cave 1 ('', 'walk', (33214, 32458, 8), {}), ('', 'moveUp', (33214, 32456, 8), {'direction': 'north'}), @@ -35,15 +46,15 @@ ('', 'moveDown', (33227, 32358, 8), {'direction': 'east'}), ('', 'walk', (33222, 32355, 9), {}), # 10 ('', 'moveDown', (33222, 32355, 9), {'direction': 'north'}), - ('caveStart', 'walk', (33207, 32353, 10), {}), - ('', 'walk', (33189, 32348, 10), {}), - ('', 'walk', (33193, 32366, 10), {}), - ('', 'walk', (33208, 32367, 10), {}), - ('', 'walk', (33223, 32387, 10), {}), - ('', 'walk', (33200, 32389, 10), {}), - ('', 'walk', (33196, 32398, 10), {}), - ('', 'walk', (33210, 32373, 10), {}), - ('', 'walk', (33221, 32351, 10), {}), # 20 + ('caveStart', 'lure', (33207, 32353, 10), {}), + ('', 'lure', (33189, 32348, 10), {}), + ('', 'lure', (33193, 32366, 10), {}), + ('', 'lure', (33208, 32367, 10), {}), + ('', 'lure', (33223, 32387, 10), {}), + ('', 'lure', (33200, 32389, 10), {}), + ('', 'lure', (33196, 32398, 10), {}), + ('', 'lure', (33210, 32373, 10), {}), + ('', 'lure', (33221, 32351, 10), {}), # 20 ('', 'dropFlasks', (33306, 32289, 7), {}), ('', 'refillChecker', (33306, 32289, 7), { # 22 'minimumOfManaPotions': 200, diff --git a/src/gameplay/core/tasks/dropFlasks.py b/src/gameplay/core/tasks/dropFlasks.py index be011936..6f6585d2 100644 --- a/src/gameplay/core/tasks/dropFlasks.py +++ b/src/gameplay/core/tasks/dropFlasks.py @@ -1,4 +1,3 @@ -from src.repositories.inventory.core import images from ...typings import Context from .common.vector import VectorTask from .dropEachFlask import DropEachFlaskTask @@ -15,11 +14,10 @@ def __init__(self): self.delayAfterComplete = 1 self.isRootTask = True - # TODO: add unit tests def onBeforeStart(self, context: Context) -> Context: self.tasks = [ OpenBackpackTask(context['backpacks']['main']).setParentTask(self).setRootTask(self), - ExpandBackpackTask(images['containersBars'][context['backpacks']['main']]).setParentTask(self).setRootTask(self), + ExpandBackpackTask(context['backpacks']['main']).setParentTask(self).setRootTask(self), DropEachFlaskTask(context['backpacks']['main']).setParentTask(self).setRootTask(self), SetNextWaypointTask().setParentTask(self).setRootTask(self), ] diff --git a/src/gameplay/core/tasks/expandBackpack.py b/src/gameplay/core/tasks/expandBackpack.py index cae00c27..9bf4f195 100644 --- a/src/gameplay/core/tasks/expandBackpack.py +++ b/src/gameplay/core/tasks/expandBackpack.py @@ -1,31 +1,29 @@ from src.gameplay.typings import Context from src.repositories.inventory.core import images -from src.shared.typings import GrayImage from src.utils.core import locate from src.utils.mouse import drag from ...typings import Context from .common.base import BaseTask +# TODO: ignore when backpack already expanded +# TODO: check if backpack is expanded on did class ExpandBackpackTask(BaseTask): - def __init__(self, backpackBarImage: GrayImage): + def __init__(self, backpack: str): super().__init__() self.name = 'expandBackpack' self.delayBeforeStart = 1 self.delayAfterComplete = 1 self.terminable = False - self.backpackBarImage = backpackBarImage - - # TODO: ignore if backpack already expanded - # TODO: add unit tests - def shouldIgnore(self, context: Context) -> bool: - return super().shouldIgnore(context) + self.backpack = backpack # TODO: add unit tests def do(self, context: Context) -> Context: + backpackBarImage = images['containersBars'][context['backpacks']['main']] # TODO: locate should be done in right content position to avoid calculation in whole screen - backpackBarPosition = locate(context['screenshot'], self.backpackBarImage, confidence=0.8) + backpackBarPosition = locate(context['screenshot'], backpackBarImage, confidence=0.8) croppedImage = context['screenshot'][backpackBarPosition[1]:, backpackBarPosition[0]:] + # TODO: locate should be done in right content position to avoid calculation in whole screen backpackBottomBarPosition = locate(croppedImage, images['containersBars']['backpack bottom'], confidence=0.8) backpackBottomBarPositionX = backpackBottomBarPosition[0] + backpackBarPosition[0] backpackBottomBarPositionY = backpackBottomBarPosition[1] + backpackBarPosition[1] @@ -36,8 +34,3 @@ def do(self, context: Context) -> Context: return context drag((backpackBottomBarPositionX, backpackBottomBarPositionY), (backpackBottomBarPositionX, backpackBottomBarPositionY + scrollY)) return context - - # TODO: check if backpack is expanded - # TODO: add unit tests - def did(self, _: Context) -> bool: - return True diff --git a/src/gameplay/core/tasks/goToFreeDepot.py b/src/gameplay/core/tasks/goToFreeDepot.py index 54470237..7940f7a2 100644 --- a/src/gameplay/core/tasks/goToFreeDepot.py +++ b/src/gameplay/core/tasks/goToFreeDepot.py @@ -69,7 +69,6 @@ def getVisibleDepotCoordinates(self, coordinate: Coordinate, depotCoordinates: C # TODO: add unit tests def ping(self, context: Context) -> Context: - print('GoToFreeDepotTask.ping') if self.closestFreeDepotCoordinate is None: return context if self.state == 'walkingIntoFreeDepot' and context['radar']['coordinate'][0] == self.closestFreeDepotCoordinate[0] and context['radar']['coordinate'][1] == self.closestFreeDepotCoordinate[1]: diff --git a/src/gameplay/core/tasks/lootCorpse.py b/src/gameplay/core/tasks/lootCorpse.py index 5c8f70fa..e92d6021 100644 --- a/src/gameplay/core/tasks/lootCorpse.py +++ b/src/gameplay/core/tasks/lootCorpse.py @@ -5,16 +5,15 @@ class LootCorpseTask(VectorTask): - def __init__(self, corpse: Creature): + def __init__(self, creature: Creature): super().__init__() self.name = 'lootCorpse' self.isRootTask = True - self.corpse = corpse + self.creature = creature - # TODO: add unit tests def onBeforeStart(self, context: Context) -> Context: self.tasks = [ - # TODO: add walkToCoordinate to reach dead corpse - CollectDeadCorpseTask(self.corpse).setParentTask(self).setRootTask(self) + # TODO: add walkToCoordinate to reach dead creature + CollectDeadCorpseTask(self.creature).setParentTask(self).setRootTask(self) ] return context diff --git a/src/gameplay/core/tasks/lure.py b/src/gameplay/core/tasks/lure.py new file mode 100644 index 00000000..0ec5ccf6 --- /dev/null +++ b/src/gameplay/core/tasks/lure.py @@ -0,0 +1,43 @@ +from src.gameplay.core.waypoint import resolveGoalCoordinate +from src.gameplay.typings import Context +import src.repositories.gameWindow.creatures as gameWindowCreatures +from ...typings import Context +from .common.vector import VectorTask +from .walkToCoordinate import WalkToCoordinateTask + + +# Tarefas: +# - Se algum bicho parar perto da coordenada, ligar o target +# - Se levar trap, ligar o target +class LureWaypointTask(VectorTask): + # TODO: add types + def __init__(self, waypoint): + super().__init__() + self.name = 'lureWaypoint' + self.delayAfterComplete = 1 + self.isRootTask = True + self.manuallyTerminable = True + self.waypoint = waypoint + + def shouldManuallyComplete(self, context: Context) -> bool: + return len(context['battleList']['creatures']) == 0 + + # def ping(self, context: Context) -> Context: + # if gameWindowCreatures.isTrappedByCreatures(context['gameWindow']['monsters'], context['radar']['coordinate']): + # context['targeting']['enabled'] = True + # return context + + def onBeforeStart(self, context: Context) -> Context: + context['targeting']['enabled'] = False + self.tasks = [ + WalkToCoordinateTask(self.waypoint['coordinate']).setParentTask(self).setRootTask(self), + ] + return context + + def onComplete(self, context: Context) -> Context: + # nextWaypointIndex = getNextArrayIndex( + # context['cavebot']['waypoints']['points'], context['cavebot']['waypoints']['currentIndex']) + # context['cavebot']['waypoints']['currentIndex'] = nextWaypointIndex + # currentWaypoint = context['cavebot']['waypoints']['points'][context['cavebot']['waypoints']['currentIndex']] + # context['cavebot']['waypoints']['state'] = resolveGoalCoordinate(context['radar']['coordinate'], currentWaypoint) + return context \ No newline at end of file diff --git a/src/gameplay/resolvers.py b/src/gameplay/resolvers.py index cbfe00b7..b2a4963c 100644 --- a/src/gameplay/resolvers.py +++ b/src/gameplay/resolvers.py @@ -6,6 +6,7 @@ from .core.tasks.depositItems import DepositItemsTask from .core.tasks.dropFlasks import DropFlasksTask from .core.tasks.logout import LogoutTask +from .core.tasks.lure import LureWaypointTask from .core.tasks.refill import RefillTask from .core.tasks.refillChecker import RefillCheckerTask from .core.tasks.singleWalk import SingleWalkTask @@ -24,6 +25,8 @@ def resolveTasksByWaypoint(waypoint: Waypoint) -> Union[BaseTask, VectorTask]: return DropFlasksTask() elif waypoint['type'] == 'logout': return LogoutTask() + elif waypoint['type'] == 'lure': + return LureWaypointTask(waypoint) elif waypoint['type'] == 'moveDown': return SingleWalkTask(waypoint['type'], waypoint['options']['direction']) elif waypoint['type'] == 'moveUp': diff --git a/test.py b/test.py new file mode 100644 index 00000000..803d0592 --- /dev/null +++ b/test.py @@ -0,0 +1,21 @@ +import src.repositories.gameWindow.creatures as gameWindowCreatures +import src.utils.core +import src.repositories.battleList.core +import src.repositories.battleList.extractors +import src.repositories.gameWindow.config +import src.repositories.gameWindow.core + + + +grayScreenshot = src.utils.core.getScreenshot() +radarCoordinate = src.repositories.radar.core.getCoordinate(grayScreenshot) +content = src.repositories.battleList.extractors.getContent(grayScreenshot) +battleListCreatures = src.repositories.battleList.core.getCreatures(content) +beingAttackedCreatureCategory = src.repositories.battleList.core.getBeingAttackedCreatureCategory(battleListCreatures) +gameWindowSize = src.repositories.gameWindow.config.gameWindowSizes[1080] +gameWindowCoordinate = src.repositories.gameWindow.core.getCoordinate(grayScreenshot, gameWindowSize) +gameWindowImg = src.repositories.gameWindow.core.getImageByCoordinate(grayScreenshot, gameWindowCoordinate, gameWindowSize) +gameWindowCreaturess = src.repositories.gameWindow.creatures.getCreatures(battleListCreatures, 'left', gameWindowCoordinate, gameWindowImg, radarCoordinate,beingAttackedCreatureCategory=beingAttackedCreatureCategory) +isTrapped = gameWindowCreatures.isTrappedByCreatures(gameWindowCreaturess, radarCoordinate) + +print('isTrapped', isTrapped) \ No newline at end of file diff --git a/tests/unit/gameplay/core/tasks/test_dropFlasks.py b/tests/unit/gameplay/core/tasks/test_dropFlasks.py new file mode 100644 index 00000000..4d829ba8 --- /dev/null +++ b/tests/unit/gameplay/core/tasks/test_dropFlasks.py @@ -0,0 +1,35 @@ +from src.gameplay.core.tasks.dropEachFlask import DropEachFlaskTask +from src.gameplay.core.tasks.dropFlasks import DropFlasksTask +from src.gameplay.core.tasks.expandBackpack import ExpandBackpackTask +from src.gameplay.core.tasks.openBackpack import OpenBackpackTask +from src.gameplay.core.tasks.setNextWaypoint import SetNextWaypointTask + + +context = {'backpacks': {'main': 'beach backpack'}} + +def test_should_test_default_params(): + task = DropFlasksTask() + assert task.name == 'dropFlasks' + assert task.delayBeforeStart == 1 + assert task.delayAfterComplete == True + assert task.isRootTask == True + +def test_onBeforeStart(): + task = DropFlasksTask() + assert task.onBeforeStart(context) == context + assert len(task.tasks) == 4 + assert isinstance(task.tasks[0], OpenBackpackTask) + assert task.tasks[0].backpack == context['backpacks']['main'] + assert task.tasks[0].parentTask == task + assert task.tasks[0].rootTask == task + assert isinstance(task.tasks[1], ExpandBackpackTask) + assert task.tasks[1].backpack == context['backpacks']['main'] + assert task.tasks[1].parentTask == task + assert task.tasks[1].rootTask == task + assert isinstance(task.tasks[2], DropEachFlaskTask) + assert task.tasks[2].backpack == context['backpacks']['main'] + assert task.tasks[2].parentTask == task + assert task.tasks[2].rootTask == task + assert isinstance(task.tasks[3], SetNextWaypointTask) + assert task.tasks[3].parentTask == task + assert task.tasks[3].rootTask == task diff --git a/tests/unit/gameplay/core/tasks/test_lootCorpse.py b/tests/unit/gameplay/core/tasks/test_lootCorpse.py new file mode 100644 index 00000000..a4923599 --- /dev/null +++ b/tests/unit/gameplay/core/tasks/test_lootCorpse.py @@ -0,0 +1,21 @@ +from src.gameplay.core.tasks.collectDeadCorpse import CollectDeadCorpseTask +from src.gameplay.core.tasks.lootCorpse import LootCorpseTask + + +context = {} +creature = {'coordinate': (0, 0, 0)} + +def test_should_test_default_params(): + task = LootCorpseTask(creature) + assert task.name == 'lootCorpse' + assert task.isRootTask == True + assert task.creature == creature + +def test_onBeforeStart(): + task = LootCorpseTask(creature) + assert task.onBeforeStart(context) == context + assert len(task.tasks) == 1 + assert isinstance(task.tasks[0], CollectDeadCorpseTask) + assert task.tasks[0].creature == creature + assert task.tasks[0].parentTask == task + assert task.tasks[0].rootTask == task diff --git a/tests/unit/gameplay/core/tasks/test_useShovelWaypoint.py b/tests/unit/gameplay/core/tasks/test_useShovelWaypoint.py new file mode 100644 index 00000000..d8c68951 --- /dev/null +++ b/tests/unit/gameplay/core/tasks/test_useShovelWaypoint.py @@ -0,0 +1,30 @@ +from src.gameplay.core.tasks.clickInCoordinate import ClickInCoordinateTask +from src.gameplay.core.tasks.setNextWaypoint import SetNextWaypointTask +from src.gameplay.core.tasks.useShovel import UseShovelTask +from src.gameplay.core.tasks.useShovelWaypoint import UseShovelWaypointTask + + +context = {} +waypoint = {'coordinate': (1, 2, 3)} + +def test_should_test_default_params(): + task = UseShovelWaypointTask(waypoint) + assert task.name == 'useShovelWaypoint' + assert task.isRootTask == True + assert task.waypoint == waypoint + +def test_onBeforeStart(): + task = UseShovelWaypointTask(waypoint) + assert task.onBeforeStart(context) == context + assert len(task.tasks) == 3 + assert isinstance(task.tasks[0], UseShovelTask) + assert task.tasks[0].waypoint == waypoint + assert task.tasks[0].parentTask == task + assert task.tasks[0].rootTask == task + assert isinstance(task.tasks[1], ClickInCoordinateTask) + assert task.tasks[1].waypoint == waypoint + assert task.tasks[1].parentTask == task + assert task.tasks[1].rootTask == task + assert isinstance(task.tasks[2], SetNextWaypointTask) + assert task.tasks[2].parentTask == task + assert task.tasks[2].rootTask == task