Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #103 from mrmin123/86_fleet_switch
Browse files Browse the repository at this point in the history
related to #86: fleet switching ability for pvp and combat
  • Loading branch information
mrmin123 committed Jan 22, 2016
2 parents 0c6e841 + 1049f59 commit 372d88d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 5 deletions.
10 changes: 10 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,21 @@ Fleet4: 21
# will be selected for everything, regardless of enemy fleet...
Enabled: True

# Specify which saved fleet composition should be used for PvP, with the first saved fleet being 1.
# NOTE: this value is only relevant if both PvP and Combat modules are enabled! Setting the
# FleetComp value to 0 for either module will disable the fleet composition switcher.
FleetComp: 1


[Combat]
# Set to True if you want Fleet 1 to run combat sorties; False if not.
Enabled: False

# Specify which saved fleet composition should be used for Combat, with the first saved fleet
# being 1. NOTE: this value is only relevant if both PvP and Combat modules are enabled! Setting
# the FleetComp value to 0 for either module will disable the fleet composition switcher.
FleetComp: 2

# Set which area you want to sortie to.
# Example 1: if you're running 3-2-A, set this to '3'
# Example 2: if you're running 2-3 (Orel), set this to '2'
Expand Down
14 changes: 14 additions & 0 deletions kancolle_auto.sikuli/combat.sikuli/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,17 @@ def go_pvp(self):
wait_and_click(self.kc_window, 'next.png', 30, expand_areas('next'))
log_msg("PvP complete!")
return True

class FleetcompSwitcher:
def __init__(self, kc_window, settings):
self.kc_window = kc_window

def switch_fleetcomp(self, fleetcomp):
# Navigate to the fleetcomp page, then enter the fleetcomp screen
rnavigation(self.kc_window, 'fleetcomp')
wait_and_click(self.kc_window, 'fleetcomp_screen.png', 30)
self.kc_window.wait('fleetcomp_button_offset.png', 30)
# the button_offset image is located 50 pixels above the first button,
# and each subsequent buttons are situated 52 pixels apart vertically
target_button = Pattern('fleetcomp_button_offset.png').targetOffset(randint(-15, 15), 50 + (52 * (fleetcomp - 1)) + randint(-8, 8))
self.kc_window.click(target_button)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 30 additions & 5 deletions kancolle_auto.sikuli/kancolle_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
'expedition_id_fleet_map': {}
}
fleet_returned = [False, False, False, False]
current_fleetcomp = 0
quest_item = None
expedition_item = None
combat_item = None
pvp_item = None
fleetcomp_switcher = None
quest_reset_skip = False
pvp_skip = False
kc_window = None
Expand Down Expand Up @@ -68,7 +70,7 @@ def go_home(refresh=False):
# the Home screen. Go straight to resupplying fleets
resupply()
elif refresh:
# We're at home, but if we're do for a refresh, refresh
# We're at home, but if we're due for a refresh, refresh
rnavigation(kc_window, 'refresh_home')
# Check for completed expeditions. Resupply them if there are.
if check_expedition():
Expand Down Expand Up @@ -174,6 +176,8 @@ def expedition_action(fleet_id):
# Actions involved in conducting PvPs
def pvp_action():
global kc_window, pvp_item, settings
# Switch fleet comp, if necessary
fleetcomp_switch_action(settings['pvp_fleetcomp'])
go_home()
while pvp_item.go_pvp():
fleet_returned[0] = True
Expand All @@ -187,7 +191,8 @@ def pvp_action():
# Actions involved in conducting sorties
def sortie_action():
global kc_window, fleet_returned, combat_item, settings
go_home(True)
fleetcomp_switch_action(settings['combat_fleetcomp'])
go_home()
combat_item.go_sortie()
fleet_returned[0] = True
# Check home, repair if needed, and resupply
Expand All @@ -198,6 +203,16 @@ def sortie_action():
fleet_returned[0] = False
log_success("Next sortie!: %s" % combat_item)

# Actions that check and switch fleet comps
def fleetcomp_switch_action(fleetcomp):
global kc_window, current_fleetcomp, fleetcomp_switcher, settings
if fleetcomp_switcher and fleetcomp != current_fleetcomp:
# fleetcomp_switcher is defined (aka necessary) AND the needed fleetcomp
# is different from the current fleetcomp, go home then switch fleets
go_home()
fleetcomp_switcher.switch_fleetcomp(fleetcomp)
current_fleetcomp = fleetcomp

# Determine when the next automated action will be, whether it's a sortie or
# expedition action (currently disregards quests and PvP)
def check_soonest():
Expand Down Expand Up @@ -248,11 +263,13 @@ def get_config():
# 'PvP' section
if config.getboolean('PvP', 'Enabled'):
settings['pvp_enabled'] = True
settings['pvp_fleetcomp'] = config.getint('PvP', 'FleetComp')
else:
settings['pvp_enabled'] = False
# 'Combat' section
if config.getboolean('Combat', 'Enabled'):
settings['combat_enabled'] = True
settings['combat_fleetcomp'] = config.getint('Combat', 'FleetComp')
settings['combat_area'] = config.getint('Combat', 'Area')
settings['combat_subarea'] = config.getint('Combat', 'Subarea')
settings['nodes'] = config.getint('Combat', 'Nodes')
Expand Down Expand Up @@ -330,7 +347,7 @@ def refresh_kancolle(e):
raise

def init():
global kc_window, fleet_returned, quest_item, expedition_item, combat_item, pvp_item, settings
global kc_window, fleet_returned, current_fleetcomp, quest_item, expedition_item, combat_item, pvp_item, fleetcomp_switcher, settings
get_config()
get_util_config()
log_success("Starting kancolle_auto")
Expand All @@ -350,6 +367,15 @@ def init():
if settings['combat_enabled']:
# Define combat item if combat module is enabled
combat_item = combat_module.Combat(kc_window, settings)
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(kc_window, settings)
# Go home
go_home(True)
if settings['quests_enabled']:
Expand All @@ -361,8 +387,7 @@ def init():
if settings['pvp_enabled']:
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!
# Run PvP, but not between the time when PvP resets but quests do not!
pvp_action()
if settings['combat_enabled']:
# Run sortie defined in combat item
Expand Down

0 comments on commit 372d88d

Please sign in to comment.