               quest: body.api_quest_name
               enemy: body.api_enemy_info.api_deck_name
               dropShipId: if body.api_get_ship? then body.api_get_ship.api_ship_id else -1
-              deckShipId: Object.clone _decks[deckId].api_ship
-              deckHp: nowHp.slice 0, 6
+              deckShipId: if combined then _decks[0].api_ship.concat(_decks[1].api_ship) else Object.clone _decks[deckId].api_ship
+              deckHp: if combined then _sortieHp.concat(_combinedHp)
               enemyShipId: Object.clone enemyShipId
               enemyFormation: enemyFormation
-              enemyHp: nowHp.slice 6, 12
+              enemyHp: Object.clone _enemyHp
               getEventItem: body.api_get_eventitem?
-          window.dispatchEvent event
-      # Event Combined battle
-      when '/kcsapi/api_req_combined_battle/airbattle'
-        battled = true
-        enemyShipId = body.api_ship_ke.slice 1, 7
-        enemyFormation = body.api_formation[1] if body.api_formation?
-        # TODO: Add hp calculate
-        nowHp = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-      when '/kcsapi/api_req_combined_battle/battle'
-        battled = true
-        enemyShipId = body.api_ship_ke.slice 1, 7
-        enemyFormation = body.api_formation[1] if body.api_formation?
-        # TODO: Add hp calculate
-        nowHp = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-      when '/kcsapi/api_req_combined_battle/midnight_battle'
-        battled = true
-        # TODO: Add hp calculate
-      when '/kcsapi/api_req_combined_battle/sp_midnight'
-        battled = true
-        enemyShipId = body.api_ship_ke.slice 1, 7
-        enemyFormation = body.api_formation[1] if body.api_formation?
-        # TODO: Add hp calculate
-        nowHp = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-      when '/kcsapi/api_req_combined_battle/battle_water'
-        battled = true
-        enemyShipId = body.api_ship_ke.slice 1, 7
-        enemyFormation = body.api_formation[1] if body.api_formation?
-        # TODO: Add hp calculate
-        nowHp = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
-      when '/kcsapi/api_req_combined_battle/battleresult'
-        if battled
-          {_decks} = window
-          event = new CustomEvent 'battle.result',
-            bubbles: true
-            cancelable: true
-            detail:
-              rank: body.api_win_rank
-              boss: bossCell == currentCell or colorNo == 5
-              map: map
-              mapCell: currentCell
-              quest: body.api_quest_name
-              enemy: body.api_enemy_info.api_deck_name
-              dropShipId: if body.api_get_ship? then body.api_get_ship.api_ship_id else -1
-              # TODO
-              # deckShipId: Object.clone _decks[deckId].api_ship
-              # deckHp: nowHp.slice 0, 6
-              enemyShipId: Object.clone enemyShipId
-              enemyFormation: enemyFormation
-              enemyHp: nowHp.slice 6, 12
-              getEventItem: body.api_get_eventitem?
+          console.log event.detail
           window.dispatchEvent event
   catch err
     console.error err

bossCell = -1
currentCell = -1
battled = false
nowHp = []
enemyShipId = []
# Formation: 0 - 単縦陣, 1 - 複縦陣, 2 - 輪形陣, 3 - 梯形陣, 4 - 単横陣,
# 5 - 第一警戒航行序列, 6 - 第二警戒航行序列, 7 - 第三警戒航行序列, 8 - 第四警戒航行序列
enemyFormation = 0
colorNo = -1

koukuAttack = (nowHp, kouku) ->
  if kouku.api_edam?
    for damage, i in kouku.api_edam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i + 5] -= damage
  if kouku.api_fdam?
    for damage, i in kouku.api_fdam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i - 1] -= damage
openAttack = (nowHp, openingAttack) ->
  if openingAttack.api_edam?
    for damage, i in openingAttack.api_edam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i + 5] -= damage
  if openingAttack.api_fdam?
    for damage, i in openingAttack.api_fdam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i - 1] -= damage
hougekiAttack = (nowHp, hougeki) ->
  for damageFrom, i in hougeki.api_at_list
    continue if damageFrom == -1
    for damage, j in hougeki.api_damage[i]
      damage = Math.floor(damage)
      damageTo = hougeki.api_df_list[i][j]
      continue if damage <= 0
      nowHp[damageTo - 1] -= damage
raigekiAttack = (nowHp, raigeki) ->
  if raigeki.api_edam?
    for damage, i in raigeki.api_edam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i + 5] -= damage
  if raigeki.api_fdam?
    for damage, i in raigeki.api_fdam
      damage = Math.floor(damage)
      continue if damage <= 0
      nowHp[i - 1] -= damage
supportAttack = (nowHp, damages) ->
  for damage, i in damages
    damage = Math.floor(damage)
    continue if damage <= 0
    continue if i > 6
    nowHp[i + 5] -= damage

window.addEventListener 'game.response', (e) ->
  {method, path, body, postBody} = e.detail

        enemyShipId = []
        colorNo = -1
        enemyFormation = 0
      # Normal battle
      when '/kcsapi/api_req_sortie/battle', '/kcsapi/api_req_battle_midnight/battle', '/kcsapi/api_req_battle_midnight/sp_midnight', '/kcsapi/api_req_sortie/airbattle'
        battled = true
        combined = false
        _sortieHp = body.api_nowhps.slice(1, 7)
        _enemyHp = body.api_nowhps.slice(7, 13)
        enemyShipId = body.api_ship_ke.slice(1, 7)
        enemyFormation = body.api_formation[1]
        analogBattle _sortieHp, _enemyHp, _combinedHp, false, false, body
        console.log [_sortieHp, _combinedHp, _enemyHp]
      # Event Combined battle
      when '/kcsapi/api_req_combined_battle/airbattle', '/kcsapi/api_req_combined_battle/battle', '/kcsapi/api_req_combined_battle/midnight_battle', '/kcsapi/api_req_combined_battle/sp_midnight'
        battled = true
        combined = true
        _sortieHp = body.api_nowhps.slice(1, 7)
        _combinedHp = body.api_nowhps_combined.slice(1, 7)
        _enemyHp = body.api_nowhps.slice(7, 13)
        enemyShipId = body.api_ship_ke.slice(1, 7)
        enemyFormation = body.api_formation[1]
        analogBattle _sortieHp, _enemyHp, _combinedHp, true, false, body
        console.log [_sortieHp, _combinedHp, _enemyHp]
      when '/kcsapi/api_req_combined_battle/battle_water'
        battled = true
        combined = true
        _sortieHp = body.api_nowhps.slice(1, 7)
        _combinedHp = body.api_nowhps_combined.slice(1, 7)
        _enemyHp = body.api_nowhps.slice(7, 13)
        enemyShipId = body.api_ship_ke.slice(1, 7)
        enemyFormation = body.api_formation[1]
        analogBattle _sortieHp, _enemyHp, _combinedHp, true, true, body
        console.log [_sortieHp, _combinedHp, _enemyHp]
      when '/kcsapi/api_req_sortie/battleresult', '/kcsapi/api_req_combined_battle/battleresult'
        if battled
          {_decks} = window
          event = new CustomEvent 'battle.result',
