perryhuynh / kcauto

kcauto, the successor to kancolle-auto, a Kantai Collection (Kancolle) bot/automation tool
GNU General Public License v3.0
68 stars 22 forks source link

Crashing when updating ship HPs in combined fleet with less than 12 ships #412

Closed perryhuynh closed 4 years ago

perryhuynh commented 4 years ago

Issue variability

Consistent

Issue

When using a combined fleet with <6 ships in the main fleet kcauto uses the wrong indexes to calculate hps and update hps, leading to an index out of range error.

Sample API response:

"api_f_nowhps": [
    43,
    56,
    57,
    56
],
"api_f_maxhps": [
    43,
    56,
    57,
    56
],
"api_f_nowhps_combined": [
    31,
    33,
    31,
    51,
    32
],
"api_f_maxhps_combined": [
    31,
    33,
    31,
    51,
    32
],

Log

[2019-12-06 05:46:03] Fleet 1 / No Damage fleet damage / No Fatigue
Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "kcauto/__main__.py", line 19, in <module>
    kcauto_main()
  File "kcauto/kcauto_wrapper.py", line 34, in kcauto_main
    _.kcauto.run_combat_logic()
  File "kcauto/kcauto.py", line 124, in run_combat_logic
    if com.combat.conduct_sortie():
  File "kcauto/combat/combat_core.py", line 174, in conduct_sortie
    return self._conduct_sortie(cfg.config.combat.sortie_map)
  File "kcauto/combat/combat_core.py", line 197, in _conduct_sortie
    self._handle_combat(sortie_map)
  File "kcauto/combat/combat_core.py", line 277, in _handle_combat
    at_combat_node = self._cycle_between_nodes(sortie_map)
  File "kcauto/combat/combat_core.py", line 373, in _cycle_between_nodes
    api.api.update_from_api(self.COMBAT_APIS, need_all=False)
  File "kcauto/api/api_core.py", line 88, in update_from_api
    request_data, json.loads(raw_svdata))
  File "kcauto/api/api_core.py", line 152, in _load_api_data
    return self._process_battle(data)
  File "kcauto/api/api_core.py", line 294, in _process_battle
    com.combat.predict_battle(battle_data)
  File "kcauto/combat/combat_core.py", line 536, in predict_battle
    flt.fleets.combat_fleets[1].update_ship_hps(new_hps[6:12])
  File "kcauto/fleet/fleet.py", line 211, in update_ship_hps
    ship.hp = hps[idx]
IndexError: list index out of range
mrmin123 commented 4 years ago

I hate their API.

mrmin123 commented 4 years ago

Should be fixed now in the event branch.

perryhuynh commented 4 years ago

@mrmin123

Traceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "kcauto/__main__.py", line 19, in <module>
    kcauto_main()
  File "kcauto/kcauto_wrapper.py", line 34, in kcauto_main
    _.kcauto.run_combat_logic()
  File "kcauto/kcauto.py", line 124, in run_combat_logic
    if com.combat.conduct_sortie():
  File "kcauto/combat/combat_core.py", line 174, in conduct_sortie
    return self._conduct_sortie(cfg.config.combat.sortie_map)
  File "kcauto/combat/combat_core.py", line 197, in _conduct_sortie
    self._handle_combat(sortie_map)
  File "kcauto/combat/combat_core.py", line 277, in _handle_combat
    at_combat_node = self._cycle_between_nodes(sortie_map)
  File "kcauto/combat/combat_core.py", line 373, in _cycle_between_nodes
    api.api.update_from_api(self.COMBAT_APIS, need_all=False)
  File "kcauto/api/api_core.py", line 88, in update_from_api
    request_data, json.loads(raw_svdata))
  File "kcauto/api/api_core.py", line 152, in _load_api_data
    return self._process_battle(data)
  File "kcauto/api/api_core.py", line 294, in _process_battle
    com.combat.predict_battle(battle_data)
  File "kcauto/combat/combat_core.py", line 531, in predict_battle
    new_hps = self._calculate_hps(new_hps, data)
  File "kcauto/combat/combat_core.py", line 557, in _calculate_hps
    new_hps = self._calculate_hps_from_type1(new_hps, data[phase])
  File "kcauto/combat/combat_core.py", line 572, in _calculate_hps_from_type1
    hps[target] -= dmgs[idx][t_idx]
