Skip to content

Commit

Permalink
Merge pull request #94 from XVs32/87-load-the-recorded-equipment-of-e…
Browse files Browse the repository at this point in the history
…very-ship

87 load the recorded equipment of every ship
  • Loading branch information
XVs32 committed Feb 13, 2024
2 parents 72150eb + 61a88da commit 8e70bf8
Show file tree
Hide file tree
Showing 30 changed files with 578 additions and 89 deletions.
Binary file modified assets/combat/lbas_group_mode_air_defense.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_mode_rest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_mode_retreat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_mode_sortie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_mode_standby.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_tab_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_tab_1_only.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_tab_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/combat/lbas_group_tab_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/1_slot_ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/2_slot_ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/3_slot_ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/4_slot_ship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/equipment_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/equipment_sort_all.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/shipswitcher/equipment_sort_arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 59 additions & 7 deletions data/expedition/expedition_preset.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,60 @@
{
"active": [[2],[3],[6]],
"passive": [[5],[21],[38]],
"overnight": [[11],[24],[38]],
"auto": [["auto"],["auto"],["auto"]],
"user": [[],[2],[3]],
"disable": [[],[],[]]
}
"active": [
[
2
],
[
3
],
[
6
]
],
"passive": [
[
5
],
[
21
],
[
38
]
],
"overnight": [
[
11
],
[
24
],
[
38
]
],
"auto": [
[
"auto"
],
[
"auto"
],
[
"auto"
]
],
"user": [
[
10
],
[
4
],
[]
],
"disable": [
[],
[],
[]
]
}
35 changes: 35 additions & 0 deletions kcauto/api/api_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def __init__(self):

def update_from_api(
self, target_apis={KCSAPIEnum.ANY}, need_all=True, timeout=30):
"""
method to read the APIs in queue, all APIs in queue currently will be removed after this method is finished
"""
if KCSAPIEnum.NONE in target_apis:
return

Expand Down Expand Up @@ -193,6 +196,8 @@ def _load_api_data(self, request_data, data):
return self._process_battle_result(data)
elif request_type is KCSAPIEnum.SORTIE_SHIPDECK:
return self._process_battle_deck(data)
elif request_type is KCSAPIEnum.SORTIE_END:
return self._process_equipment_data(data)
elif request_type is KCSAPIEnum.EXPEDITION_LIST:
return self._process_expedition_list(data)
elif request_type is KCSAPIEnum.EXPEDITION_START:
Expand All @@ -211,13 +216,22 @@ def _load_api_data(self, request_data, data):
return True
elif request_type is KCSAPIEnum.LBAS_RESUPPLY_ACTION:
return True
elif request_type is KCSAPIEnum.FREE_EQUIPMENT:
return self._process_free_equipment_data(data)


return None

def _process_get_data(self, data):
try:
get_data_ship = data['api_data']['api_mst_ship']
shp.ships.update_ship_library(get_data_ship)
JsonData.dump_json(get_data_ship, 'data|temp|get_data_ship.json')

equ.equipment.reinforce_general_category = data['api_data']['api_mst_equip_exslot']
equ.equipment.reinforce_special = data['api_data']['api_mst_equip_exslot_ship']
JsonData.dump_json(equ.equipment.reinforce_general_category, 'data|temp|reinforce_general_category.json')
JsonData.dump_json(equ.equipment.reinforce_special, 'data|temp|reinforce_special.json')
except KeyError:
Log.log_debug("No getData found in API response.")

Expand Down Expand Up @@ -410,5 +424,26 @@ def update_ship_library_from_json(self):
Log.log_error(e)
sys.exit(1)

def _process_equipment_data(self, data):
try:
JsonData.dump_json(data['api_data'], 'data|temp|equipment_list.json')
except KeyError:
Log.log_debug("No equipment found in API response.")


def _process_free_equipment_data(self, data):
equ.equipment.equipment['raw'] = {}
equ.equipment.equipment['free'] = []
try:
equ.equipment.equipment['raw'] = data['api_data']['api_slot_data']
keys = equ.equipment.equipment['raw'].keys()
sorted_keys = sorted(keys, key=lambda x: (len(x), x))
for key in sorted_keys:
equ.equipment.equipment['free'] = equ.equipment.equipment['free'] + data['api_data']['api_slot_data'][key]

except KeyError:
Log.log_debug("No provisional equipment data found in API response")

#Log.log_debug(free_equipment)

api = ApiWrapper()
6 changes: 6 additions & 0 deletions kcauto/args/args_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ def __init__(self):
help=(
"similarity to search asset with in debug mode; defaults to "
f"{DEFAULT}"))
self.parser.add_argument(
'--save-equipment', action='store_true',
help="save current equipment config")
self.parser.add_argument(
'--load-equipment', type=str, action='store',
help="load current equipment config")

