diff --git a/AutoAFK2.py b/AutoAFK2.py index 03e6efb..1bf49ba 100644 --- a/AutoAFK2.py +++ b/AutoAFK2.py @@ -137,6 +137,12 @@ def emit(self, record): bot.open_afk_stages(afkstages=False) bot.blind_push("afkstages") + if args.fish: + bot.safe_open_and_close( + name=inspect.currentframe().f_code.co_name, state="open" + ) + bot.fishing() + # If no function launch argument we pop the UI options = [ "Run Dailies", diff --git a/automation/afkj_automation.py b/automation/afkj_automation.py index ea9740d..1e1a66a 100644 --- a/automation/afkj_automation.py +++ b/automation/afkj_automation.py @@ -2025,3 +2025,86 @@ def quest_push(self) -> None: ): self.logger.info("Time changed!") self.wait(4) + + def fishing(self) -> None: + """Farms the fishing. + An experimental feature for AutoAFK2. Currently not completely implemented. + + The overall logic as follows: + 1. **Open and choose a map** + 1. click upper right corner to open map + 2. click Starter Story + 3. if found "check" button then click it. (character currently not in Starter Story maps) + 4. swipe from left to right, homing the location of submaps + 5. click the first submap + 2. **Find fishing spot** + 1. if found any available fishing spot then click it. + 2. click "goto" button + 3. wait until the "fishing_cast" button shows up. This means the character has arrived at the spot and start fishing. + 3. **Fishing activity** + 1. wait until "fishing_cast" or "fishing_pull" or "fishing_locked" buttons shows up then apply corresponding logic. + 2. (see the fishing logic in following comments, which inspired by the so called "bang-bang control") + """ + + self.logger.info("Farming fishing!\n") + self.click_xy(880, 200, seconds=3) # Open map + self.click_xy(400, 1800, seconds=3) # Select Starter Story + self.swipe(400, 1600, 1000, 1600, 500) # "Homing" sub-maps + self.click_xy(170, 1600, seconds=3) # Select first sub-map, TODO: add support for iterating through all sub-maps + + # Find fishing spot + spot = self.is_visible_array( + ["buttons/fishing_available_collected_spot", # 100% collected spots + "buttons/fishing_available_spot"], # Available spots + confidence=0.9, + seconds=3, + ) + + if spot != "not_found": + self.logger.info("Fishing spot found\n") + self.click(spot, confidence=0.9, seconds=3) # Click the spot + self.click("buttons/goto", seconds=3) # Click "goto" button + + # Wait until the "fishing_cast" button shows up with limited patience and click it + for _ in range(20): + self.wait(1) + if self.is_visible("buttons/fishing_cast", confidence=0.9, seconds=0) or \ + self.is_visible("buttons/fishing_pull", confidence=0.9, seconds=0): + break + + # Fishing activity + while True: + if self.is_visible("buttons/fishing_cast", confidence=0.9, seconds=0, click=True): + self.logger.info("Fish caught!, cast again!\n") + + elif self.is_visible("buttons/fishing_pull", confidence=0.9, seconds=0, click=True): + self.logger.info("Start fighting!\n") + + # The following logic is inspired by the so called "bang-bang control" + while not self.is_visible("buttons/fishing_cast", confidence=0.9, seconds=0): + if self.is_visible("buttons/fishing_skill", confidence=0.9, seconds=0, click=True): + # cast the skill, this will be the major contributor under the fishing logic + pass + elif self.is_visible("buttons/fishing_in_range", confidence=0.9, seconds=0): + # do nothing, let the hook go left + pass + elif self.is_visible("buttons/fishing_cast", confidence=0.9, seconds=0): + self.logger.info("Fish caught!, cast again!\n") + break + else: + # TODO: press the "fishing_pull" button, move the hook righ until its in the "circle". (I'm not sure how to do "press" in the current framework) + pass + self.wait(1) # if there's any way to decrease the waiting time, it would be better (e.g. directly call `time.sleep()`) + + elif self.is_visible("buttons/fishing_locked", confidence=0.9, seconds=0): + self.logger.info("Spot locked!\n") + + else: + self.logger.info("Something went wrong!\n") + + self.wait(1) + + else: + self.logger.info("No fishing spots found\n") + + self.logger.info("Fishing farmed!\n") \ No newline at end of file diff --git a/automation/utility.py b/automation/utility.py index ca2e293..5e2f7e0 100644 --- a/automation/utility.py +++ b/automation/utility.py @@ -43,6 +43,7 @@ def parse_arguments() -> argparse.Namespace: ) parser.add_argument("-afks", action="store_true", help="Run AFK Stages") parser.add_argument("-afkt", action="store_true", help="Run AFK Talent Stages") + parser.add_argument("-fish", action="store_true", help="Run the Fishing farming") parser.add_argument("-test", action="store_true", help="Used for testing functions") parser.add_argument( "-charms", action="store_true", help="Run the Dura's Trials function" diff --git a/img/buttons/fishing_available_collected_spot.png b/img/buttons/fishing_available_collected_spot.png new file mode 100644 index 0000000..fa8a749 Binary files /dev/null and b/img/buttons/fishing_available_collected_spot.png differ diff --git a/img/buttons/fishing_available_spot.png b/img/buttons/fishing_available_spot.png new file mode 100644 index 0000000..7dcf690 Binary files /dev/null and b/img/buttons/fishing_available_spot.png differ diff --git a/img/buttons/fishing_cast.png b/img/buttons/fishing_cast.png new file mode 100644 index 0000000..a94592c Binary files /dev/null and b/img/buttons/fishing_cast.png differ diff --git a/img/buttons/fishing_locked.png b/img/buttons/fishing_locked.png new file mode 100644 index 0000000..9dbf18d Binary files /dev/null and b/img/buttons/fishing_locked.png differ diff --git a/img/buttons/fishing_pull.png b/img/buttons/fishing_pull.png new file mode 100644 index 0000000..6f19d7a Binary files /dev/null and b/img/buttons/fishing_pull.png differ diff --git a/img/buttons/fishing_skill.png b/img/buttons/fishing_skill.png new file mode 100644 index 0000000..f2ee619 Binary files /dev/null and b/img/buttons/fishing_skill.png differ diff --git a/img/buttons/fising_in_range.png b/img/buttons/fising_in_range.png new file mode 100644 index 0000000..275393a Binary files /dev/null and b/img/buttons/fising_in_range.png differ diff --git a/img/buttons/goto.png b/img/buttons/goto.png new file mode 100644 index 0000000..8c3acb1 Binary files /dev/null and b/img/buttons/goto.png differ