Exemplo n.º 1
0
 def resupply_fleets(self):
     """Method that goes through the fleets and resupplies them in the
     resupply menu.
     """
     Util.log_msg("Begin resupplying fleets.")
     for fleet_id, fleet in self.fleets.items():
         if fleet.needs_resupply:
             Util.log_msg("Resupplying fleet {}.".format(fleet_id))
             if fleet_id != 1:
                 Fleet.switch(self.regions['top_submenu'], fleet.fleet_id)
             Util.wait_and_click_and_wait(
                 self.regions['top_submenu'], 'resupply_all.png',
                 self.regions['lower_right'], 'resupply_all_done.png')
             Util.kc_sleep()
             self.stats.increment_resupplies_done()
             fleet.needs_resupply = False
             Util.kc_sleep()
     Util.log_msg("Done resupplying fleets.")
Exemplo n.º 2
0
    def _conduct_pre_sortie_checks(self):
        """Method to conduct pre-sortie fatigue and supply checks on the
        combat fleets as needed.

        Returns:
            bool: True if the fleet passes the pre-sortie checks, False
                otherwise
        """
        cancel_sortie = False

        if self.config.combat['fleet_mode'] == 'striking':
            # switch fleet to 3rd fleet if striking fleet
            Util.kc_sleep(1)
            Fleet.switch(self.regions['top_submenu'], 3)

        needs_resupply, self.dmg, fleet_fatigue = (
            self._run_pre_sortie_fleet_check_logic(self.primary_fleet))

        if self.combined_fleet:
            # additional combined fleet checks
            Fleet.switch(self.regions['top_submenu'], 2)
            two_needs_resupply, fleet_two_damages, fleet_two_fatigue = (
                self._run_pre_sortie_fleet_check_logic(self.fleets[2]))
            Fleet.switch(self.regions['top_submenu'], 1)

            self.dmg = self._combine_fleet_damages(self.dmg, fleet_two_damages)
            for key in fleet_fatigue:
                fleet_fatigue[key] = (fleet_fatigue[key]
                                      or fleet_two_fatigue[key])

        if needs_resupply:
            Util.log_warning("Canceling combat sortie: resupply required.")
            self.set_next_combat_time()
            cancel_sortie = True

        if 'CheckFatigue' in self.config.combat['misc_options']:
            if fleet_fatigue['high']:
                Util.log_warning(
                    "Canceling combat sortie: fleet has high fatigue.")
                self.set_next_combat_time({'minutes': 25})
                cancel_sortie = True
            elif fleet_fatigue['medium']:
                Util.log_warning(
                    "Canceling combat sortie: fleet has medium fatigue.")
                self.set_next_combat_time({'minutes': 15})
                cancel_sortie = True

        # just use fleet 1's method
        damage_counts_at_threshold = (
            self.primary_fleet.get_damage_counts_at_threshold(
                self.config.combat['repair_limit'], self.dmg))

        if damage_counts_at_threshold > 0:
            Util.log_warning(
                "Canceling combat sortie: {:d} ships above damage threshold.".
                format(damage_counts_at_threshold))
            self.set_next_combat_time()
            cancel_sortie = True

        if ('PortCheck' in self.config.combat['misc_options']
                or self.map.world == 'event'):
            port_full_notice = ('warning_port_full_event.png' if self.map.world
                                == 'event' else 'warning_port_full.png')
            if self.regions['lower'].exists(port_full_notice):
                Util.log_warning("Canceling combat sortie: port is full.")
                self.set_next_combat_time({'minutes': 15})
                cancel_sortie = True

        if cancel_sortie:
            return False
        return True
Exemplo n.º 3
0
    def sortie_expedition(self, fleet):
        """Method to sortie an expedition fleet to its assigned expeditions.

        Args:
            fleet (ExpeditionFleet): ExpeditionFleet to send on an expedition

        Returns:
            bool: True if the fleet was successfully sent on an expedition,
                False otherwise
        """
        self.stats.increment_expeditions_attempted()
        fleet.choose_expedition()
        Util.log_msg("Sortieing fleet {:d} to expedition {:d}".format(
            fleet.fleet_id, fleet.expedition))
        # change expedition world if necessary
        while not Util.check_and_click(
                self.kc_region, 'expedition_{}.png'.format(fleet.expedition)):
            Util.kc_sleep()
            Util.wait_and_click(self.kc_region,
                                'e_world_{}.png'.format(fleet.expedition_area))
        Util.kc_sleep(1)
        if not Util.check_and_click(self.kc_region, 'sortie_select.png'):
            if self.kc_region.exists(
                    Pattern('expedition_timer_complete.png').exact()):
                fleet.update_return_time(0, -1)
            else:
                expedition_timer = Util.read_timer(self.kc_region,
                                                   'expedition_timer.png', 'r',
                                                   80)
                fleet.update_return_time(expedition_timer['hours'],
                                         expedition_timer['minutes'] - 1)
                Util.log_warning(
                    "Expedition is already running. Return time: {}".format(
                        fleet.return_time.strftime('%Y-%m-%d %H:%M:%S')))
            return False

        Util.rejigger_mouse(self.regions, 'top')
        # switch fleet as necessary
        if fleet.fleet_id != 2:
            Fleet.switch(self.regions['top_submenu'], fleet.fleet_id)

        if (self.regions['right'].exists('ship_state_busy.png')
                or self.regions['right'].exists('ship_state_dmg_repair.png')):
            # fleet is already on an expedition or ship is being repaired
            Util.log_warning('Fleet or ship not available. Check back later')
            fleet.update_return_time(0, 15)
            Util.wait_and_click_and_wait(
                self.kc_region, 'e_world_1.png', self.regions['top_submenu'],
                'sortie_top_menu_expedition_active.png')
            return False
        else:
            if not fleet.check_supplies(self.regions['check_supply']):
                # fleet needs resupply
                Util.wait_and_click_and_wait(
                    self.kc_region, 'e_world_1.png',
                    self.regions['top_submenu'],
                    'sortie_top_menu_expedition_active.png')
                return False
            # successful expedition sortie
            Util.wait_and_click(self.kc_region, 'expedition_dispatch.png')
            fleet.dispatch_fleet()
            self.stats.increment_expeditions_sent()
            Util.log_msg("Fleet {:d} sortied. Expected return time: {}".format(
                fleet.fleet_id,
                fleet.return_time.strftime('%Y-%m-%d %H:%M:%S')))
            Util.kc_sleep(3)
        Util.rejigger_mouse(self.regions, 'top')
        Util.kc_sleep()
        return True