def parse_args(self):
self.parsed_args = self.parser.parse_args()
Expand Down
40 changes: 22 additions & 18 deletions kcauto/combat/combat_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CombatCore(CoreBase):
}
RESULT_APIS = {KCSAPIEnum.SORTIE_RESULT, KCSAPIEnum.SORTIE_CF_RESULT}
SHIPDECK_API = {KCSAPIEnum.SORTIE_SHIPDECK}
EQUIP_API = {KCSAPIEnum.SORTIE_END}
API_COMBAT_PHASES_TYPE1 = (
'api_hougeki', 'api_hougeki1', 'api_hougeki2', 'api_hougeki3')
API_COMBAT_PHASES_TYPE2 = ('api_opening_atack', 'api_raigeki')
Expand All @@ -56,6 +57,7 @@ class CombatCore(CoreBase):
NODE_TYPE_COMBAT_FINISH = 2
NODE_TYPE_SELECT = 3
NODE_TYPE_NOTHING = 4
NODE_TYPE_FORMATION_SKIP = 5
module_name = 'combat'
module_display_name = 'Combat'
available_maps = {}
Expand Down Expand Up @@ -350,7 +352,9 @@ def _handle_combat(self, sortie_map):
# Go to next acrion needed node
node_type = self._cycle_between_nodes(sortie_map)

if node_type == self.NODE_TYPE_COMBAT or node_type == self.NODE_TYPE_COMBAT_FINISH :
if node_type == self.NODE_TYPE_COMBAT \
or node_type == self.NODE_TYPE_COMBAT_FINISH \
or node_type == self.NODE_TYPE_FORMATION_SKIP :

Log.log_msg(f"Combat at node {self.current_node}.")

Expand All @@ -363,15 +367,15 @@ def _handle_combat(self, sortie_map):

self.combat_nodes_run.append(self.current_node)

if self.current_node.boss_node or self.boss_api:
#Todo: only trigger when screen doesn't change at all
kca_u.kca.sleep(8)
Log.log_msg("Dismissing boss dialogue.")
kca_u.kca.r['center'].click()

while not kca_u.kca.exists(
'lower_right_corner', 'global|next.png'):

if self.current_node.boss_node or self.boss_api:
#Todo: only trigger when screen doesn't change at all
Log.log_msg("Dismissing boss dialogue.")
kca_u.kca.r['center'].click()
kca_u.kca.sleep(3)

if kca_u.kca.exists('kc', 'global|combat_nb_fight.png'):
Log.log_debug("Night battle prompt.")

Expand Down Expand Up @@ -405,26 +409,24 @@ def _handle_combat(self, sortie_map):
kca_u.kca.r['combat_click'].click()
kca_u.kca.sleep()

if flt.fleets.combined_fleet:
if kca_u.kca.exists('lower', 'combat|fcf_retreat_ship.png'):
Log.log_error("FCF prompt is not supported yet. T^T")
# self._resolve_fcf_prompt()

if kca_u.kca.exists('kc', 'combat|combat_retreat.png'):
if kca_u.kca.exists('lower', 'combat|fcf_retreat_ship.png'):
Log.log_error("FCF prompt is not supported yet. T^T")
# self._resolve_fcf_prompt()
elif kca_u.kca.exists('kc', 'combat|combat_retreat.png'):
Log.log_debug("Continue sortie prompt.")
if self._resolve_continue_sortie_prompt():
Log.log_debug("Continue button pressed")
continue
#api.api.update_from_api({KCSAPIEnum.SORTIE_SHIPDECK})
else:
kca_u.kca.wait('left', 'nav|home_menu_sortie.png')
conducting_sortie = False
continue
elif kca_u.kca.exists(
'lower_right', 'combat|combat_flagship_dmg.png'):
Log.log_debug("Flagship heavily damaged.")
conducting_sortie = False
continue
elif kca_u.kca.exists('left', 'nav|home_menu_sortie.png'):
Log.log_debug("backed to port.")
conducting_sortie = False

elif node_type == self.NODE_TYPE_SELECT:
kca_u.kca.sleep()
Expand Down Expand Up @@ -456,15 +458,15 @@ def _handle_combat(self, sortie_map):
def _click_until_port(self):
while not kca_u.kca.exists('left', 'nav|home_menu_sortie.png'):
api_result = api.api.update_from_api(
{KCSAPIEnum.PORT}, need_all=False, timeout=3)
{KCSAPIEnum.PORT} | self.SHIPDECK_API | self.EQUIP_API, need_all=False, timeout=3)
if KCSAPIEnum.PORT.name not in api_result:
kca_u.kca.r['combat_click'].click()

