OSDN Git Service

guard の書き方を統一した
[kcd/KCD.git] / KCD / BattleCommand.swift
1 //
2 //  BattleCommand.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/01/18.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 enum BattleAPI: String {
12     
13     case battle = "/kcsapi/api_req_sortie/battle"
14     
15     case combinedBattle = "/kcsapi/api_req_combined_battle/battle"
16     case combinedAirBattle = "/kcsapi/api_req_combined_battle/airbattle"
17     case combinedBattleWater = "/kcsapi/api_req_combined_battle/battle_water"
18     case combinedEcBattle = "/kcsapi/api_req_combined_battle/ec_battle"
19     case combinedEachBattle = "/kcsapi/api_req_combined_battle/each_battle"
20     case combinedEachBattleWater = "/kcsapi/api_req_combined_battle/each_battle_water"
21     
22     case airBattle = "/kcsapi/api_req_sortie/airbattle"
23     case ldAirBattle = "/kcsapi/api_req_sortie/ld_airbattle"
24     case combinedLdAirBattle = "/kcsapi/api_req_combined_battle/ld_airbattle"
25     
26     case midnightBattle = "/kcsapi/api_req_battle_midnight/battle"
27     case midnightSpMidnight = "/kcsapi/api_req_battle_midnight/sp_midnight"
28     case combinedEcMidnightBattle = "/kcsapi/api_req_combined_battle/ec_midnight_battle"
29     case combinedMidnightBattle = "/kcsapi/api_req_combined_battle/midnight_battle"
30     case combinedSpMidnight = "/kcsapi/api_req_combined_battle/sp_midnight"
31     
32     case battleResult = "/kcsapi/api_req_sortie/battleresult"
33     case combinedBattleResult = "/kcsapi/api_req_combined_battle/battleresult"
34 }
35
36 final class BattleCommand: JSONCommand {
37     
38     override class func canExecuteAPI(_ api: String) -> Bool {
39         
40         return BattleAPI(rawValue: api) != nil
41     }
42     
43     override func execute() {
44         
45         CalculateDamageCommand(apiResponse: apiResponse).execute()
46         
47         guard let battleApi = BattleAPI(rawValue: apiResponse.api) else { return }
48         
49         switch battleApi {
50         case .battleResult, .combinedBattleResult:
51             DropShipHistoryCommand(apiResponse: apiResponse).execute()
52             DummyShipCommand(apiResponse: apiResponse).execute()
53             GuardShelterCommand(apiResponse: apiResponse).execute()
54             
55         default: break
56         }
57     }
58 }