Example #1
0
import args.args_core as arg
from util.logger import Log
from version import __version__

if __name__ == '__main__':
    """Main entry point for kcauto script. Decides whether or not to launch in
    CLI, GUI, or debug mode.
    """

    args = arg.args.parse_args()

    if args.cli:
        from kcauto_wrapper import kcauto_main
        cfg = args.cfg_path if args.cfg_path else args.cfg
        Log.log_success(
            f"Initializing kcauto v{__version__} in command-line mode with "
            f"the '{cfg}' config file.")
        kcauto_main()
    elif args.debug:
        if not args.debug_asset:
            raise ValueError(
                "--debug-asset must be specified when using --debug.")
        from util.debug import debug
        debug.find_all(args.debug_asset, args.debug_similarity)
    else:
        from kcauto_gui import gui_main
        Log.log_success(f"Initializing kcauto v{__version__} GUI.")
        gui_main()
Example #2
0
    def print_stats(self):
        Log.log_success(
            "kcauto has been running for "
            f"{KCTime.timedelta_to_str(datetime.now() - self.start_time)}"
            f" (loop {self.loop_count}).")
        if cfg.config.combat.enabled:
            Log.log_success(self.combat)
        if cfg.config.pvp.enabled:
            Log.log_success(self.pvp)
        if cfg.config.expedition.enabled:
            Log.log_success(self.expedition)

        if cfg.config.combat.enabled:
            for fleet in flt.fleets.combat_fleets:
                Log.log_success(fleet)
        if cfg.config.expedition.enabled:
            for fleet in flt.fleets.expedition_fleets:
                Log.log_success(fleet)

        if cfg.config.ship_switcher.enabled:
            Log.log_success(self.ship_switcher)

        if self.resupply.resupplies_done > 0:
            Log.log_success(self.resupply)

        if self.repair.repairs_done > 0:
            Log.log_success(self.repair)

        if cfg.config.quest.enabled:
            Log.log_success(self.quest)

        if cfg.config.scheduler.enabled:
            import scheduler.scheduler_core as sch
            Log.log_success("Active Scheduler rules:")
            for sleep_tuple in sch.scheduler.stop_timers:
                Log.log_success(
                    f"- {sleep_tuple[1]} at "
                    f"{KCTime.datetime_to_str(sleep_tuple[0])}")
            for wake_tuple in sch.scheduler.wake_timers:
                Log.log_success(
                    f"- {wake_tuple[1]} until "
                    f"{KCTime.datetime_to_str(wake_tuple[0])}")
            for run_tuple in sch.scheduler.run_thresholds:
                Log.log_success(f"- {run_tuple[1]}")
            for rule_tuple in sch.scheduler.misc_rules:
                Log.log_success(f"- {rule_tuple}")

        if self.recovery.recoveries_done > 0:
            Log.log_success(self.recovery)

        Log.log_success(self.rsc)

        if not arg.args.parsed_args.no_click_track:
            clt.click_tracker.export()

        self.print_loop_end_stats = False
Example #3
0
    def find_kancolle(self):
        """Method that finds the Kancolle game on-screen and determine the UI
        being used as well as the position of the game. On first startup the
        method will look for all UIs until one is found; on subsequent runs
        it will first look for the last found UI. Generates or modifies
        pre-defined regions accordingly.

        Raises:
            FindFailed: could not find the game on-screen.
        """
        Log.log_msg("Finding kancolle.")
        ref_r = None
        attempt = 0
        screen = Region()

        # look for last-seen UI, if set
        if self.last_ui:
            try:
                ref_r = self.find(
                    screen, f'global|kc_ref_point_{self.last_ui}.png', EXACT)
            except FindFailed:
                self.last_ui = None
                Log.log_debug("Last known UI not found.")

        # if last-seen UI was not found, or if kcauto is in first start
        while not ref_r:
            try:
                ref_r = self.find(screen, 'global|kc_ref_point_1.png', EXACT)
                self.last_ui = 1
                Log.log_debug("Using UI 1 or 2")
                break
            except FindFailed:
                Log.log_debug("Not using UI 1 or 2")
            try:
                ref_r = self.find(screen, 'global|kc_ref_point_2.png', EXACT)
                self.last_ui = 2
                Log.log_debug("Using UI 3")
                break
            except FindFailed:
                Log.log_debug("Not using UI 3")
            try:
                ref_r = self.find(screen, 'global|kc_ref_point_3.png', EXACT)
                self.last_ui = 3
                Log.log_debug("Using UI 4 or 5")
                break
            except FindFailed:
                Log.log_debug("Not using UI 4 or 5")
            attempt += 1
            sleep(1)
            if attempt > 3:
                Log.log_error("Could not find Kancolle reference point.")
                raise FindFailed()

        new_game_x = ref_r.x - 144
        new_game_y = ref_r.y
        Log.log_debug(f"Game X:{new_game_x}, Y:{new_game_y}")

        # define click callback as needed
        if not arg.args.parsed_args.no_click_track:
            ImageMatch.click_callback = clt.click_tracker.track_click

        # define click and hover method overrides as needed
        if (cfg.config.general.interaction_mode
                is InteractionModeEnum.CHROME_DRIVER):
            ImageMatch.override_click_method = self._override_click_method
            ImageMatch.override_hover_method = self._override_hover_method

        if new_game_x != self.game_x or new_game_y != self.game_y:
            if not self.game_x or self.game_y:
                Log.log_success("Game found. Initializing regions.")
            else:
                Log.log_msg("Game has moved. Shifting regions.")
            self.game_x = new_game_x
            self.game_y = new_game_y
            self._update_regions()

        return True