def _next_node_handler(self):

while self.combat_api_listener_enable:
api_result = api.api.update_from_api(
self.COMBAT_APIS | self.RESULT_APIS | self.SHIPDECK_API, need_all=False, timeout=5)
self.COMBAT_APIS | self.RESULT_APIS | self.SHIPDECK_API | self.EQUIP_API, need_all=True, timeout=5)
if KCSAPIEnum.SORTIE_NEXT.name in api_result:
self._find_next_node(
api_result[KCSAPIEnum.SORTIE_NEXT.name][0])
Expand Down Expand Up @@ -496,6 +498,8 @@ def _cycle_between_nodes(self, sortie_map):
elif kca_u.kca.exists('lower_right_corner', 'global|next_alt.png'):
# resource node end
return self.NODE_TYPE_END
elif kca_u.kca.exists('kc', 'global|combat_nb_fight.png'):
return self.NODE_TYPE_FORMATION_SKIP
elif kca_u.kca.exists('left', 'nav|home_menu_sortie.png'):
# back at home already
return self.NODE_TYPE_END
Expand Down
54 changes: 34 additions & 20 deletions kcauto/fleet_switcher/fleet_switcher_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ def switch_fleet(self, context):
elif context == 'factory_develop':
Log.log_msg(f"Switching to {cfg.config.factory.develop_secretary} for develop.")

ssw.ship_switcher.current_shipcomp_page = 1
ssw.ship_switcher.current_page = 1
ssw.ship_switcher.switch_slot_by_id(1,cfg.config.factory.develop_secretary)
elif context == 'factory_build':
Log.log_msg(f"Switching to {cfg.config.factory.build_secretary} for construction.")

ssw.ship_switcher.current_shipcomp_page = 1
ssw.ship_switcher.current_page = 1
ssw.ship_switcher.switch_slot_by_id(1,cfg.config.factory.build_secretary)

else:
Expand Down Expand Up @@ -485,31 +485,45 @@ def switch_to_costom_fleet(self, fleet_id, ship_list):
ship_list(int list): ships to use
"""
EMPTY = -1
retry = 0

flt.fleets.fleets[fleet_id].select()

empty_slot_count = 0
while True:

size = max(len(flt.fleets.fleets[fleet_id].ship_ids), len(ship_list))
for i in range(1,size + 1):
if i > len(ship_list):
id = EMPTY #remove this slot
else:
id = ship_list[i - 1]
flt.fleets.fleets[fleet_id].select()

empty_slot_count = 0

if i <= len(flt.fleets.fleets[fleet_id].ship_ids) and \
id == flt.fleets.fleets[fleet_id].ship_ids[i-1]:
continue
size = max(len(flt.fleets.fleets[fleet_id].ship_ids), len(ship_list))
for i in range(1,size + 1):
if i > len(ship_list):
id = EMPTY #remove this slot
else:
id = ship_list[i - 1]

if i <= len(flt.fleets.fleets[fleet_id].ship_ids) and \
id == flt.fleets.fleets[fleet_id].ship_ids[i-1]:
continue

if not ssw.ship_switcher.switch_slot_by_id(i-empty_slot_count,id):
#fleet data update
retry += 1
break
else:
retry = 0

if id == EMPTY:
empty_slot_count += 1

if not ssw.ship_switcher.switch_slot_by_id(i-empty_slot_count,id):
#fleet data update
if retry == 1:
Log.log_msg(f"retrying...")
nav.navigate.to('home')
self.goto()
continue
elif retry > 1:
return False

if id == EMPTY:
empty_slot_count += 1

else:
break

return True

def _scroll_preset_list(self, target_clicks):
Expand Down
2 changes: 2 additions & 0 deletions kcauto/kca_enums/kcsapi_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class KCSAPIEnum(EnumBase):
SORTIE_CF_ECF_LD_SHOOTING = (
'kcsapi/api_req_combined_battle/each_ld_shooting')
SORTIE_CF_RESULT = 'kcsapi/api_req_combined_battle/battleresult'
# sortie endpoint
SORTIE_END = 'kcsapi/api_get_member/slot_item'
# pvp
PVP_ENEMY_INFO = 'kcsapi/api_req_member/get_practice_enemyinfo'
PVP_RESULTS = 'kcsapi/api_req_practice/battle_result'
Expand Down
4 changes: 4 additions & 0 deletions kcauto/kca_enums/ship_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ def type(self):
@property
def display_name(self):
return self.name

@property
def id(self):
return self.value
Loading

0 comments on commit 8e70bf8

Please sign in to comment.