def test_movement_two(self): "Test movement example two" # 1. Create a cave from movement example one myobj = combat.Combat(text=aoc_15.from_text(TEST_MOVEMENT_TWO)) self.assertEqual(str(myobj), TEST_MOVEMENT_TWO.strip()) # 2. Check the opponents unit = myobj.cave.get_by_location(TEST_MOVEMENT_TWO_UNIT) opponents = myobj.opponents(unit) self.assertEqual(set(opponents), set(TEST_MOVEMENT_TWO_OPPONENTS)) # 3. Check the empty locations adjacent to the opponents in_range = myobj.move_in_range(unit, opponents) self.assertEqual(in_range, set(TEST_MOVEMENT_TWO_IN_RANGE)) # 4. Check the reachable locations reachable = myobj.move_reachable(unit, in_range) self.assertEqual(set(reachable), set(TEST_MOVEMENT_TWO_REACHABLE)) # 5. Check the nearest reachable locations nearest = myobj.move_nearest(unit, reachable) self.assertEqual(set(nearest), set(TEST_MOVEMENT_TWO_NEAREST)) # 6. Choose one of the nearest reachable locations chosen = myobj.move_choose(nearest) self.assertEqual(chosen, TEST_MOVEMENT_TWO_CHOSEN) # 7. Determine the first step toward the chosen location new_loc = myobj.move_location(reachable, chosen) self.assertEqual(new_loc, TEST_MOVEMENT_TWO_NEW_LOC) # 8. Execute the move myobj.move_execute(unit, new_loc) self.assertEqual(str(myobj), TEST_MOVEMENT_TWO_MOVED.strip())
def activate_foe(self, npc): # Activate this foe, starting combat if it hasn't already started. if self.camp.fight: self.camp.fight.activate_foe(npc) else: self.camp.fight = combat.Combat(self.camp) self.camp.fight.activate_foe(npc)
def test_larger_movement_example(self): "Test the Combat object movement example" # 1. Create Combat object from text myobj = combat.Combat(text=aoc_15.from_text(MOVEMENT_EXAMPLE_0)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 9) self.assertEqual(len(myobj.cave), 3) self.assertEqual(len(myobj.cave['#']), 32) self.assertEqual(len(myobj.cave['E']), 1) self.assertEqual(len(myobj.cave['G']), 8) self.assertEqual(myobj.cave.max_loc(), 808) self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_0.strip()) # 3. A couple of rounds of movement myobj.round() self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_1.strip()) myobj.round() self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_2.strip()) myobj.round() self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_3.strip()) myobj.round() self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_3.strip()) myobj.round() self.assertEqual(str(myobj), MOVEMENT_EXAMPLE_3.strip())
def run(self): # Set clock for fps clock = pygame.time.Clock() while True: # Reset any possible action action = 0 # Go through any actions taken by the user for event in pygame.event.get(): # Key events if event.type == pygame.KEYDOWN: # Alt+F4 = quitting if event.key == pygame.K_F4 and bool(event.mod & pygame.KMOD_ALT): pygame.display.quit() pygame.quit() # Handle actual controls if event.key in keyboard_dict.keys(): action = keyboard_dict[event.key] # Handle any joystick actions over the keyboard actions else: action = joystick.joystick_handler() # If there is a fight if self.is_fighting: self.is_fighting = False fight = combat.Combat(self.screen, self.player) self.player = fight.run() # Draw world self.draw() self.input_handler(action) pygame.display.flip() clock.tick(60)
def test_part_two(self): "Test part two example of Combat object" # 1. Create Combat object from text myobj = combat.Combat(part2=True, text=aoc_15.from_text(PART_TWO_TEXT)) # 2. Check the part two result self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
def test_part_one(self): "Test part one example of Combat object" # 1. Create Combat object from text myobj = combat.Combat(text=aoc_15.from_text(PART_ONE_TEXT)) # 2. Check the part one result self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
def start(self): enter_yulin() while self.get_remain_chance(): fight_loc = wait_for_color(YuLinColor.ReadyFightYuLinChi, max_time=10) click(fight_loc, random_range=5, tired_check=True) this_fight = combat.Combat('御灵', combat_time_limit=60 * 5 + random.randint(40, 80)) combat_result = this_fight.start(auto_ready=True)
def test_empty_init(self): "Test the default Combat creation" # 1. Create default Combat object myobj = combat.Combat() # 2. Make sure it has the default values self.assertEqual(myobj.part2, False) self.assertEqual(myobj.text, None) self.assertEqual(len(myobj.cave), 0)
def main_personaltupo(refresh_time=3, desc=True): ''' 1. 锁定阵容 2,进入寮突破 3. 开始挂机 :return: ''' tupo_main = MainJiejie() tupo_main.tap_to_main() personal_tupo = PersonalTuPo(desc) remain = personal_tupo.get_remain_chance() while remain: win_count, avaliable_targets = personal_tupo.get_tupo_page_status() if win_count < refresh_time: next_target = avaliable_targets[0] logging.debug(f'this target have {next_target.metals} metal.') click((int((next_target.region[2] + next_target.region[0]) / 2), int((next_target.region[3] + next_target.region[1]) / 2))) this_color = JiejieColor.PersonalAttack x_offset, y_offset = 423 - 185, 547 - 171 x_offset, y_offset = cordinates_scale((x_offset, y_offset), constants.WINDOW_ATTRIBUTES) this_color.region = [ next_target.region[0], next_target.region[1], next_target.region[2] + x_offset, next_target.region[1] + y_offset ] this_color.screen_shot_region = this_color.get_region_to_screenshot( ) time.sleep(1) attack_cords = wait_for_color(this_color) accept_invite() click(attack_cords) this_fight = combat.Combat('结界突破', combat_time_limit=60 * 2 + random.randint(40, 80)) try: combat_result = this_fight.start(auto_ready=True) except TimeoutError: logging.warning('Failed to finish tupo combat!') accept_invite() click((986, 629), tired_check=False, need_convert=True) escape() utilities.random_sleep(1, 0.5) accept_invite() click((986, 629), tired_check=False, need_convert=True) # combat_result = this_fight.start(auto_ready=True) logging.debug('finished one tupo') tupo_main.tap_to_main() remain = personal_tupo.get_remain_chance() else: personal_tupo.refresh() wait_for_state(img.jiejietupo_img.MAIN_TUPO) return 0
def main_liaotupo(): ''' 1. 锁定阵容 2,进入寮突破 3. 开始挂机 :return: ''' tupo_main = MainJiejie() tupo_main.tap_to_main() liao_tupo = LiaoTuPo() remain = liao_tupo.get_remain_chance() while remain: try: next_target = liao_tupo.get_next_avaliable_target() click((int((next_target.region[2] + next_target.region[0]) / 2), int((next_target.region[3] + next_target.region[1]) / 2))) this_color = JiejieColor.LiaoAttack y_offset_top, y_offset_bottom = 593 - 729, 920 - 549 y_offset_top, y_offset_bottom = cordinates_scale( (y_offset_top, y_offset_bottom), constants.WINDOW_ATTRIBUTES) this_color.region = [ next_target.region[0], next_target.region[1] + y_offset_top, next_target.region[2], next_target.region[1] + y_offset_bottom ] this_color.screen_shot_region = this_color.get_region_to_screenshot( ) time.sleep(1) attack_cords = wait_for_color(this_color) accept_invite() click(attack_cords) this_fight = combat.Combat('阴阳寮突破', combat_time_limit=60 * 5 + random.randint(40, 80)) try: combat_result = this_fight.start(auto_ready=True) except TimeoutError: logging.warning('Failed to finish tupo combat!') accept_invite() click((986, 629), tired_check=False, need_convert=True) escape() utilities.random_sleep(1, 0.5) accept_invite() click((986, 629), tired_check=False, need_convert=True) # combat_result = this_fight.start(auto_ready=True) tupo_main.tap_to_main() liao_tupo.current_page = 0 logging.debug('finished one tupo') remain = liao_tupo.get_remain_chance() except LiaotupoFinishedException: # no need to continue return 0 return 1
def go_new_location(self, inp): current_room = ROOMS[self.location] # Checks all DIRECTIONS, comparing them to user input for dir in DIRECTIONS: # If the DESTINATION is available and matches user input, move to it if current_room[dir] and dir == inp: target_room_id = current_room[dir] # Finds approperiate wording for the load screen! if inp == UP: load_text='Climbing' elif inp == DOWN: load_text='Descending' else: load_text = 'Walking' # Loader between screens transition(self.go_loadspeed, text=load_text + ' ' + inp + '!') # If target room contains enemies, prompt for combat if (ROOMS[target_room_id][ENEMIES]) and (not ROOMS[target_room_id][SEEN]): # If fight forf = self.ask_fight_or_flight(ROOMS[target_room_id], dir) if forf[0]: enemies = [give_monster(x) for x in ROOMS[target_room_id][ENEMIES]] self.player.inventory = self.inventory fight = combat.Combat(self.player, enemies) fight.cmdloop() if self.player.hp <= 0: print ('\n') exit() for weps in range(forf[1] - fight.user.weapon_quantity): self.inventory.remove(fight.user.weapon[NAME].lower()) self.location = target_room_id self.display_current_room() # If user chose retreat else: transition(text='Retreating cowardly to ' + current_room[NAME]) self.display_current_room() # Elif room is peaceful, change location and display room else: self.location = current_room[dir] self.display_current_room() break # If the DESTINATION is empty elif dir == inp and not current_room[dir]: self.display_current_room() # Customized messages for CLIMBING/DESCENDING no destination if dir == UP: self.error_msg(self.NO_UP) elif dir == DOWN: self.error_msg(self.NO_DOWN) # N/S/E/W else: self.error_msg('{} {}'.format(self.EMPTY_DIR, dir.upper())) break
def part_two(args, input_lines): "Process part two of the puzzle" # 1. Create the puzzle solver solver = combat.Combat(part2=True, text=input_lines) # 2. Determine the solution for part two solution = solver.part_two(verbose=args.verbose, limit=args.limit) if solution is None: print("There is no solution") else: print("The solution for part two is %s" % (solution)) # 3. Return result return solution is not None
def test_example_part_two_elf_attack(self): "Test determine attack rate for part two" # 1. Loop for all of the examples for index, text in enumerate(PART_TWO_COMBAT): #print("test_rounds %d" % index) # 2. Create the Combat object myobj = combat.Combat(text=aoc_15.from_text(text)) # 3. Determine the minimum attack rate elf_attack = myobj.minimum_elf_attack(verbose=False, limit=40) # 5. Verify that things are the way they should be self.assertEqual(elf_attack, PART_TWO_COMBAT_ATTACK[index])
def event(self, list): #Function accepts argument and sets it to a attribute called self.list self.list = list #Has a list of options pre-made. sections = ["Sit-down", "Get-Food", "Go to the Teacher", "Exit"] print( "You've entered the lunch-room, it's loud, busy and bustling as always ..." ) print( "The Cafeteria is split up amongst five sections, which one do you want to sit at today?" ) #print the options in sentence template. for i in range(4): print(f"{i}.{sections[i]}") #Ask user what they want to do then generate combat. seat = int(input("What would you like to do? :")) if seat in range(4): fighting = combat.Combat(self.list) fighting.fight()
def test_example_combat_results(self): "Test combat results" # 1. Loop for all of the examples for index, text in enumerate(EXAMPLE_COMBAT): #print("test_rounds %d" % index) # 2. Create the Combat object myobj = combat.Combat(text=aoc_15.from_text(text)) # 3. Engage in combat rounds = myobj.fight(verbose=False) # 4. Get the surviving hit points hitpoints = myobj.hitpoints() # 5. Verify that things are the way they should be self.assertEqual(rounds, EXAMPLE_COMBAT_ROUNDS[index]) self.assertEqual(hitpoints, EXAMPLE_COMBAT_HITPOINTS[index]) self.assertEqual(hitpoints * rounds, EXAMPLE_COMBAT_RESULTS[index])
def generate_successor_state(self, state, action, real): temp_state = deepcopy(state) if state.state_type == StateType.NORMAL_COMBAT: # Special state: if we've killed all enemies but want our q-learning to update itself if action == (cards.strike, -1): if temp_state.player.health <= 0: return (0, -1000) # Only increment combat_count if we've won a real combat if real: self.combat_count += 1 # 10 wins = win game! if self.combat_count >= self.combat_wins: return (1, 1000) # Else, we add a card temp_state.nc_player.health = temp_state.player.health temp_state.nc_player.max_health = temp_state.player.max_health next_state = RandomEvent(deepcopy(temp_state.nc_player)) next_state.state_type = StateType.ADD_CARD # Our reward is how much health we had left at the end of this combat return (next_state, next_state.player.health) if action is None: temp_state.end_turn() temp_state.start_turn() else: card, target = action if not temp_state.player.deck.use_card(card, target): return (None, 0) # This checks in the new state if all enemies are dead. Temp state -> new state dead_enemies = True for enemy in temp_state.enemies: if enemy.health > 0: dead_enemies = False break # If we've lost this combat/game if temp_state.player.health <= 0: temp_state.end_game = True return (temp_state, 0) # If we've won this combat... if dead_enemies: temp_state.end_game = True return (temp_state, 0) else: return (temp_state, 0) if state.state_type == StateType.COPY: if action is not None: temp_state.player.deck.hand.append(action) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.DISCARD_TO_DRAW: if action is not None: temp_state.player.deck.draw_pile.insert(0, action) temp_state.player.deck.discard_pile.remove(action) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.EXHAUST_TO_HAND: if action is not None: temp_state.player.deck.hand.append(action) temp_state.player.deck.exhaust_pile.remove(action) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.HAND_TO_DRAW: if action is not None: temp_state.player.deck.draw_pile.insert(0, action) temp_state.player.deck.hand.remove(action) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.HAND_TO_EXHAUST: if action is not None: temp_state.player.deck.exhaust_card(action) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.UPGRADE: if action is not None and action.card_type != CardType.STATUS: temp_state.player.deck.hand.remove(action) temp_state.player.deck.hand.append( self.upgrade_list[action.name]) temp_state.state_type = StateType.NORMAL_COMBAT return (temp_state, 0) if state.state_type == StateType.NORMAL_REST: if action == 0: temp_state.heal() probability = random.uniform(0, 1) if probability <= 0.2: # go to rest next_state = RestSite(deepcopy(temp_state.player)) return (next_state, 0) elif probability <= 0.4: # go to a random event next_state = RandomEvent(deepcopy(temp_state.player)) return (next_state, 0) else: # go to a combat next_state = combat.Combat(deepcopy(temp_state.player), self.get_enemy_encounter()) return (next_state, 0) else: temp_state.state_type = StateType.UPGRADE_REST return (temp_state, 0) if state.state_type == StateType.UPGRADE_REST: if action is not None: upgraded_card = self.upgrade_list[action.name] temp_state.player.deck.remove_card(action) temp_state.player.deck.add_card(upgraded_card) probability = random.uniform(0, 1) if probability <= 0.2: # go to rest next_state = RestSite(deepcopy(temp_state.player)) return (next_state, 0) elif probability <= 0.3: # go to a random event next_state = RandomEvent(deepcopy(temp_state.player)) return (next_state, 0) else: # go to a combat next_state = combat.Combat(deepcopy(temp_state.player), self.get_enemy_encounter()) return (next_state, 0) if state.state_type == StateType.NORMAL_RANDOM: if temp_state.generate_random_event(): probability = random.uniform(0, 1) if probability <= 0.1: # go to rest next_state = RestSite(deepcopy(temp_state.player)) return (next_state, 0) elif probability <= 0.2: # go to a random event next_state = RandomEvent(deepcopy(temp_state.player)) return (next_state, 0) else: next_state = combat.Combat(deepcopy(temp_state.player), self.get_enemy_encounter()) return (next_state, 0) else: return (temp_state, 0) if state.state_type == StateType.REMOVE_CARD: if action is not None: temp_state.player.deck.remove_card(action) probability = random.uniform(0, 1) if probability <= 0.1: # go to rest next_state = RestSite(deepcopy(temp_state.player)) return (next_state, 0) elif probability <= 0.2: # go to a random event next_state = RandomEvent(deepcopy(temp_state.player)) return (next_state, 0) else: next_state = combat.Combat(deepcopy(temp_state.player), self.get_enemy_encounter()) return (next_state, 0) if state.state_type == StateType.ADD_CARD: if action is not None: temp_state.player.deck.add_card(action) probability = random.uniform(0, 1) if probability <= 0.1: # go to rest next_state = RestSite(deepcopy(temp_state.player)) return (next_state, 0) elif probability <= 0.2: # go to a random event next_state = RandomEvent(deepcopy(temp_state.player)) return (next_state, 0) else: next_state = combat.Combat(deepcopy(temp_state.player), self.get_enemy_encounter()) return (next_state, 0)
def test_text_init(self): "Test the Combat object creation from text" # 1. Create Combat object from text myobj = combat.Combat(text=aoc_15.from_text(EXAMPLE_TEXT)) # 2. Make sure it has the expected values self.assertEqual(myobj.part2, False) self.assertEqual(len(myobj.text), 7) self.assertEqual(len(myobj.cave), 3) self.assertEqual(len(myobj.cave['#']), 27) self.assertEqual(len(myobj.cave['E']), 2) self.assertEqual(len(myobj.cave['G']), 4) self.assertEqual(myobj.cave.max_loc(), 606) self.assertEqual(str(myobj), EXAMPLE_TEXT.strip()) self.assertEqual(myobj.map(), EXAMPLE_TEXT_WITH_HITPOINTS.strip()) # 3. A couple of rounds self.assertEqual(myobj.cave['E'].hitpoints(), 2 * 200) self.assertEqual(myobj.cave['G'].hitpoints(), 4 * 200) myobj.round() self.assertEqual(myobj.cave['E'].hitpoints(), 197 + 197) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 197 + 197) self.assertEqual(str(myobj), EXAMPLE_STEPS_01.strip()) myobj.round() self.assertEqual(myobj.cave['E'].hitpoints(), 188 + 194) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 194 + 194) self.assertEqual(str(myobj), EXAMPLE_STEPS_02.strip()) # 4. And then several more for _ in range(3, 24): assert _ > 0 myobj.round() self.assertEqual(str(myobj), EXAMPLE_STEPS_23.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 131) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 131) myobj.round() # 24 self.assertEqual(str(myobj), EXAMPLE_STEPS_24.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 128) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 128) myobj.round() # 25 self.assertEqual(str(myobj), EXAMPLE_STEPS_25.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 125) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 125) myobj.round() # 26 self.assertEqual(str(myobj), EXAMPLE_STEPS_26.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 122) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 122) myobj.round() # 27 self.assertEqual(str(myobj), EXAMPLE_STEPS_27.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 119) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 119) myobj.round() # 28 self.assertEqual(str(myobj), EXAMPLE_STEPS_28.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 113) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 116) # 5. And then several more again for _ in range(29, 48): assert _ > 0 myobj.round() self.assertEqual(str(myobj), EXAMPLE_STEPS_47.strip()) self.assertEqual(myobj.cave['E'].hitpoints(), 0) self.assertEqual(myobj.cave['G'].hitpoints(), 200 + 200 + 131 + 59)
def start_state(self): actor = player.Player(cards.generate_default_deck(), 80) enemies = deepcopy(random.choice(self.easy_enemies)) start_state = combat.Combat(actor, enemies) return start_state
def test_part1(self): c = combat.Combat(self.input_data) self.assertEqual(306, c.part1())
def activate_monster(self, mon): """Prepare this monster for combat.""" if self.fight: self.fight.activate_monster(mon) else: self.fight = combat.Combat(self, mon)
def test_part2(self): c = combat.Combat(self.input_data) self.assertEqual(1, c.part2())
def init(): global fleet_needs_resupply, current_fleetcomp, quest_item, expedition_item, combat_item, pvp_item, fleetcomp_switcher, default_quest_mode, sleep_cycle, settings settings, sleep_cycle = config_reader.get_config(settings, sleep_cycle) get_util_config() log_success("Config successfully loaded!") log_success("Starting kancolle_auto!") log_msg("Finding window!") focus_window() log_msg("Defining module items!") if settings['quests_enabled']: # Define quest item if quest module is enabled quest_item = quest_module.Quests(global_regions['game'], settings) log_success("Quest module started") if settings['expeditions_enabled']: # Define expedition list if expeditions module is enabled expedition_item = expedition_module.Expedition(global_regions['game'], settings) log_success("Expedition module started") if settings['pvp_enabled']: # Define PvP item if pvp module is enabled pvp_item = combat_module.PvP(global_regions['game'], settings) log_success("Combat module started (PvP mode)") if settings['combat_enabled']: # Define combat item if combat module is enabled combat_item = combat_module.Combat(global_regions['game'], settings) default_quest_mode = 'sortie' log_success("Combat module started (Sortie mode)") if settings['pvp_enabled'] and settings['combat_enabled']: if settings['pvp_fleetcomp'] == 0 or settings['combat_fleetcomp'] == 0: # If either of the fleetcomp values are set to 0, do not define the fleet comp # switcher module pass elif settings['pvp_fleetcomp'] != settings['combat_fleetcomp']: # Define fleet comp switcher module if both pvp and combat modules are enabled # and they have different fleet comps assigned fleetcomp_switcher = combat_module.FleetcompSwitcher(global_regions['game'], settings) # Go home go_home(True) if settings['scheduled_sleep_enabled']: # If just starting script, set a sleep start time now_time = datetime.datetime.now() if now_time.hour * 100 + now_time.minute > int(settings['scheduled_sleep_start']): # If the schedule sleep start time for the day has passed, set it for the next day reset_next_sleep_time(True) else: # Otherwise, set it for later in the day reset_next_sleep_time() if settings['scheduled_stop_enabled'] and settings['scheduled_stop_mode'] == 'time': # If ScheduledStop is enabled and its mode is 'time', set the stop time on script start settings['scheduled_stop_time'] = datetime.datetime.now() + datetime.timedelta(hours=settings['scheduled_stop_count']) if settings['quests_enabled']: # Run through quests defined in quests item quest_action(default_quest_mode, True) if settings['expeditions_enabled']: # Run expeditions defined in expedition item go_home() expedition_item.go_expedition() expedition_action('all') if settings['pvp_enabled']: reset_next_pvp_time() now_time = datetime.datetime.now() if not 3 <= jst_convert(now_time).hour < 5: # Run PvP, but not between the time when PvP resets but quests do not! pvp_action() if settings['combat_enabled']: if settings['quests_enabled'] and settings['pvp_enabled']: # Run through quests defined in quests item quest_action('sortie', True) # Run sortie defined in combat item sortie_action() if settings['quests_enabled']: # Expedition or Combat event occured. Loop 'increases' quest_item.schedule_loop += 1 temp_need_to_check = quest_item.need_to_check() log_msg("Quest check loop count at %s; need to check is %s with %s quests being tracked" % (quest_item.schedule_loop, temp_need_to_check, quest_item.active_quests)) log_msg("Next quest check after %s sortie(s) / %s pvp(s) / %s expedition(s)" % ( quest_item.schedule_sorties[0] - quest_item.done_sorties if len(quest_item.schedule_sorties) > 0 else 0, quest_item.schedule_pvp[0] - quest_item.done_pvp if len(quest_item.schedule_pvp) > 0 else 0, quest_item.schedule_expeditions[0] - quest_item.done_expeditions if len(quest_item.schedule_expeditions) > 0 else 0 )) if temp_need_to_check: go_home() quest_action(default_quest_mode) temp_need_to_check = False # Disable need to check after checking display_timers()
def search_for_exp(fight_count): count = 0 print('寻找经验怪, 同屏找怪5秒') search_t = datetime.datetime.now() while (datetime.datetime.now() - search_t).total_seconds() <= 5: # print(f'找怪第{count}次') exp_loc = myFindColor(TansuoColor.ExpIcon) if exp_loc: print('找到经验怪') # click(exp_loc) accept_invite() combat_loc = myFindColor( ColorToMatch((max(exp_loc[0] - 200, 0), max( exp_loc[1] - 500, 0), exp_loc[0] + 200, exp_loc[1] - 30), [[(0, 0), (229, 230, 248)], [(-14, 31), (237, 163, 172)], [(-23, -13), (66, 77, 132)]], 10)) if combat_loc: logging.debug('找到战斗') click(combat_loc) time.sleep(0.5) if_outof_sushi() combat_loc = myFindColor(TansuoColor.CombatIcon) if combat_loc: logging.debug('进入战斗失败') # check_current_state() return search_for_exp(fight_count) swap_full_exp_mons() this_fight = combat.Combat('探索', combat_time_limit=60 * 1 + random.randint(40, 80)) combat_result = this_fight.start(auto_ready=False) time.sleep(1) wait_for_color(TansuoColor.InDungeon) boss_loc = myFindColor(TansuoColor.CombatBoss) if boss_loc: click(boss_loc) fight_count = fight_count + 1 this_fight = combat.Combat('探索BOSS', combat_time_limit=60 * 1 + random.randint(40, 80)) combat_result = this_fight.start(auto_ready=False) time.sleep(2) loc = wait_for_color(TansuoColor.InDungeon, max_time=3) if loc: logging.info('loot found!') loot_loc = myFindColor(TansuoColor.BossLoot) while loot_loc: logging.info('picking up loot') click(loot_loc, tired_check=True) utilities.random_sleep(0.5, 1) click((90, 943), tired_check=True, random_range=10, need_convert=True) utilities.random_sleep(1.5, 1) loot_loc = myFindColor(TansuoColor.BossLoot) else: logging.info('no loot, enter dungeon') print('完成boss战斗') return TansuoResult.FinishedWithBoss return search_for_exp(fight_count) else: print('未找到战斗') return search_for_exp(fight_count) else: print('未找到经验怪') count = count + 1
def init(): global fleet_needs_resupply, current_fleetcomp, quest_item, expedition_item, combat_item, pvp_item, fleetcomp_switcher, default_quest_mode, settings get_config() get_util_config() log_success("Starting kancolle_auto") try: log_msg("Finding window!") focus_window() log_msg("Defining module items!") if settings['quests_enabled']: # Define quest item if quest module is enabled quest_item = quest_module.Quests(global_regions['game'], settings) if settings['expeditions_enabled']: # Define expedition list if expeditions module is enabled expedition_item = expedition_module.Expedition( global_regions['game'], settings) if settings['pvp_enabled']: # Define PvP item if pvp module is enabled pvp_item = combat_module.PvP(global_regions['game'], settings) if settings['combat_enabled']: # Define combat item if combat module is enabled combat_item = combat_module.Combat(global_regions['game'], settings) default_quest_mode = 'sortie' if settings['pvp_enabled'] and settings['combat_enabled']: if settings['pvp_fleetcomp'] == 0 or settings[ 'combat_fleetcomp'] == 0: # If either of the fleetcomp values are set to 0, do not define the fleet comp # switcher module pass elif settings['pvp_fleetcomp'] != settings['combat_fleetcomp']: # Define fleet comp switcher module if both pvp and combat modules are enabled # and they have different fleet comps assigned fleetcomp_switcher = combat_module.FleetcompSwitcher( global_regions['game'], settings) # Go home go_home(True) if settings['scheduled_sleep_enabled']: # If just starting script, set a sleep start time now_time = datetime.datetime.now() if now_time.hour * 100 + now_time.minute > int( settings['scheduled_sleep_start']): # If the schedule sleep start time for the day has passed, set it for the next day reset_next_sleep_time(True) else: # Otherwise, set it for later in the day reset_next_sleep_time() if settings['quests_enabled']: # Run through quests defined in quests item quest_action(default_quest_mode, True) if settings['expeditions_enabled']: # Run expeditions defined in expedition item go_home() expedition_item.go_expedition() expedition_action('all') if settings['pvp_enabled']: reset_next_pvp_time() now_time = datetime.datetime.now() if not 3 <= jst_convert(now_time).hour < 5: # Run PvP, but not between the time when PvP resets but quests do not! pvp_action() if settings['combat_enabled']: if settings['quests_enabled'] and settings['pvp_enabled']: # Run through quests defined in quests item quest_action('sortie', True) # Run sortie defined in combat item sortie_action() # Let the Quests module know, if it's enabled if settings['quests_enabled']: quest_item.done_sorties += 1 display_timers() except FindFailed, e: refresh_kancolle(e)
#showmenu = 0 if key == "K_SPACE": #If we are selecting the battlesystem option if glb.menu.cursorloc == len(glb.menu.menutext) - 2: menusound.play() showmenu = 0 #next two lines initialize the battle system by making a new battle system glb.battlemenu = battle.BattleMenu(screen.get_size(), glb.cursor, battlescreen, playerlist, enemylist, actionbox, fillcolor=(75, 75, 75)) glb.combat = combat.Combat(playerlist, enemylist) showbattle = 1 #for changing to battle music need music to be stopped pygame.mixer.music.stop() pygame.mixer.music.load( os.path.join(os.getcwd(), "Objects", "battleThemeA.ogg")) pygame.mixer.music.play(-1) if glb.menu.cursorloc == len(glb.menu.menutext) - 1: showmenu = 0 showtiles = 1 menuclosesound.play() #elif menu_screen_xstate != 6: # menu_screen_xstate = 6 #else: