OSDN Git Service

41a90b43a4d5048dda47cfc38f6b7f7efbf9a156
[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 combinedEachNightToDay = "/kcsapi/api_req_combined_battle/ec_night_to_day"
23     
24     case airBattle = "/kcsapi/api_req_sortie/airbattle"
25     case ldAirBattle = "/kcsapi/api_req_sortie/ld_airbattle"
26     case combinedLdAirBattle = "/kcsapi/api_req_combined_battle/ld_airbattle"
27     
28     case midnightBattle = "/kcsapi/api_req_battle_midnight/battle"
29     case midnightSpMidnight = "/kcsapi/api_req_battle_midnight/sp_midnight"
30     case combinedEcMidnightBattle = "/kcsapi/api_req_combined_battle/ec_midnight_battle"
31     case combinedMidnightBattle = "/kcsapi/api_req_combined_battle/midnight_battle"
32     case combinedSpMidnight = "/kcsapi/api_req_combined_battle/sp_midnight"
33     
34     case battleResult = "/kcsapi/api_req_sortie/battleresult"
35     case combinedBattleResult = "/kcsapi/api_req_combined_battle/battleresult"
36 }
37
38 final class BattleCommand: JSONCommand {
39     
40     override class func canExecuteAPI(_ api: String) -> Bool {
41         
42         return BattleAPI(rawValue: api) != nil
43     }
44     
45     override func execute() {
46         
47         CalculateDamageCommand(apiResponse: apiResponse).execute()
48         
49         guard let battleApi = BattleAPI(rawValue: apiResponse.api) else { return }
50         
51         switch battleApi {
52         case .battleResult, .combinedBattleResult:
53             DropShipHistoryCommand(apiResponse: apiResponse).execute()
54             DummyShipCommand(apiResponse: apiResponse).execute()
55             GuardShelterCommand(apiResponse: apiResponse).execute()
56             
57         default: break
58         }
59     }
60 }