IndexError: list index out of range

Didn't happen until the 2nd battle

    "api_result": 1,
    "api_result_msg": "\u6210\u529f",
    "api_data": {
        "api_deck_id": 1,
        "api_formation": [
            14,
            2,
            2
        ],
        "api_f_nowhps": [
            50,
            56,
            56,
            57,
            48
        ],
        "api_f_maxhps": [
            50,
            56,
            56,
            57,
            48
        ],
        "api_f_nowhps_combined": [
            18,
            31,
            51,
            11,
            26
        ],
        "api_f_maxhps_combined": [
            32,
            31,
            51,
            31,
            33
        ],
        "api_fParam": [
            [
                29,
                0,
                69,
                59
            ],
            [
                82,
                84,
                74,
                79
            ],
            [
                80,
                84,
                83,
                78
            ],
            [
                84,
                84,
                72,
                77
            ],
            [
                68,
                84,
                75,
                68
            ]
        ],
        "api_fParam_combined": [
            [
                59,
                89,
                59,
                59
            ],
            [
                68,
                88,
                70,
                51
            ],
            [
                72,
                98,
                68,
                69
            ],
            [
                62,
                96,
                64,
                51
            ],
            [
                55,
                80,
                76,
                56
            ]
        ],
        "api_ship_ke": [
            1554,
            1527,
            1527,
            1591,
            1576,
            1576
        ],
        "api_ship_lv": [
            1,
            1,
            1,
            1,
            1,
            1
        ],
        "api_e_nowhps": [
            53,
            76,
            76,
            48,
            37,
            37
        ],
        "api_e_maxhps": [
            53,
            76,
            76,
            48,
            37,
            37
        ],
        "api_eSlot": [
            [
                504,
                542,
                543,
                -1,
                -1
            ],
            [
                505,
                506,
                515,
                525,
                -1
            ],
            [
                505,
                506,
                515,
                525,
                -1
            ],
            [
                550,
                550,
                545,
                525,
                -1
            ],
            [
                502,
                545,
                542,
                -1,
                -1
            ],
            [
                502,
                545,
                542,
                -1,
                -1
            ]
        ],
        "api_eParam": [
            [
                42,
                72,
                27,
                36
            ],
            [
                68,
                48,
                40,
                70
            ],
            [
                68,
                48,
                40,
                70
            ],
            [
                58,
                84,
                88,
                55
            ],
            [
                38,
                66,
                32,
                26
            ],
            [
                38,
                66,
                32,
                26
            ]
        ],
        "api_midnight_flag": 1,
        "api_search": [
            1,
            1
        ],
        "api_stage_flag": [
            1,
            1,
            1
        ],
        "api_kouku": {
            "api_plane_from": [
                [
                    1
                ],
                null
            ],
            "api_stage1": {
                "api_f_count": 66,
                "api_f_lostcount": 0,
                "api_e_count": 0,
                "api_e_lostcount": 0,
                "api_disp_seiku": 1,
                "api_touch_plane": [
                    239,
                    -1
                ]
            },
            "api_stage2": {
                "api_f_count": 18,
                "api_f_lostcount": 8,
                "api_e_count": 0,
                "api_e_lostcount": 0
            },
            "api_stage3": {
                "api_frai_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_erai_flag": [
                    0,
                    0,
                    1,
                    0,
                    0,
                    0
                ],
                "api_fbak_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_ebak_flag": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_fcl_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_ecl_flag": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_fdam": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_edam": [
                    0,
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            },
            "api_stage3_combined": {
                "api_frai_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_fbak_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_fcl_flag": [
                    0,
                    0,
                    0,
                    0,
                    0
                ],
                "api_fdam": [
                    0,
                    0,
                    0,
                    0,
                    0
                ]
            }
        },
        "api_support_flag": 0,
        "api_support_info": null,
        "api_opening_taisen_flag": 0,
        "api_opening_taisen": null,
        "api_opening_flag": 0,
        "api_opening_atack": null,
        "api_hourai_flag": [
            1,
            0,
            1,
            1
        ],
        "api_hougeki1": {
            "api_at_eflag": [
                0,
                1,
                0,
                1,
                0,
                1,
                0,
                1,
                0,
                1
            ],
            "api_at_list": [
                1,
                1,
                2,
                3,
                3,
                2,
                4,
                0,
                0,
                5
            ],
            "api_at_type": [
                2,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ],
            "api_df_list": [
                [
                    4,
                    4
                ],
                [
                    2
                ],
                [
                    2
                ],
                [
                    1
                ],
                [
                    3
                ],
                [
                    1
                ],
                [
                    0
                ],
                [
                    2
                ],
                [
                    1
                ],
                [
                    4
                ]
            ],
            "api_si_list": [
                [
                    "50",
                    "90"
                ],
                [
                    505
                ],
                [
                    50
                ],
                [
                    550
                ],
                [
                    90
                ],
                [
                    505
                ],
                [
                    50
                ],
                [
                    504
                ],
                [
                    -1
                ],
                [
                    502
                ]
            ],
            "api_cl_list": [
                [
                    1,
                    1
                ],
                [
                    0
                ],
                [
                    1
                ],
                [
                    1
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    2
                ],
                [
                    0
                ]
            ],
            "api_damage": [
                [
                    130,
                    130
                ],
                [
                    0.1
                ],
                [
                    39
                ],
                [
                    6
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    0
                ],
                [
                    158
                ],
                [
                    0
                ]
            ]
        },
        "api_hougeki3": {
            "api_at_eflag": [
                0,
                1,
                0,
                1,
                0,
                1,
                0,
                1,
                0
            ],
            "api_at_list": [
                7,
                0,
                8,
                3,
                6,
                2,
                9,
                5,
                10
            ],
            "api_at_type": [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ],
            "api_df_list": [
                [
                    3
                ],
                [
                    9
                ],
                [
                    0
                ],
                [
                    10
                ],
                [
                    3
                ],
                [
                    9
                ],
                [
                    5
                ],
                [
                    9
                ],
                [
                    2
                ]
            ],
            "api_si_list": [
                [
                    266
                ],
                [
                    504
                ],
                [
                    50
                ],
                [
                    550
                ],
                [
                    122
                ],
                [
                    505
                ],
                [
                    -1
                ],
                [
                    502
                ],
                [
                    -1
                ]
            ],
            "api_cl_list": [
                [
                    1
                ],
                [
                    0
                ],
                [
                    1
                ],
                [
                    0
                ],
                [
                    2
                ],
                [
                    0
                ],
                [
                    1
                ],
                [
                    1
                ],
                [
                    1
                ]
            ],
            "api_damage": [
                [
                    26.1
                ],
                [
                    0
                ],
                [
                    62
                ],
                [
                    0
                ],
                [
                    70
                ],
                [
                    0
                ],
                [
                    16
                ],
                [
                    0
                ],
                [
                    2
                ]
            ]
        },
        "api_raigeki": {
            "api_frai": [
                -1,
                -1,
                -1,
                -1,
                -1,
                -1,
                2,
                2,
                2,
                -1,
                2,
                -1
            ],
            "api_fcl": [
                0,
                0,
                0,
                0,
                0,
                0,
                1,
                1,
                1,
                0,
                1,
                0
            ],
            "api_fdam": [
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ],
            "api_fydam": [
                0,
                0,
                0,
                0,
                0,
                0,
                18,
                2,
                3,
                0,
                1,
                0
            ],
            "api_erai": [
                -1,
                -1,
                -1,
                -1,
                -1,
                9,
                -1
            ],
            "api_ecl": [
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ],
            "api_edam": [
                0,
                0,
                24,
                0,
                0,
                0,
                0
            ],
            "api_eydam": [
                0,
                0,
                0,
                0,
                0,
                0,
                0
            ]
        }
    }
}

here's the entire battle_water response

mrmin123 commented 4 years ago

@perryhuynh can you DM me the replay file for when this happened?